Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SectionObjectHandlerTest.php
Go to the documentation of this file.
1 <?php
8 
9 use AspectMock\Test as AspectMock;
15 
17 {
18  public function testGetSectionObject()
19  {
20  $mockData = [
21  "testSection1" => [
22  "element" => [
23  "testElement" => [
24  "type" => "input",
25  "selector" => "#element"
26  ]
27  ]
28  ],
29 
30  "testSection2" => [
31  "element" => [
32  "testElement" => [
33  "type" => "input",
34  "selector" => "#element"
35  ]
36  ]
37  ]
38  ];
39 
40  $this->setMockParserOutput($mockData);
41 
42  // get sections
43  $sectionHandler = SectionObjectHandler::getInstance();
44  $sections = $sectionHandler->getAllObjects();
45  $section = $sectionHandler->getObject("testSection1");
46  $invalidSection = $sectionHandler->getObject("InvalidSection");
47 
48  // perform asserts
49  $this->assertCount(2, $sections);
50  $this->assertArrayHasKey("testSection1", $sections);
51  $this->assertArrayHasKey("testSection2", $sections);
52  $this->assertNull($invalidSection);
53  }
54 
60  private function setMockParserOutput($data)
61  {
62  // clear section object handler value to inject parsed content
63  $property = new \ReflectionProperty(SectionObjectHandler::class, "INSTANCE");
64  $property->setAccessible(true);
65  $property->setValue(null);
66 
67  $mockSectionParser = AspectMock::double(SectionParser::class, ["getData" => $data])->make();
68  $instance = AspectMock::double(ObjectManager::class, ["get" => $mockSectionParser])->make();
69  AspectMock::double(ObjectManagerFactory::class, ["getObjectManager" => $instance]);
70  }
71 }