Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FrontendStorageManagerTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class FrontendStorageManagerTest extends \PHPUnit\Framework\TestCase
12 {
14  protected $model;
15 
18 
20  protected $contextMock;
21 
24 
25  protected function setUp()
26  {
27  $this->contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\Template\Context::class)
28  ->disableOriginalConstructor()
29  ->getMock();
30  $this->frontendStorageConfigurationPoolMock = $this
31  ->getMockBuilder(\Magento\Catalog\Model\FrontendStorageConfigurationPool::class)
32  ->disableOriginalConstructor()
33  ->getMock();
34 
35  $this->objectManagerHelper = new ObjectManagerHelper($this);
36  $this->model = $this->objectManagerHelper->getObject(
37  \Magento\Catalog\Block\FrontendStorageManager::class,
38  [
39  'context' => $this->contextMock,
40  'storageConfigurationPool' => $this->frontendStorageConfigurationPoolMock
41  ]
42  );
43  }
44 
45  public function testGetConfigurationJson()
46  {
47  $dynamicStorage = $this->getMockBuilder(FrontendStorageConfigurationInterface::class)
48  ->disableOriginalConstructor()
49  ->getMockForAbstractClass();
50  $configuration = [
51  'first_key' => [
52  'first' => 'data_before',
53  ],
54  'second_key' => []
55  ];
56  $this->model->setData('configuration', $configuration);
57  $this->frontendStorageConfigurationPoolMock->expects($this->exactly(2))
58  ->method('get')
59  ->withConsecutive(['first_key'], ['second_key'])
60  ->willReturnOnConsecutiveCalls($dynamicStorage, null);
61  $dynamicStorage->expects($this->once())
62  ->method('get')
63  ->willReturn(['second' => 'data']);
64 
65  $this->assertEquals(
66  [
67  'first_key' => [
68  'first' => 'data_before',
69  'second' => 'data',
70  'allowToSendRequest' => null,
71  ],
72  'second_key' => [
73  'allowToSendRequest' => null,
74  ]
75  ],
76  json_decode($this->model->getConfigurationJson(), true)
77  );
78  }
79 }
$configuration
Definition: index.php:33