Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SectionPoolTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class SectionPoolTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $objectManagerMock;
17 
21  protected $identifierMock;
22 
26  protected $sectionSourceMap;
27 
31  protected $model;
32 
33  protected function setUp()
34  {
35  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
36  $this->identifierMock = $this->createMock(\Magento\Customer\CustomerData\Section\Identifier::class);
37  $this->sectionSourceMap = ['section1' => 'b'];
38  $this->model = new SectionPool(
39  $this->objectManagerMock,
40  $this->identifierMock,
41  $this->sectionSourceMap
42  );
43  }
44 
46  {
47  $sectionNames = ['section1'];
48  $sectionsData = ['data1', 'data2'];
49  $allSectionsData = [
50  'section1' => [
51  'data1',
52  'data2'
53  ]
54  ];
55  $identifierResult = [1, 2, 3];
56 
57  $sectionSourceMock = $this->createMock(\Magento\Customer\CustomerData\SectionSourceInterface::class);
58  $this->objectManagerMock->expects($this->once())
59  ->method('get')
60  ->with('b')
61  ->willReturn($sectionSourceMock);
62  $sectionSourceMock->expects($this->once())->method('getSectionData')->willReturn($sectionsData);
63 
64  $this->identifierMock->expects($this->once())
65  ->method('markSections')
66  //check also default value for $updateIds = false
67  ->with($allSectionsData, $sectionNames, false)
68  ->willReturn($identifierResult);
69  $modelResult = $this->model->getSectionsData($sectionNames);
70  $this->assertEquals($identifierResult, $modelResult);
71  }
72 
78  {
79  $sectionNames = [];
80  $identifierResult = [1, 2, 3];
81  $this->objectManagerMock->expects($this->once())
82  ->method('get')
83  ->with('b')
84  ->willReturn($this->model);
85  $modelResult = $this->model->getSectionsData($sectionNames);
86  $this->assertEquals($identifierResult, $modelResult);
87  }
88 }