|
12 | 12 | use Drupal\user\UserInterface; |
13 | 13 |
|
14 | 14 | /** |
15 | | - * Data producers Field test class. |
| 15 | + * Tests the entity_reference data producers. |
16 | 16 | * |
17 | 17 | * @group graphql |
18 | 18 | */ |
@@ -92,4 +92,95 @@ public function testResolveEntityReference(): void { |
92 | 92 | $this->assertEquals('Dolor2 French', reset($result)->label()); |
93 | 93 | } |
94 | 94 |
|
| 95 | + /** |
| 96 | + * Tests that a given data producer returns an empty array. |
| 97 | + * |
| 98 | + * @dataProvider emptyResultsProvider |
| 99 | + */ |
| 100 | + public function testEmptyResults(string $data_producer, array $contexts): void { |
| 101 | + $node = Node::create([ |
| 102 | + 'title' => 'Dolor', |
| 103 | + 'type' => 'test1', |
| 104 | + ]); |
| 105 | + $node->save(); |
| 106 | + $contexts['entity'] = $node; |
| 107 | + |
| 108 | + $result = $this->executeDataProducer($data_producer, $contexts); |
| 109 | + $this->assertIsArray($result); |
| 110 | + $this->assertEmpty($result); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Data provider for testEmptyResults(). |
| 115 | + */ |
| 116 | + public function emptyResultsProvider(): array { |
| 117 | + return [ |
| 118 | + // Test that an empty reference field returns an empty array. |
| 119 | + ['entity_reference', [ |
| 120 | + 'field' => 'field_test1_to_test2', |
| 121 | + 'access' => TRUE, |
| 122 | + 'access_operation' => 'view', |
| 123 | + ], |
| 124 | + ], |
| 125 | + // Test that an invalid field name returns an empty array. |
| 126 | + ['entity_reference', [ |
| 127 | + 'field' => 'does_not_exist', |
| 128 | + 'access' => TRUE, |
| 129 | + 'access_operation' => 'view', |
| 130 | + ], |
| 131 | + ], |
| 132 | + // Test that an invalid field type returns an empty array. |
| 133 | + ['entity_reference', [ |
| 134 | + 'field' => 'title', |
| 135 | + 'access' => TRUE, |
| 136 | + 'access_operation' => 'view', |
| 137 | + ], |
| 138 | + ], |
| 139 | + // Same test set for the entity_reference_revisions data producer. |
| 140 | + // Test that an empty reference field returns an empty array. |
| 141 | + ['entity_reference_revisions', [ |
| 142 | + 'field' => 'field_test1_to_test2', |
| 143 | + 'access' => TRUE, |
| 144 | + 'access_operation' => 'view', |
| 145 | + ], |
| 146 | + ], |
| 147 | + // Test that an invalid field name returns an empty array. |
| 148 | + ['entity_reference_revisions', [ |
| 149 | + 'field' => 'does_not_exist', |
| 150 | + 'access' => TRUE, |
| 151 | + 'access_operation' => 'view', |
| 152 | + ], |
| 153 | + ], |
| 154 | + // Test that an invalid field type returns an empty array. |
| 155 | + ['entity_reference_revisions', [ |
| 156 | + 'field' => 'title', |
| 157 | + 'access' => TRUE, |
| 158 | + 'access_operation' => 'view', |
| 159 | + ], |
| 160 | + ], |
| 161 | + // Same test set for the entity_reference_layout_revisions data producer. |
| 162 | + // Test that an empty reference field returns an empty array. |
| 163 | + ['entity_reference_layout_revisions', [ |
| 164 | + 'field' => 'field_test1_to_test2', |
| 165 | + 'access' => TRUE, |
| 166 | + 'access_operation' => 'view', |
| 167 | + ], |
| 168 | + ], |
| 169 | + // Test that an invalid field name returns an empty array. |
| 170 | + ['entity_reference_layout_revisions', [ |
| 171 | + 'field' => 'does_not_exist', |
| 172 | + 'access' => TRUE, |
| 173 | + 'access_operation' => 'view', |
| 174 | + ], |
| 175 | + ], |
| 176 | + // Test that an invalid field type returns an empty array. |
| 177 | + ['entity_reference_layout_revisions', [ |
| 178 | + 'field' => 'title', |
| 179 | + 'access' => TRUE, |
| 180 | + 'access_operation' => 'view', |
| 181 | + ], |
| 182 | + ], |
| 183 | + ]; |
| 184 | + } |
| 185 | + |
95 | 186 | } |
0 commit comments