|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Tests\unit\Magento\FunctionalTestFramework\Test\Handlers; |
| 8 | + |
| 9 | +use AspectMock\Test as AspectMock; |
| 10 | + |
| 11 | +use Magento\FunctionalTestingFramework\ObjectManager; |
| 12 | +use Magento\FunctionalTestingFramework\ObjectManagerFactory; |
| 13 | +use Magento\FunctionalTestingFramework\Test\Handlers\CestObjectHandler; |
| 14 | +use Magento\FunctionalTestingFramework\Test\Objects\ActionObject; |
| 15 | +use Magento\FunctionalTestingFramework\Test\Objects\CestHookObject; |
| 16 | +use Magento\FunctionalTestingFramework\Test\Objects\CestObject; |
| 17 | +use Magento\FunctionalTestingFramework\Test\Objects\TestObject; |
| 18 | +use Magento\FunctionalTestingFramework\Test\Parsers\TestDataParser; |
| 19 | +use Magento\FunctionalTestingFramework\Test\Util\ActionObjectExtractor; |
| 20 | +use Magento\FunctionalTestingFramework\Test\Util\CestObjectExtractor; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | + |
| 23 | +class CestObjectHandlerTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * Basic test to validate array => test object conversion |
| 27 | + */ |
| 28 | + public function testGetCestObject() |
| 29 | + { |
| 30 | + // set up mock data |
| 31 | + $testCestName = 'testCest'; |
| 32 | + $testTestName = 'testTest'; |
| 33 | + $testActionBeforeName = 'testActionBefore'; |
| 34 | + $testActionAfterName = 'testActionAfter'; |
| 35 | + $testTestActionName = 'testActionInTest'; |
| 36 | + $testActionType = 'testAction'; |
| 37 | + |
| 38 | + $mockData = [CestObjectExtractor::CEST_ROOT => [ |
| 39 | + $testCestName => [ |
| 40 | + CestObjectExtractor::NAME => $testCestName, |
| 41 | + CestObjectExtractor::CEST_BEFORE_HOOK => [ |
| 42 | + $testActionBeforeName => [ |
| 43 | + ActionObjectExtractor::NODE_NAME => $testActionType, |
| 44 | + ActionObjectExtractor::TEST_STEP_MERGE_KEY => $testActionBeforeName |
| 45 | + ] |
| 46 | + ], |
| 47 | + CestObjectExtractor::CEST_AFTER_HOOK => [ |
| 48 | + $testActionAfterName => [ |
| 49 | + ActionObjectExtractor::NODE_NAME => $testActionType, |
| 50 | + ActionObjectExtractor::TEST_STEP_MERGE_KEY => $testActionAfterName |
| 51 | + |
| 52 | + ] |
| 53 | + ], |
| 54 | + CestObjectExtractor::CEST_ANNOTATIONS => [ |
| 55 | + 'group' => [['value' => 'test']] |
| 56 | + ], |
| 57 | + $testTestName => [ |
| 58 | + $testTestActionName => [ |
| 59 | + ActionObjectExtractor::NODE_NAME => $testActionType, |
| 60 | + ActionObjectExtractor::TEST_STEP_MERGE_KEY => $testTestActionName |
| 61 | + ], |
| 62 | + ] |
| 63 | + ] |
| 64 | + ] |
| 65 | + ]; |
| 66 | + $mockDataParser = AspectMock::double(TestDataParser::class, ['readTestData' => $mockData])->make(); |
| 67 | + $instance = AspectMock::double(ObjectManager::class, ['create' => $mockDataParser]) |
| 68 | + ->make(); // bypass the private constructor |
| 69 | + AspectMock::double(ObjectManagerFactory::class, ['getObjectManager' => $instance]); |
| 70 | + |
| 71 | + // run object handler method |
| 72 | + $coh = CestObjectHandler::getInstance(); |
| 73 | + $actualCestObject = $coh->getObject($testCestName); |
| 74 | + |
| 75 | + // perform asserts |
| 76 | + $expectedBeforeActionObject = new ActionObject($testActionBeforeName, $testActionType, []); |
| 77 | + $expectedAfterActionObject = new ActionObject($testActionAfterName, $testActionType, []); |
| 78 | + $expectedBeforeHookObject = new CestHookObject( |
| 79 | + CestObjectExtractor::CEST_BEFORE_HOOK, |
| 80 | + $testCestName, |
| 81 | + [$expectedBeforeActionObject], |
| 82 | + [] |
| 83 | + ); |
| 84 | + $expectedAfterHookObject = new CestHookObject( |
| 85 | + CestObjectExtractor::CEST_AFTER_HOOK, |
| 86 | + $testCestName, |
| 87 | + [$expectedAfterActionObject], |
| 88 | + [] |
| 89 | + ); |
| 90 | + |
| 91 | + $expectedTestActionObject = new ActionObject($testTestActionName, $testActionType, []); |
| 92 | + $expectedTestObject = new TestObject($testTestName, [$expectedTestActionObject], [], []); |
| 93 | + |
| 94 | + $expectedCestObject = new CestObject( |
| 95 | + $testCestName, |
| 96 | + [ |
| 97 | + 'group' => ['test'] |
| 98 | + ], |
| 99 | + [ |
| 100 | + $testTestName => $expectedTestObject |
| 101 | + ], |
| 102 | + [ |
| 103 | + CestObjectExtractor::CEST_BEFORE_HOOK => $expectedBeforeHookObject, |
| 104 | + CestObjectExtractor::CEST_AFTER_HOOK => $expectedAfterHookObject |
| 105 | + ] |
| 106 | + ); |
| 107 | + |
| 108 | + $this->assertEquals($expectedCestObject, $actualCestObject); |
| 109 | + } |
| 110 | +} |
0 commit comments