|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
7 |
| -namespace tests\unit\Magento\FunctionalTestFramework\DataGenerator\Objects; |
| 7 | +namespace Magento\FunctionalTestingFramework\DataGenerator\Objects; |
8 | 8 |
|
9 | 9 | use PHPUnit\Framework\TestCase;
|
10 | 10 |
|
| 11 | +/** |
| 12 | + * The following function declarations override the global function_exists and declare msq/msqs for use |
| 13 | + * in the Magento\FunctionalTestingFramework\DataGenerator\Objects, which EntityDataObject needs. |
| 14 | + */ |
| 15 | +// @codingStandardsIgnoreStart |
| 16 | +function function_exists($val) |
| 17 | +{ |
| 18 | + return true; |
| 19 | +} |
| 20 | + |
| 21 | +function msq($id = null) |
| 22 | +{ |
| 23 | + return "msqUnique"; |
| 24 | +} |
| 25 | + |
| 26 | +function msqs($id = null) |
| 27 | +{ |
| 28 | + return "msqsUnique"; |
| 29 | +} |
| 30 | +// @codingStandardsIgnoreEnd |
| 31 | + |
11 | 32 | /**
|
12 | 33 | * Class EntityDataObjectTest
|
13 | 34 | */
|
14 | 35 | class EntityDataObjectTest extends TestCase
|
15 | 36 | {
|
16 |
| - public function testTodo() |
| 37 | + public function testBasicGetters() |
| 38 | + { |
| 39 | + $data = ["datakey1" => "value1"]; |
| 40 | + $dataObject = new EntityDataObject("name", "type", $data, null, null, null); |
| 41 | + // Perform Asserts |
| 42 | + $this->assertEquals("name", $dataObject->getName()); |
| 43 | + $this->assertEquals("type", $dataObject->getType()); |
| 44 | + $this->assertEquals($data, $dataObject->getData()); |
| 45 | + } |
| 46 | + |
| 47 | + public function testGetDataByName() |
| 48 | + { |
| 49 | + $data = ["datakey1" => "value1", "datakey2" => "value2", "datakey3" => "value3"]; |
| 50 | + $dataObject = new EntityDataObject("name", "type", $data, null, null, null); |
| 51 | + // Perform Asserts |
| 52 | + $this->assertNull($dataObject->getDataByName("someInvalidName", 0)); |
| 53 | + $this->assertEquals("value1", $dataObject->getDataByName("dataKey1", 0)); |
| 54 | + $this->assertEquals("value2", $dataObject->getDataByName("dataKey2", 0)); |
| 55 | + $this->assertEquals("value3", $dataObject->getDataByName("dataKey3", 0)); |
| 56 | + } |
| 57 | + |
| 58 | + public function testGetUniqueDataByName() |
| 59 | + { |
| 60 | + $data = ["datakey1" => "value1", "datakey2" => "value2"]; |
| 61 | + $uniquenessKeys = ["datakey1" => "suffix", "datakey2" => "prefix"]; |
| 62 | + $dataObject = new EntityDataObject("name", "type", $data, null, $uniquenessKeys, null); |
| 63 | + // Perform Asserts |
| 64 | + $this->assertEquals("value1msqsUnique", $dataObject->getDataByName("datakey1", 1)); |
| 65 | + $this->assertEquals("msqsUniquevalue2", $dataObject->getDataByName("datakey2", 1)); |
| 66 | + $this->assertEquals("value1msqUnique", $dataObject->getDataByName("datakey1", 2)); |
| 67 | + $this->assertEquals("msqUniquevalue2", $dataObject->getDataByName("datakey2", 2)); |
| 68 | + $this->assertEquals('value1msqs("name")', $dataObject->getDataByName("datakey1", 3)); |
| 69 | + $this->assertEquals('msqs("name")value2', $dataObject->getDataByName("datakey2", 3)); |
| 70 | + $this->assertEquals('value1msq("name")', $dataObject->getDataByName("datakey1", 4)); |
| 71 | + $this->assertEquals('msq("name")value2', $dataObject->getDataByName("datakey2", 4)); |
| 72 | + } |
| 73 | + |
| 74 | + public function testVarGetter() |
| 75 | + { |
| 76 | + $data = ["datakey1" => "value1", "datakey2" => "value2", "datakey3" => "value3"]; |
| 77 | + $vars = ["someOtherEntity" => "id"]; |
| 78 | + $dataObject = new EntityDataObject("name", "type", $data, null, null, $vars); |
| 79 | + // Perform Asserts |
| 80 | + $this->assertEquals("id", $dataObject->getVarReference("someOtherEntity")); |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + public function testGetDataByNameInvalidUniquenessFormatValue() |
| 85 | + { |
| 86 | + $this->expectException("Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException"); |
| 87 | + $data = ["datakey1" => "value1", "datakey2" => "value2", "datakey3" => "value3"]; |
| 88 | + $dataObject = new EntityDataObject("name", "type", $data, null, null, null); |
| 89 | + // Trigger Exception |
| 90 | + $dataObject->getDataByName("dataKey1", 9999); |
| 91 | + } |
| 92 | + |
| 93 | + public function testUniquenessFunctionsDontExist() |
| 94 | + { |
| 95 | + $this->markTestIncomplete('Test fails, as msqMock is always declared in test runs.'); |
| 96 | + $this->expectException("Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException"); |
| 97 | + $data = ["datakey1" => "value1", "datakey2" => "value2", "datakey3" => "value3"]; |
| 98 | + $uniquenessKeys = ["datakey1" => "suffix"]; |
| 99 | + $dataObject = new EntityDataObject("name", "type", $data, null, $uniquenessKeys, null); |
| 100 | + // Trigger Exception |
| 101 | + $dataObject->getDataByName("datakey1", 1); |
| 102 | + } |
| 103 | + |
| 104 | + public function testGetLinkedEntities() |
17 | 105 | {
|
18 |
| - $this->markTestIncomplete('TODO'); |
| 106 | + $data = ["datakey1" => "value1", "datakey2" => "value2", "datakey3" => "value3"]; |
| 107 | + $entities = ["linkedEntity1" => "linkedEntityType", "linkedEntity2" => "otherEntityType"]; |
| 108 | + $dataObject = new EntityDataObject("name", "type", $data, $entities, null, null); |
| 109 | + // Perform Asserts |
| 110 | + $this->assertCount(2, $dataObject->getLinkedEntities()); |
| 111 | + $this->assertEquals("linkedEntity1", $dataObject->getLinkedEntitiesOfType("linkedEntityType")[0]); |
| 112 | + $this->assertEquals("linkedEntity2", $dataObject->getLinkedEntitiesOfType("otherEntityType")[0]); |
19 | 113 | }
|
20 | 114 | }
|
0 commit comments