Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataLoaderTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class DataLoaderTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
22  protected $request;
23 
27  protected $dataPersistor;
28 
33 
37  protected $designConfig;
38 
42  protected $designConfigData;
43 
48 
49  protected function setUp()
50  {
51  $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
52  ->disableOriginalConstructor()
53  ->getMock();
54  $this->dataPersistor = $this->getMockBuilder(\Magento\Framework\App\Request\DataPersistorInterface::class)
55  ->getMockForAbstractClass();
56  $this->designConfigRepository = $this->getMockBuilder(\Magento\Theme\Api\DesignConfigRepositoryInterface::class)
57  ->getMockForAbstractClass();
58  $this->designConfig = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigInterface::class)
59  ->getMockForAbstractClass();
60  $this->designConfigData = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigDataInterface::class)
61  ->getMockForAbstractClass();
62  $this->designConfigExtension = $this->getMockBuilder(
63  \Magento\Theme\Api\Data\DesignConfigExtensionInterface::class
64  )->setMethods(['getDesignConfigData'])->getMockForAbstractClass();
65 
66  $this->model = new DataLoader(
67  $this->request,
68  $this->designConfigRepository,
69  $this->dataPersistor
70  );
71  }
72 
73  public function testGetDataWithNoItems()
74  {
75  $scope = 'websites';
76  $scopeId = 1;
77 
78  $this->request->expects($this->exactly(2))
79  ->method('getParam')
80  ->willReturnMap([
81  ['scope', null, $scope],
82  ['scope_id', null, $scopeId],
83  ]);
84 
85  $this->designConfigRepository->expects($this->once())
86  ->method('getByScope')
87  ->with($scope, $scopeId)
88  ->willReturn($this->designConfig);
89  $this->designConfig->expects($this->once())
90  ->method('getExtensionAttributes')
91  ->willReturn($this->designConfigExtension);
92  $this->designConfigExtension->expects($this->once())
93  ->method('getDesignConfigData')
94  ->willReturn([$this->designConfigData]);
95  $this->designConfigData->expects($this->once())
96  ->method('getFieldConfig')
97  ->willReturn(['field' => 'field']);
98  $this->designConfigData->expects($this->once())
99  ->method('getValue')
100  ->willReturn('value');
101  $this->dataPersistor->expects($this->once())
102  ->method('get')
103  ->with('theme_design_config')
104  ->willReturn(['scope' => $scope, 'scope_id' => $scopeId]);
105  $this->dataPersistor->expects($this->once())
106  ->method('clear')
107  ->with('theme_design_config');
108 
109  $result = $this->model->getData();
110 
111  $this->assertTrue(is_array($result));
112  $this->assertTrue(array_key_exists($scope, $result));
113  $this->assertTrue(is_array($result[$scope]));
114  $this->assertTrue(array_key_exists('scope', $result[$scope]));
115  $this->assertTrue(array_key_exists('scope_id', $result[$scope]));
116  $this->assertEquals($scope, $result[$scope]['scope']);
117  $this->assertEquals($scopeId, $result[$scope]['scope_id']);
118  }
119 }