Skip to content

Commit 9f823d3

Browse files
authored
MQE-548: [Unit Test] SectionObjectHandler.php
- Added Unit tests for SectionObjectHandler
1 parent 47db109 commit 9f823d3

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Page/Handlers/SectionObjectHandlerTest.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,66 @@
66

77
namespace tests\unit\Magento\FunctionalTestFramework\Page\Handlers;
88

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;
915
use PHPUnit\Framework\TestCase;
1016

1117
class SectionObjectHandlerTest extends TestCase
1218
{
13-
public function testTodo()
19+
public function testGetSectionObject()
1420
{
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+
1670
}
1771
}

0 commit comments

Comments
 (0)