Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MetadataLoaderTest.php
Go to the documentation of this file.
1 <?php
7 
11 
12 class MetadataLoaderTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $model;
18 
22  protected $request;
23 
28 
33 
37  protected $designConfig;
38 
42  protected $designConfigData;
43 
48 
52  protected $storeManager;
53 
54  protected function setUp()
55  {
56  $this->request = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59 
60  $this->scopeFallbackResolver = $this->getMockBuilder(
61  \Magento\Framework\App\ScopeFallbackResolverInterface::class
62  )->getMockForAbstractClass();
63 
64  $this->designConfigRepository = $this->getMockBuilder(\Magento\Theme\Api\DesignConfigRepositoryInterface::class)
65  ->getMockForAbstractClass();
66  $this->designConfig = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigInterface::class)
67  ->getMockForAbstractClass();
68  $this->designConfigData = $this->getMockBuilder(\Magento\Theme\Api\Data\DesignConfigDataInterface::class)
69  ->getMockForAbstractClass();
70  $this->designConfigExtension = $this->getMockBuilder(
71  \Magento\Theme\Api\Data\DesignConfigExtensionInterface::class
72  )
73  ->setMethods(['getDesignConfigData'])
74  ->getMockForAbstractClass();
75  $this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
76  ->getMockForAbstractClass();
77 
78  $this->model = new MetadataLoader(
79  $this->request,
80  $this->scopeFallbackResolver,
81  $this->designConfigRepository,
82  $this->storeManager
83  );
84  }
85 
92  public function testGetData(
93  $scope,
94  $scopeId,
95  $showFallbackReset
96  ) {
97  $this->request->expects($this->exactly(2))
98  ->method('getParam')
99  ->willReturnMap([
100  ['scope', null, $scope],
101  ['scope_id', null, $scopeId],
102  ]);
103 
104  $this->scopeFallbackResolver->expects($this->atLeastOnce())
105  ->method('getFallbackScope')
106  ->with($scope, $scopeId)
107  ->willReturn([$scope, $scopeId]);
108  $this->storeManager->expects($this->once())
109  ->method('isSingleStoreMode')
110  ->willReturn(false);
111 
112  $this->designConfigRepository->expects($this->once())
113  ->method('getByScope')
114  ->with($scope, $scopeId)
115  ->willReturn($this->designConfig);
116  $this->designConfig->expects($this->once())
117  ->method('getExtensionAttributes')
118  ->willReturn($this->designConfigExtension);
119  $this->designConfigExtension->expects($this->once())
120  ->method('getDesignConfigData')
121  ->willReturn([$this->designConfigData]);
122  $this->designConfigData->expects($this->atLeastOnce())
123  ->method('getFieldConfig')
124  ->willReturn([
125  'field' => 'field',
126  'fieldset' => 'fieldset1'
127  ]);
128  $this->designConfigData->expects($this->once())
129  ->method('getValue')
130  ->willReturn('value');
131 
132  $result = $this->model->getData();
133  $expected = [
134  'fieldset1' => [
135  'children' => [
136  'field' => [
137  'arguments' => [
138  'data' => [
139  'config' => [
140  'default' => 'value',
141  'showFallbackReset' => $showFallbackReset,
142  ],
143  ],
144  ],
145  ],
146  ],
147  ],
148  ];
149 
150  $this->assertEquals($expected, $result);
151  }
152 
156  public function dataProviderGetData()
157  {
158  return [
159  ['default', 0, 1],
160  ['websites', 1, 1],
161  ];
162  }
163 }