1 | <?php |
||
19 | class EntityFieldValueTest extends GraphQLFileTestBase { |
||
20 | use ContentTypeCreationTrait; |
||
21 | use NodeCreationTrait; |
||
22 | |||
23 | /** |
||
24 | * @var File |
||
25 | */ |
||
26 | protected $testFile; |
||
27 | |||
28 | /** |
||
29 | * @var File |
||
30 | */ |
||
31 | protected $testImage; |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | public static $modules = [ |
||
37 | 'graphql_core', |
||
38 | 'node', |
||
39 | 'field', |
||
40 | 'filter', |
||
41 | 'text', |
||
42 | 'graphql_core', |
||
43 | 'link', |
||
44 | 'datetime', |
||
45 | 'image', |
||
46 | 'file', |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | protected function setUp() { |
||
99 | |||
100 | /** |
||
101 | * Test if the basic fields are available on the interface. |
||
102 | * |
||
103 | * @dataProvider nodeValuesProvider |
||
104 | */ |
||
105 | public function testRawValues($actualFieldValues, $expectedFieldValues) { |
||
125 | |||
126 | /** |
||
127 | * Data provider for testRawValues. |
||
128 | * |
||
129 | * @return array |
||
130 | */ |
||
131 | public function nodeValuesProvider() { |
||
132 | $fieldValues = [ |
||
133 | 'body' => [ |
||
134 | 'value' => 'test', |
||
135 | 'summary' => 'test summary', |
||
136 | ], |
||
137 | 'field_text' => ['a', 'b', 'c'], |
||
138 | 'field_boolean' => [TRUE, FALSE], |
||
139 | 'field_link' => [ |
||
140 | ['title' => 'Internal link', 'uri' => 'internal:/node/1'], |
||
141 | ['title' => 'External link', 'uri' => 'http://drupal.org'], |
||
142 | ], |
||
143 | 'field_integer' => [10, -5], |
||
144 | 'field_float' => [3.14145, -8.8], |
||
145 | 'field_decimal' => [10.5, -17.22], |
||
146 | 'field_datetime' => ['2017-01-01', '1900-01-01'], |
||
147 | 'field_timestamp' => [0, 300], |
||
148 | 'field_email' => ['[email protected]'], |
||
149 | 'field_string' => ['test', '123'], |
||
150 | 'field_reference' => [ |
||
151 | ['target_id' => 1], |
||
152 | ], |
||
153 | 'field_file' => [ |
||
154 | [ |
||
155 | 'target_id' => 1, |
||
156 | 'display' => 0, |
||
157 | 'description' => 'description test 1', |
||
158 | ], |
||
159 | [ |
||
160 | 'target_id' => 2, |
||
161 | 'display' => 1, |
||
162 | 'description' => 'description test 2', |
||
163 | ], |
||
164 | ], |
||
165 | 'field_image' => [ |
||
166 | [ |
||
167 | 'target_id' => 1, |
||
168 | 'alt' => 'alt test 1', |
||
169 | 'title' => 'title test 1', |
||
170 | 'width' => 100, |
||
171 | 'height' => 50, |
||
172 | ], |
||
173 | [ |
||
174 | 'target_id' => 2, |
||
175 | 'alt' => 'alt test 2', |
||
176 | 'title' => 'title test 2', |
||
177 | 'width' => 200, |
||
178 | 'height' => 100, |
||
179 | ], |
||
180 | ], |
||
181 | ]; |
||
182 | |||
183 | $expected = [ |
||
184 | 'nid' => 1, |
||
185 | 'vid' => 1, |
||
186 | 'langcode' => [ |
||
187 | 'value' => 'en', |
||
188 | ], |
||
189 | 'type' => [ |
||
190 | 'targetId' => 'test', |
||
191 | ], |
||
192 | 'uid' => [ |
||
193 | 'targetId' => 0, |
||
194 | 'entity' => NULL, |
||
195 | ], |
||
196 | 'title' => 'Test', |
||
197 | 'status' => 1, |
||
198 | 'promote' => 1, |
||
199 | 'sticky' => 0, |
||
200 | 'revisionTranslationAffected' => 1, |
||
201 | 'body' => [ |
||
202 | 'value' => 'test', |
||
203 | 'summary' => 'test summary', |
||
204 | 'summaryProcessed' => "<p>test summary</p>\n", |
||
205 | 'processed' => "<p>test</p>\n", |
||
206 | 'format' => NULL, |
||
207 | ], |
||
208 | 'fieldText' => [ |
||
209 | ['value' => 'a'], |
||
210 | ['value' => 'b'], |
||
211 | ['value' => 'c'], |
||
212 | ], |
||
213 | 'fieldBoolean' => [ |
||
214 | TRUE, |
||
215 | FALSE, |
||
216 | ], |
||
217 | 'fieldLink' => [ |
||
218 | ['title' => 'Internal link', 'uri' => 'internal:/node/1'], |
||
219 | ['title' => 'External link', 'uri' => 'http://drupal.org'], |
||
220 | ], |
||
221 | 'fieldInteger' => [ |
||
222 | 10, |
||
223 | -5, |
||
224 | ], |
||
225 | 'fieldFloat' => [ |
||
226 | 3.14145, |
||
227 | -8.8, |
||
228 | ], |
||
229 | 'fieldDecimal' => [ |
||
230 | 10.5, |
||
231 | -17.22, |
||
232 | ], |
||
233 | 'fieldDatetime' => [ |
||
234 | ['value' => '2017-01-01'], |
||
235 | ['value' => '1900-01-01'], |
||
236 | ], |
||
237 | 'fieldTimestamp' => [ |
||
238 | 0, |
||
239 | 300, |
||
240 | ], |
||
241 | 'fieldEmail' => ['[email protected]'], |
||
242 | 'fieldString' => [ |
||
243 | 'test', |
||
244 | '123', |
||
245 | ], |
||
246 | 'fieldReference' => [ |
||
247 | [ |
||
248 | 'targetId' => 1, |
||
249 | 'entity' => [ |
||
250 | 'title' => 'Test', |
||
251 | 'fieldReference' => [ |
||
252 | [ |
||
253 | 'targetId' => 1, |
||
254 | 'entity' => [ |
||
255 | 'title' => 'Test', |
||
256 | ], |
||
257 | ], |
||
258 | ], |
||
259 | ], |
||
260 | ], |
||
261 | ], |
||
262 | 'fieldFile' => [ |
||
263 | [ |
||
264 | 'targetId' => 1, |
||
265 | 'display' => 0, |
||
266 | 'description' => 'description test 1', |
||
267 | 'entity' => [ |
||
268 | 'uri' => 'public://example.txt' |
||
269 | ], |
||
270 | ], |
||
271 | [ |
||
272 | 'targetId' => 2, |
||
273 | 'display' => 1, |
||
274 | 'description' => 'description test 2', |
||
275 | 'entity' => [ |
||
276 | 'uri' => 'public://example.png' |
||
277 | ], |
||
278 | ], |
||
279 | ], |
||
280 | 'fieldImage' => [ |
||
281 | [ |
||
282 | 'targetId' => 1, |
||
283 | 'alt' => 'alt test 1', |
||
284 | 'title' => 'title test 1', |
||
285 | 'width' => 100, |
||
286 | 'height' => 50, |
||
287 | 'entity' => [ |
||
288 | 'uri' => 'public://example.txt' |
||
289 | ], |
||
290 | ], |
||
291 | [ |
||
292 | 'targetId' => 2, |
||
293 | 'alt' => 'alt test 2', |
||
294 | 'title' => 'title test 2', |
||
295 | 'width' => 200, |
||
296 | 'height' => 100, |
||
297 | 'entity' => [ |
||
298 | 'uri' => 'public://example.png' |
||
299 | ], |
||
300 | ], |
||
301 | ], |
||
302 | ]; |
||
303 | |||
304 | return [ |
||
305 | [$fieldValues, $expected], |
||
306 | ]; |
||
307 | } |
||
308 | |||
309 | /** |
||
310 | * Add a field to test content type. |
||
311 | * |
||
312 | * @param string $type |
||
313 | * Field type. |
||
314 | * @param string $fieldName |
||
315 | * Field machine name. |
||
316 | * @param string $label |
||
317 | * Label for the field. |
||
318 | */ |
||
319 | protected function addField($type, $fieldName, $label = 'Label') { |
||
333 | |||
334 | } |
||
335 |