|
6 | 6 |
|
7 | 7 | namespace tests\unit\Magento\FunctionalTestFramework\Page\Handlers;
|
8 | 8 |
|
| 9 | +use AspectMock\Test as AspectMock; |
| 10 | +use Magento\FunctionalTestingFramework\ObjectManager; |
| 11 | +use Magento\FunctionalTestingFramework\ObjectManagerFactory; |
| 12 | +use Magento\FunctionalTestingFramework\Page\Handlers\SectionObjectHandler; |
| 13 | +use Magento\FunctionalTestingFramework\XmlParser\SectionParser; |
| 14 | +use Magento\FunctionalTestingFramework\Page\Objects\SectionObject; |
9 | 15 | use PHPUnit\Framework\TestCase;
|
10 | 16 |
|
11 | 17 | class SectionObjectHandlerTest extends TestCase
|
12 | 18 | {
|
13 |
| - public function testTodo() |
| 19 | + public function testGetSectionObject() |
14 | 20 | {
|
15 |
| - $this->markTestIncomplete('TODO'); |
| 21 | + $mockData = [ |
| 22 | + "testSection1" => [ |
| 23 | + "element" => [ |
| 24 | + "testElement" => [ |
| 25 | + "type" => "input", |
| 26 | + "selector" => "#element" |
| 27 | + ] |
| 28 | + ] |
| 29 | + ], |
| 30 | + |
| 31 | + "testSection2" => [ |
| 32 | + "element" => [ |
| 33 | + "testElement" => [ |
| 34 | + "type" => "input", |
| 35 | + "selector" => "#element" |
| 36 | + ] |
| 37 | + ] |
| 38 | + ]]; |
| 39 | + $this->setMockParserOutput($mockData); |
| 40 | + |
| 41 | + // get sections |
| 42 | + $sectionHandler = SectionObjectHandler::getInstance(); |
| 43 | + $sections = $sectionHandler->getAllObjects(); |
| 44 | + $section = $sectionHandler->getObject("testSection1"); |
| 45 | + $invalidSection = $sectionHandler->getObject("InvalidSection"); |
| 46 | + |
| 47 | + // perform asserts |
| 48 | + $this->assertCount(2, $sections); |
| 49 | + $this->assertArrayHasKey("testSection1", $sections); |
| 50 | + $this->assertArrayHasKey("testSection2", $sections); |
| 51 | + $this->assertNull($invalidSection); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Function used to set mock for parser return and force init method to run between tests. |
| 56 | + * |
| 57 | + * @param array $data |
| 58 | + */ |
| 59 | + private function setMockParserOutput($data) |
| 60 | + { |
| 61 | + // clear section object handler value to inject parsed content |
| 62 | + $property = new \ReflectionProperty(SectionObjectHandler::class, 'SECTION_DATA_PROCESSOR'); |
| 63 | + $property->setAccessible(true); |
| 64 | + $property->setValue(null); |
| 65 | + |
| 66 | + $mockSectionParser = AspectMock::double(SectionParser::class, ["getData" => $data])->make(); |
| 67 | + $instance = AspectMock::double(ObjectManager::class, ['get' => $mockSectionParser])->make(); |
| 68 | + AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]); |
| 69 | + |
16 | 70 | }
|
17 | 71 | }
|
0 commit comments