|
11 | 11 | use Magento\FunctionalTestingFramework\DataGenerator\Handlers\PersistedObjectHandler;
|
12 | 12 | use Magento\FunctionalTestingFramework\DataGenerator\Parsers\DataProfileSchemaParser;
|
13 | 13 | use Magento\FunctionalTestingFramework\DataGenerator\Persist\CurlHandler;
|
| 14 | +use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; |
| 15 | +use Magento\FunctionalTestingFramework\Exceptions\TestReferenceException; |
14 | 16 | use Magento\FunctionalTestingFramework\ObjectManager;
|
15 | 17 | use Magento\FunctionalTestingFramework\ObjectManagerFactory;
|
16 | 18 | use Magento\FunctionalTestingFramework\Util\MagentoTestCase;
|
| 19 | +use tests\unit\Util\TestLoggingUtil; |
17 | 20 |
|
18 | 21 | /**
|
19 | 22 | * Class PersistedObjectHandlerTest
|
20 | 23 | */
|
21 | 24 | class PersistedObjectHandlerTest extends MagentoTestCase
|
22 | 25 | {
|
| 26 | + /** |
| 27 | + * Before test functionality |
| 28 | + * @return void |
| 29 | + */ |
| 30 | + public function setUp() |
| 31 | + { |
| 32 | + TestLoggingUtil::getInstance()->setMockLoggingUtil(); |
| 33 | + } |
| 34 | + |
23 | 35 | public function testCreateSimpleEntity()
|
24 | 36 | {
|
25 | 37 | // Test Data and Variables
|
@@ -330,6 +342,115 @@ public function testRetrieveEntityAcrossScopes()
|
330 | 342 | $this->assertEquals($dataValueThree, $retrievedFromSuite);
|
331 | 343 | }
|
332 | 344 |
|
| 345 | + /** |
| 346 | + * @param string $name |
| 347 | + * @param string $key |
| 348 | + * @param string $value |
| 349 | + * @param string $type |
| 350 | + * @param string $scope |
| 351 | + * @param string $stepKey |
| 352 | + * @dataProvider entityDataProvider |
| 353 | + */ |
| 354 | + public function testRetrieveEntityValidField($name, $key, $value, $type, $scope, $stepKey) |
| 355 | + { |
| 356 | + $parserOutputOne = [ |
| 357 | + 'entity' => [ |
| 358 | + $name => [ |
| 359 | + 'type' => $type, |
| 360 | + 'data' => [ |
| 361 | + 0 => [ |
| 362 | + 'key' => $key, |
| 363 | + 'value' => $value |
| 364 | + ] |
| 365 | + ] |
| 366 | + ] |
| 367 | + ] |
| 368 | + ]; |
| 369 | + $jsonReponseOne = " |
| 370 | + { |
| 371 | + \"" . strtolower($key) . "\" : \"{$value}\" |
| 372 | + } |
| 373 | + "; |
| 374 | + |
| 375 | + // Mock Classes and Create Entities |
| 376 | + $handler = PersistedObjectHandler::getInstance(); |
| 377 | + |
| 378 | + $this->mockDataHandlerWithOutput($parserOutputOne); |
| 379 | + $this->mockCurlHandler($jsonReponseOne); |
| 380 | + $handler->createEntity($stepKey, $scope, $name); |
| 381 | + |
| 382 | + // Call method |
| 383 | + $retrieved = $handler->retrieveEntityField($stepKey, $key, $scope); |
| 384 | + |
| 385 | + $this->assertEquals($value, $retrieved); |
| 386 | + } |
| 387 | + |
| 388 | + /** |
| 389 | + * @param string $name |
| 390 | + * @param string $key |
| 391 | + * @param string $value |
| 392 | + * @param string $type |
| 393 | + * @param string $scope |
| 394 | + * @param string $stepKey |
| 395 | + * @dataProvider entityDataProvider |
| 396 | + * @throws TestReferenceException |
| 397 | + * @throws TestFrameworkException |
| 398 | + */ |
| 399 | + public function testRetrieveEntityInValidField($name, $key, $value, $type, $scope, $stepKey) |
| 400 | + { |
| 401 | + $invalidDataKey = "invalidDataKey"; |
| 402 | + $warnMsg = "Undefined field {$invalidDataKey} in entity object with a stepKey of {$stepKey}\n"; |
| 403 | + $warnMsg .= "Please fix the invalid reference. This will result in fatal error in next major release."; |
| 404 | + |
| 405 | + $parserOutputOne = [ |
| 406 | + 'entity' => [ |
| 407 | + $name => [ |
| 408 | + 'type' => $type, |
| 409 | + 'data' => [ |
| 410 | + 0 => [ |
| 411 | + 'key' => $key, |
| 412 | + 'value' => $value |
| 413 | + ] |
| 414 | + ] |
| 415 | + ] |
| 416 | + ] |
| 417 | + ]; |
| 418 | + $jsonReponseOne = " |
| 419 | + { |
| 420 | + \"" . strtolower($key) . "\" : \"{$value}\" |
| 421 | + } |
| 422 | + "; |
| 423 | + |
| 424 | + // Mock Classes and Create Entities |
| 425 | + $handler = PersistedObjectHandler::getInstance(); |
| 426 | + |
| 427 | + $this->mockDataHandlerWithOutput($parserOutputOne); |
| 428 | + $this->mockCurlHandler($jsonReponseOne); |
| 429 | + $handler->createEntity($stepKey, $scope, $name); |
| 430 | + |
| 431 | + // Call method |
| 432 | + $handler->retrieveEntityField($stepKey, $invalidDataKey, $scope); |
| 433 | + |
| 434 | + // validate log statement |
| 435 | + TestLoggingUtil::getInstance()->validateMockLogStatement( |
| 436 | + 'warning', |
| 437 | + $warnMsg, |
| 438 | + [] |
| 439 | + ); |
| 440 | + } |
| 441 | + |
| 442 | + /** |
| 443 | + * Data provider for testRetrieveEntityField |
| 444 | + */ |
| 445 | + public static function entityDataProvider() |
| 446 | + { |
| 447 | + return [ |
| 448 | + ['Entity1', 'testKey1', 'testValue1', 'testType', PersistedObjectHandler::HOOK_SCOPE, 'StepKey1'], |
| 449 | + ['Entity2', 'testKey2', 'testValue2', 'testType', PersistedObjectHandler::SUITE_SCOPE, 'StepKey2'], |
| 450 | + ['Entity3', 'testKey3', 'testValue3', 'testType', PersistedObjectHandler::TEST_SCOPE, 'StepKey3'] |
| 451 | + ]; |
| 452 | + } |
| 453 | + |
333 | 454 | /**
|
334 | 455 | * Mocks DataObjectHandler to use given output to create
|
335 | 456 | * @param $parserOutput
|
@@ -374,4 +495,14 @@ public function tearDown()
|
374 | 495 |
|
375 | 496 | parent::tearDown(); // TODO: Change the autogenerated stub
|
376 | 497 | }
|
| 498 | + |
| 499 | + /** |
| 500 | + * After class functionality |
| 501 | + * @return void |
| 502 | + */ |
| 503 | + public static function tearDownAfterClass() |
| 504 | + { |
| 505 | + TestLoggingUtil::getInstance()->clearMockLoggingUtil(); |
| 506 | + parent::tearDownAfterClass(); |
| 507 | + } |
377 | 508 | }
|
0 commit comments