|
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;
|
@@ -330,6 +332,108 @@ public function testRetrieveEntityAcrossScopes()
|
330 | 332 | $this->assertEquals($dataValueThree, $retrievedFromSuite);
|
331 | 333 | }
|
332 | 334 |
|
| 335 | + /** |
| 336 | + * @param string $name |
| 337 | + * @param string $key |
| 338 | + * @param string $value |
| 339 | + * @param string $type |
| 340 | + * @param string $scope |
| 341 | + * @param string $stepKey |
| 342 | + * @dataProvider entityDataProvider |
| 343 | + */ |
| 344 | + public function testRetrieveEntityValidField($name, $key, $value, $type, $scope, $stepKey) |
| 345 | + { |
| 346 | + $parserOutputOne = [ |
| 347 | + 'entity' => [ |
| 348 | + $name => [ |
| 349 | + 'type' => $type, |
| 350 | + 'data' => [ |
| 351 | + 0 => [ |
| 352 | + 'key' => $key, |
| 353 | + 'value' => $value |
| 354 | + ] |
| 355 | + ] |
| 356 | + ] |
| 357 | + ] |
| 358 | + ]; |
| 359 | + $jsonReponseOne = " |
| 360 | + { |
| 361 | + \"" . strtolower($key) . "\" : \"{$value}\" |
| 362 | + } |
| 363 | + "; |
| 364 | + |
| 365 | + // Mock Classes and Create Entities |
| 366 | + $handler = PersistedObjectHandler::getInstance(); |
| 367 | + |
| 368 | + $this->mockDataHandlerWithOutput($parserOutputOne); |
| 369 | + $this->mockCurlHandler($jsonReponseOne); |
| 370 | + $handler->createEntity($stepKey, $scope, $name); |
| 371 | + |
| 372 | + // Call method |
| 373 | + $retrieved = $handler->retrieveEntityField($stepKey, $key, $scope); |
| 374 | + |
| 375 | + $this->assertEquals($value, $retrieved); |
| 376 | + } |
| 377 | + |
| 378 | + /** |
| 379 | + * @param string $name |
| 380 | + * @param string $key |
| 381 | + * @param string $value |
| 382 | + * @param string $type |
| 383 | + * @param string $scope |
| 384 | + * @param string $stepKey |
| 385 | + * @dataProvider entityDataProvider |
| 386 | + * @throws TestReferenceException |
| 387 | + * @throws TestFrameworkException |
| 388 | + */ |
| 389 | + public function testRetrieveEntityInValidField($name, $key, $value, $type, $scope, $stepKey) |
| 390 | + { |
| 391 | + $invalidDataKey = "invalidDataKey"; |
| 392 | + |
| 393 | + $parserOutputOne = [ |
| 394 | + 'entity' => [ |
| 395 | + $name => [ |
| 396 | + 'type' => $type, |
| 397 | + 'data' => [ |
| 398 | + 0 => [ |
| 399 | + 'key' => $key, |
| 400 | + 'value' => $value |
| 401 | + ] |
| 402 | + ] |
| 403 | + ] |
| 404 | + ] |
| 405 | + ]; |
| 406 | + $jsonReponseOne = " |
| 407 | + { |
| 408 | + \"" . strtolower($key) . "\" : \"{$value}\" |
| 409 | + } |
| 410 | + "; |
| 411 | + |
| 412 | + // Mock Classes and Create Entities |
| 413 | + $handler = PersistedObjectHandler::getInstance(); |
| 414 | + |
| 415 | + $this->mockDataHandlerWithOutput($parserOutputOne); |
| 416 | + $this->mockCurlHandler($jsonReponseOne); |
| 417 | + $handler->createEntity($stepKey, $scope, $name); |
| 418 | + |
| 419 | + $this->expectException(\Magento\FunctionalTestingFramework\Exceptions\TestReferenceException::class); |
| 420 | + |
| 421 | + // Call method |
| 422 | + $handler->retrieveEntityField($stepKey, $invalidDataKey, $scope); |
| 423 | + } |
| 424 | + |
| 425 | + /** |
| 426 | + * Data provider for testRetrieveEntityField |
| 427 | + */ |
| 428 | + public static function entityDataProvider() |
| 429 | + { |
| 430 | + return [ |
| 431 | + ['Entity1', 'testKey1', 'testValue1', 'testType', PersistedObjectHandler::HOOK_SCOPE, 'StepKey1'], |
| 432 | + ['Entity2', 'testKey2', 'testValue2', 'testType', PersistedObjectHandler::SUITE_SCOPE, 'StepKey2'], |
| 433 | + ['Entity3', 'testKey3', 'testValue3', 'testType', PersistedObjectHandler::TEST_SCOPE, 'StepKey3'] |
| 434 | + ]; |
| 435 | + } |
| 436 | + |
333 | 437 | /**
|
334 | 438 | * Mocks DataObjectHandler to use given output to create
|
335 | 439 | * @param $parserOutput
|
|
0 commit comments