Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DoctrineDatabaseTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DoctrineDatabaseTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class DoctrineDatabaseTest extends LanguageAwareTestCase |
||
26 | { |
||
27 | /** |
||
28 | * Database gateway to test. |
||
29 | * |
||
30 | * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase |
||
31 | */ |
||
32 | protected $databaseGateway; |
||
33 | |||
34 | /** |
||
35 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::insertContentObject |
||
36 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::generateLanguageMask |
||
37 | * |
||
38 | * @todo Fix not available fields |
||
39 | */ |
||
40 | public function testInsertContentObject() |
||
41 | { |
||
42 | $struct = $this->getCreateStructFixture(); |
||
43 | |||
44 | $gateway = $this->getDatabaseGateway(); |
||
45 | $gateway->insertContentObject($struct); |
||
46 | |||
47 | $this->assertQueryResult( |
||
48 | [ |
||
49 | [ |
||
50 | 'name' => 'Content name', |
||
51 | 'contentclass_id' => '23', |
||
52 | 'section_id' => '42', |
||
53 | 'owner_id' => '13', |
||
54 | 'current_version' => '1', |
||
55 | 'initial_language_id' => '2', |
||
56 | 'remote_id' => 'some_remote_id', |
||
57 | 'language_mask' => '3', |
||
58 | 'modified' => '0', |
||
59 | 'published' => '0', |
||
60 | 'status' => ContentInfo::STATUS_DRAFT, |
||
61 | ], |
||
62 | ], |
||
63 | $this->getDatabaseHandler() |
||
64 | ->createSelectQuery() |
||
65 | ->select( |
||
66 | [ |
||
67 | 'name', |
||
68 | 'contentclass_id', |
||
69 | 'section_id', |
||
70 | 'owner_id', |
||
71 | 'current_version', |
||
72 | 'initial_language_id', |
||
73 | 'remote_id', |
||
74 | 'language_mask', |
||
75 | 'modified', |
||
76 | 'published', |
||
77 | 'status', |
||
78 | ] |
||
79 | )->from('ezcontentobject') |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Returns a Content fixture. |
||
85 | * |
||
86 | * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct |
||
87 | */ |
||
88 | protected function getCreateStructFixture() |
||
89 | { |
||
90 | $struct = new CreateStruct(); |
||
91 | |||
92 | $struct->typeId = 23; |
||
93 | $struct->sectionId = 42; |
||
94 | $struct->ownerId = 13; |
||
95 | $struct->initialLanguageId = 2; |
||
96 | $struct->remoteId = 'some_remote_id'; |
||
97 | $struct->alwaysAvailable = true; |
||
98 | $struct->modified = 456; |
||
99 | $struct->name = [ |
||
|
|||
100 | 'eng-US' => 'Content name', |
||
101 | ]; |
||
102 | $struct->fields = [ |
||
103 | new Field(['languageCode' => 'eng-US']), |
||
104 | ]; |
||
105 | $struct->locations = []; |
||
106 | |||
107 | return $struct; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Returns a Content fixture. |
||
112 | * |
||
113 | * @return \eZ\Publish\SPI\Persistence\Content |
||
114 | */ |
||
115 | protected function getContentFixture() |
||
116 | { |
||
117 | $content = new Content(); |
||
118 | |||
119 | $content->versionInfo = new VersionInfo(); |
||
120 | $content->versionInfo->names = [ |
||
121 | 'eng-US' => 'Content name', |
||
122 | ]; |
||
123 | $content->versionInfo->status = VersionInfo::STATUS_PENDING; |
||
124 | |||
125 | $content->versionInfo->contentInfo = new ContentInfo(); |
||
126 | $content->versionInfo->contentInfo->contentTypeId = 23; |
||
127 | $content->versionInfo->contentInfo->sectionId = 42; |
||
128 | $content->versionInfo->contentInfo->ownerId = 13; |
||
129 | $content->versionInfo->contentInfo->currentVersionNo = 2; |
||
130 | $content->versionInfo->contentInfo->mainLanguageCode = 'eng-US'; |
||
131 | $content->versionInfo->contentInfo->remoteId = 'some_remote_id'; |
||
132 | $content->versionInfo->contentInfo->alwaysAvailable = true; |
||
133 | $content->versionInfo->contentInfo->publicationDate = 123; |
||
134 | $content->versionInfo->contentInfo->modificationDate = 456; |
||
135 | $content->versionInfo->contentInfo->isPublished = false; |
||
136 | $content->versionInfo->contentInfo->name = 'Content name'; |
||
137 | |||
138 | return $content; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Returns a Version fixture. |
||
143 | * |
||
144 | * @return \eZ\Publish\SPI\Persistence\Content\VersionInfo |
||
145 | */ |
||
146 | protected function getVersionFixture() |
||
147 | { |
||
148 | $version = new VersionInfo(); |
||
149 | |||
150 | $version->id = null; |
||
151 | $version->versionNo = 1; |
||
152 | $version->creatorId = 13; |
||
153 | $version->status = 0; |
||
154 | $version->creationDate = 1312278322; |
||
155 | $version->modificationDate = 1312278323; |
||
156 | $version->initialLanguageCode = 'eng-GB'; |
||
157 | $version->contentInfo = new ContentInfo( |
||
158 | [ |
||
159 | 'id' => 2342, |
||
160 | 'alwaysAvailable' => true, |
||
161 | ] |
||
162 | ); |
||
163 | |||
164 | return $version; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::insertVersion |
||
169 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::generateLanguage |
||
170 | */ |
||
171 | public function testInsertVersion() |
||
172 | { |
||
173 | $version = $this->getVersionFixture(); |
||
174 | |||
175 | $gateway = $this->getDatabaseGateway(); |
||
176 | $gateway->insertVersion($version, []); |
||
177 | |||
178 | $this->assertQueryResult( |
||
179 | [ |
||
180 | [ |
||
181 | 'contentobject_id' => '2342', |
||
182 | 'created' => '1312278322', |
||
183 | 'creator_id' => '13', |
||
184 | 'modified' => '1312278323', |
||
185 | 'status' => '0', |
||
186 | 'workflow_event_pos' => '0', |
||
187 | 'version' => '1', |
||
188 | 'language_mask' => '5', |
||
189 | 'initial_language_id' => '4', |
||
190 | // Not needed, according to field mapping document |
||
191 | // 'user_id', |
||
192 | ], |
||
193 | ], |
||
194 | $this->getDatabaseHandler() |
||
195 | ->createSelectQuery() |
||
196 | ->select( |
||
197 | [ |
||
198 | 'contentobject_id', |
||
199 | 'created', |
||
200 | 'creator_id', |
||
201 | 'modified', |
||
202 | 'status', |
||
203 | 'workflow_event_pos', |
||
204 | 'version', |
||
205 | 'language_mask', |
||
206 | 'initial_language_id', |
||
207 | ] |
||
208 | )->from('ezcontentobject_version') |
||
209 | ); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setStatus |
||
214 | */ |
||
215 | View Code Duplication | public function testSetStatus() |
|
216 | { |
||
217 | $gateway = $this->getDatabaseGateway(); |
||
218 | |||
219 | // insert content |
||
220 | $struct = $this->getCreateStructFixture(); |
||
221 | $contentId = $gateway->insertContentObject($struct); |
||
222 | |||
223 | // insert version |
||
224 | $version = $this->getVersionFixture(); |
||
225 | $version->contentInfo->id = $contentId; |
||
226 | $gateway->insertVersion($version, []); |
||
227 | |||
228 | $this->assertTrue( |
||
229 | $gateway->setStatus($version->contentInfo->id, $version->versionNo, VersionInfo::STATUS_PENDING) |
||
230 | ); |
||
231 | |||
232 | $this->assertQueryResult( |
||
233 | [[VersionInfo::STATUS_PENDING]], |
||
234 | $this->getDatabaseHandler() |
||
235 | ->createSelectQuery() |
||
236 | ->select('status') |
||
237 | ->from('ezcontentobject_version') |
||
238 | ); |
||
239 | |||
240 | // check that content status has not been set to published |
||
241 | $this->assertQueryResult( |
||
242 | [[VersionInfo::STATUS_DRAFT]], |
||
243 | $this->getDatabaseHandler() |
||
244 | ->createSelectQuery() |
||
245 | ->select('status') |
||
246 | ->from('ezcontentobject') |
||
247 | ); |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setStatus |
||
252 | */ |
||
253 | View Code Duplication | public function testSetStatusPublished() |
|
254 | { |
||
255 | $gateway = $this->getDatabaseGateway(); |
||
256 | |||
257 | // insert content |
||
258 | $struct = $this->getCreateStructFixture(); |
||
259 | $contentId = $gateway->insertContentObject($struct); |
||
260 | |||
261 | // insert version |
||
262 | $version = $this->getVersionFixture(); |
||
263 | $version->contentInfo->id = $contentId; |
||
264 | $gateway->insertVersion($version, []); |
||
265 | |||
266 | $this->assertTrue( |
||
267 | $gateway->setStatus($version->contentInfo->id, $version->versionNo, VersionInfo::STATUS_PUBLISHED) |
||
268 | ); |
||
269 | |||
270 | $this->assertQueryResult( |
||
271 | [[VersionInfo::STATUS_PUBLISHED]], |
||
272 | $this->getDatabaseHandler() |
||
273 | ->createSelectQuery() |
||
274 | ->select('status') |
||
275 | ->from('ezcontentobject_version') |
||
276 | ); |
||
277 | |||
278 | // check that content status has been set to published |
||
279 | $this->assertQueryResult( |
||
280 | [[ContentInfo::STATUS_PUBLISHED]], |
||
281 | $this->getDatabaseHandler() |
||
282 | ->createSelectQuery() |
||
283 | ->select('status') |
||
284 | ->from('ezcontentobject') |
||
285 | ); |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setStatus |
||
290 | */ |
||
291 | public function testSetStatusUnknownVersion() |
||
292 | { |
||
293 | $gateway = $this->getDatabaseGateway(); |
||
294 | |||
295 | $this->assertFalse( |
||
296 | $gateway->setStatus(23, 42, 2) |
||
297 | ); |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateContent |
||
302 | */ |
||
303 | public function testUpdateContent() |
||
304 | { |
||
305 | $gateway = $this->getDatabaseGateway(); |
||
306 | |||
307 | $this->insertDatabaseFixture( |
||
308 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
309 | ); |
||
310 | |||
311 | $metadataStruct = $this->getMetadataUpdateStructFixture(); |
||
312 | |||
313 | $gateway->updateContent(10, $metadataStruct); |
||
314 | |||
315 | $this->assertQueryResult( |
||
316 | [ |
||
317 | [ |
||
318 | 'initial_language_id' => '3', |
||
319 | 'modified' => '234567', |
||
320 | 'owner_id' => '42', |
||
321 | 'published' => '123456', |
||
322 | 'remote_id' => 'ghjk1234567890ghjk1234567890', |
||
323 | 'name' => 'Thoth', |
||
324 | ], |
||
325 | ], |
||
326 | $this->getDatabaseHandler()->createSelectQuery() |
||
327 | ->select( |
||
328 | 'initial_language_id', |
||
329 | 'modified', |
||
330 | 'owner_id', |
||
331 | 'published', |
||
332 | 'remote_id', |
||
333 | 'name' |
||
334 | )->from('ezcontentobject') |
||
335 | ->where('id = 10') |
||
336 | ); |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Returns an UpdateStruct fixture. |
||
341 | * |
||
342 | * @return \eZ\Publish\SPI\Persistence\Content\UpdateStruct |
||
343 | */ |
||
344 | protected function getUpdateStructFixture() |
||
345 | { |
||
346 | $struct = new UpdateStruct(); |
||
347 | $struct->creatorId = 23; |
||
348 | $struct->fields = []; |
||
349 | $struct->modificationDate = 234567; |
||
350 | $struct->initialLanguageId = 2; |
||
351 | |||
352 | return $struct; |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * Returns a MetadataUpdateStruct fixture. |
||
357 | * |
||
358 | * @return \eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct |
||
359 | */ |
||
360 | protected function getMetadataUpdateStructFixture() |
||
361 | { |
||
362 | $struct = new MetadataUpdateStruct(); |
||
363 | $struct->ownerId = 42; |
||
364 | $struct->publicationDate = 123456; |
||
365 | $struct->mainLanguageId = 3; |
||
366 | $struct->modificationDate = 234567; |
||
367 | $struct->remoteId = 'ghjk1234567890ghjk1234567890'; |
||
368 | $struct->name = 'Thoth'; |
||
369 | |||
370 | return $struct; |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateVersion |
||
375 | */ |
||
376 | public function testUpdateVersion() |
||
377 | { |
||
378 | $gateway = $this->getDatabaseGateway(); |
||
379 | |||
380 | $this->insertDatabaseFixture( |
||
381 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
382 | ); |
||
383 | |||
384 | $gateway->updateVersion(10, 2, $this->getUpdateStructFixture()); |
||
385 | |||
386 | $query = $this->getDatabaseHandler()->createSelectQuery(); |
||
387 | $this->assertQueryResult( |
||
388 | [ |
||
389 | [ |
||
390 | 'creator_id' => '23', |
||
391 | 'initial_language_id' => '2', |
||
392 | 'modified' => '234567', |
||
393 | ], |
||
394 | ], |
||
395 | $query |
||
396 | ->select( |
||
397 | [ |
||
398 | 'creator_id', |
||
399 | 'initial_language_id', |
||
400 | 'modified', |
||
401 | ] |
||
402 | )->from('ezcontentobject_version') |
||
403 | ->where( |
||
404 | $query->expr->lAnd( |
||
405 | $query->expr->eq('contentobject_id', 10), |
||
406 | $query->expr->eq('version', 2) |
||
407 | ) |
||
408 | ) |
||
409 | ); |
||
410 | } |
||
411 | |||
412 | /** |
||
413 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::insertNewField |
||
414 | */ |
||
415 | public function testInsertNewField() |
||
416 | { |
||
417 | $content = $this->getContentFixture(); |
||
418 | $content->versionInfo->contentInfo->id = 2342; |
||
419 | |||
420 | $field = $this->getFieldFixture(); |
||
421 | $value = $this->getStorageValueFixture(); |
||
422 | |||
423 | $gateway = $this->getDatabaseGateway(); |
||
424 | $gateway->insertNewField($content, $field, $value); |
||
425 | |||
426 | $this->assertQueryResult( |
||
427 | [ |
||
428 | [ |
||
429 | 'contentclassattribute_id' => '231', |
||
430 | 'contentobject_id' => '2342', |
||
431 | 'data_float' => '24.42', |
||
432 | 'data_int' => '42', |
||
433 | 'data_text' => 'Test text', |
||
434 | 'data_type_string' => 'ezstring', |
||
435 | 'language_code' => 'eng-GB', |
||
436 | 'language_id' => '4', |
||
437 | 'sort_key_int' => '23', |
||
438 | 'sort_key_string' => 'Test', |
||
439 | 'version' => '1', |
||
440 | ], |
||
441 | ], |
||
442 | $this->getDatabaseHandler() |
||
443 | ->createSelectQuery() |
||
444 | ->select( |
||
445 | [ |
||
446 | 'contentclassattribute_id', |
||
447 | 'contentobject_id', |
||
448 | 'data_float', |
||
449 | 'data_int', |
||
450 | 'data_text', |
||
451 | 'data_type_string', |
||
452 | 'language_code', |
||
453 | 'language_id', |
||
454 | 'sort_key_int', |
||
455 | 'sort_key_string', |
||
456 | 'version', |
||
457 | ] |
||
458 | )->from('ezcontentobject_attribute') |
||
459 | ); |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::insertNewField |
||
464 | */ |
||
465 | public function testInsertNewAlwaysAvailableField() |
||
466 | { |
||
467 | $content = $this->getContentFixture(); |
||
468 | $content->versionInfo->contentInfo->id = 2342; |
||
469 | // Set main language to the one used in the field fixture |
||
470 | $content->versionInfo->contentInfo->mainLanguageCode = 'eng-GB'; |
||
471 | |||
472 | $field = $this->getFieldFixture(); |
||
473 | $value = $this->getStorageValueFixture(); |
||
474 | |||
475 | $gateway = $this->getDatabaseGateway(); |
||
476 | $gateway->insertNewField($content, $field, $value); |
||
477 | |||
478 | $this->assertQueryResult( |
||
479 | [ |
||
480 | [ |
||
481 | 'contentclassattribute_id' => '231', |
||
482 | 'contentobject_id' => '2342', |
||
483 | 'data_float' => '24.42', |
||
484 | 'data_int' => '42', |
||
485 | 'data_text' => 'Test text', |
||
486 | 'data_type_string' => 'ezstring', |
||
487 | 'language_code' => 'eng-GB', |
||
488 | 'language_id' => '5', |
||
489 | 'sort_key_int' => '23', |
||
490 | 'sort_key_string' => 'Test', |
||
491 | 'version' => '1', |
||
492 | ], |
||
493 | ], |
||
494 | $this->getDatabaseHandler() |
||
495 | ->createSelectQuery() |
||
496 | ->select( |
||
497 | [ |
||
498 | 'contentclassattribute_id', |
||
499 | 'contentobject_id', |
||
500 | 'data_float', |
||
501 | 'data_int', |
||
502 | 'data_text', |
||
503 | 'data_type_string', |
||
504 | 'language_code', |
||
505 | 'language_id', |
||
506 | 'sort_key_int', |
||
507 | 'sort_key_string', |
||
508 | 'version', |
||
509 | ] |
||
510 | )->from('ezcontentobject_attribute') |
||
511 | ); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateField |
||
516 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setFieldUpdateValues |
||
517 | */ |
||
518 | public function testUpdateField() |
||
519 | { |
||
520 | $content = $this->getContentFixture(); |
||
521 | $content->versionInfo->contentInfo->id = 2342; |
||
522 | |||
523 | $field = $this->getFieldFixture(); |
||
524 | $value = $this->getStorageValueFixture(); |
||
525 | |||
526 | $gateway = $this->getDatabaseGateway(); |
||
527 | $field->id = $gateway->insertNewField($content, $field, $value); |
||
528 | |||
529 | $newValue = new StorageFieldValue( |
||
530 | [ |
||
531 | 'dataFloat' => 124.42, |
||
532 | 'dataInt' => 142, |
||
533 | 'dataText' => 'New text', |
||
534 | 'sortKeyInt' => 123, |
||
535 | 'sortKeyString' => 'new_text', |
||
536 | ] |
||
537 | ); |
||
538 | |||
539 | $gateway->updateField($field, $newValue); |
||
540 | |||
541 | $this->assertQueryResult( |
||
542 | [ |
||
543 | [ |
||
544 | 'data_float' => '124.42', |
||
545 | 'data_int' => '142', |
||
546 | 'data_text' => 'New text', |
||
547 | 'sort_key_int' => '123', |
||
548 | 'sort_key_string' => 'new_text', |
||
549 | ], |
||
550 | ], |
||
551 | $this->getDatabaseHandler() |
||
552 | ->createSelectQuery() |
||
553 | ->select( |
||
554 | [ |
||
555 | 'data_float', |
||
556 | 'data_int', |
||
557 | 'data_text', |
||
558 | 'sort_key_int', |
||
559 | 'sort_key_string', |
||
560 | ] |
||
561 | )->from('ezcontentobject_attribute') |
||
562 | ); |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateNonTranslatableField |
||
567 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setFieldUpdateValues |
||
568 | */ |
||
569 | public function testUpdateNonTranslatableField() |
||
570 | { |
||
571 | $content = $this->getContentFixture(); |
||
572 | $content->versionInfo->contentInfo->id = 2342; |
||
573 | |||
574 | $fieldGb = $this->getFieldFixture(); |
||
575 | $fieldUs = $this->getOtherLanguageFieldFixture(); |
||
576 | $value = $this->getStorageValueFixture(); |
||
577 | |||
578 | $gateway = $this->getDatabaseGateway(); |
||
579 | $fieldGb->id = $gateway->insertNewField($content, $fieldGb, $value); |
||
580 | $fieldUs->id = $gateway->insertNewField($content, $fieldUs, $value); |
||
581 | |||
582 | $updateStruct = new Content\UpdateStruct(); |
||
583 | |||
584 | $newValue = new StorageFieldValue( |
||
585 | [ |
||
586 | 'dataFloat' => 124.42, |
||
587 | 'dataInt' => 142, |
||
588 | 'dataText' => 'New text', |
||
589 | 'sortKeyInt' => 123, |
||
590 | 'sortKeyString' => 'new_text', |
||
591 | ] |
||
592 | ); |
||
593 | |||
594 | $gateway->updateNonTranslatableField($fieldGb, $newValue, $content->versionInfo->contentInfo->id); |
||
595 | |||
596 | $this->assertQueryResult( |
||
597 | [ |
||
598 | // Both fields updated |
||
599 | [ |
||
600 | 'data_float' => '124.42', |
||
601 | 'data_int' => '142', |
||
602 | 'data_text' => 'New text', |
||
603 | 'sort_key_int' => '123', |
||
604 | 'sort_key_string' => 'new_text', |
||
605 | ], |
||
606 | [ |
||
607 | 'data_float' => '124.42', |
||
608 | 'data_int' => '142', |
||
609 | 'data_text' => 'New text', |
||
610 | 'sort_key_int' => '123', |
||
611 | 'sort_key_string' => 'new_text', |
||
612 | ], |
||
613 | ], |
||
614 | $this->getDatabaseHandler() |
||
615 | ->createSelectQuery() |
||
616 | ->select( |
||
617 | [ |
||
618 | 'data_float', |
||
619 | 'data_int', |
||
620 | 'data_text', |
||
621 | 'sort_key_int', |
||
622 | 'sort_key_string', |
||
623 | ] |
||
624 | )->from('ezcontentobject_attribute') |
||
625 | ); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::listVersions |
||
630 | */ |
||
631 | public function testListVersions(): void |
||
632 | { |
||
633 | $this->insertDatabaseFixture( |
||
634 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
635 | ); |
||
636 | |||
637 | $gateway = $this->getDatabaseGateway(); |
||
638 | $res = $gateway->listVersions(226); |
||
639 | |||
640 | $this->assertCount( |
||
641 | 2, |
||
642 | $res |
||
643 | ); |
||
644 | |||
645 | foreach ($res as $row) { |
||
646 | $this->assertCount( |
||
647 | 23, |
||
648 | $row |
||
649 | ); |
||
650 | } |
||
651 | |||
652 | $this->assertEquals( |
||
653 | 675, |
||
654 | $res[0]['ezcontentobject_version_id'] |
||
655 | ); |
||
656 | $this->assertEquals( |
||
657 | 676, |
||
658 | $res[1]['ezcontentobject_version_id'] |
||
659 | ); |
||
660 | } |
||
661 | |||
662 | /** |
||
663 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::listVersionNumbers |
||
664 | */ |
||
665 | View Code Duplication | public function testListVersionNumbers() |
|
666 | { |
||
667 | $this->insertDatabaseFixture( |
||
668 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
669 | ); |
||
670 | |||
671 | $gateway = $this->getDatabaseGateway(); |
||
672 | $res = $gateway->listVersionNumbers(226); |
||
673 | |||
674 | $this->assertEquals([1, 2], $res); |
||
675 | } |
||
676 | |||
677 | /** |
||
678 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::listVersionsForUser |
||
679 | */ |
||
680 | public function testListVersionsForUser() |
||
681 | { |
||
682 | $this->insertDatabaseFixture( |
||
683 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
684 | ); |
||
685 | |||
686 | $gateway = $this->getDatabaseGateway(); |
||
687 | $res = $gateway->listVersionsForUser(14); |
||
688 | |||
689 | $this->assertCount( |
||
690 | 2, |
||
691 | $res |
||
692 | ); |
||
693 | |||
694 | foreach ($res as $row) { |
||
695 | $this->assertCount( |
||
696 | 23, |
||
697 | $row |
||
698 | ); |
||
699 | } |
||
700 | |||
701 | $this->assertEquals( |
||
702 | 677, |
||
703 | $res[0]['ezcontentobject_version_id'] |
||
704 | ); |
||
705 | $this->assertEquals( |
||
706 | 0, |
||
707 | $res[0]['ezcontentobject_version_status'] |
||
708 | ); |
||
709 | $this->assertEquals( |
||
710 | 678, |
||
711 | $res[1]['ezcontentobject_version_id'] |
||
712 | ); |
||
713 | $this->assertEquals( |
||
714 | 0, |
||
715 | $res[1]['ezcontentobject_version_status'] |
||
716 | ); |
||
717 | } |
||
718 | |||
719 | /** |
||
720 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::load |
||
721 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder |
||
722 | */ |
||
723 | public function testLoadWithAllTranslations() |
||
724 | { |
||
725 | $this->insertDatabaseFixture( |
||
726 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
727 | ); |
||
728 | |||
729 | $gateway = $this->getDatabaseGateway(); |
||
730 | $res = $gateway->load(226, 2); |
||
731 | |||
732 | $this->assertValuesInRows( |
||
733 | 'ezcontentobject_attribute_language_code', |
||
734 | ['eng-US', 'eng-GB'], |
||
735 | $res |
||
736 | ); |
||
737 | |||
738 | $this->assertValuesInRows( |
||
739 | 'ezcontentobject_attribute_language_id', |
||
740 | ['2', '4'], |
||
741 | $res |
||
742 | ); |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::load |
||
747 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder |
||
748 | */ |
||
749 | View Code Duplication | public function testCreateFixtureForMapperExtractContentFromRowsMultipleVersions() |
|
750 | { |
||
751 | $this->insertDatabaseFixture( |
||
752 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
753 | ); |
||
754 | |||
755 | $gateway = $this->getDatabaseGateway(); |
||
756 | |||
757 | $resFirst = $gateway->load(11, 1); |
||
758 | $resSecond = $gateway->load(11, 2); |
||
759 | |||
760 | $res = array_merge($resFirst, $resSecond); |
||
761 | |||
762 | $orig = include __DIR__ . '/../_fixtures/extract_content_from_rows_multiple_versions.php'; |
||
763 | |||
764 | /*$this->storeFixture( |
||
765 | __DIR__ . '/../_fixtures/extract_content_from_rows_multiple_versions.php', |
||
766 | $res |
||
767 | );*/ |
||
768 | |||
769 | $this->assertEquals($orig, $res, 'Fixtures differ between what was previously stored(expected) and what it now generates(actual), this hints either some mistake in impl or that the fixture (../_fixtures/extract_content_from_rows_multiple_versions.php) and tests needs to be adapted.'); |
||
770 | } |
||
771 | |||
772 | /** |
||
773 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::load |
||
774 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder |
||
775 | */ |
||
776 | public function testCreateFixtureForMapperExtractContentFromRows() |
||
777 | { |
||
778 | $this->insertDatabaseFixture( |
||
779 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
780 | ); |
||
781 | |||
782 | $gateway = $this->getDatabaseGateway(); |
||
783 | |||
784 | $res = array_merge($gateway->load(226, 2)); |
||
785 | |||
786 | $orig = include __DIR__ . '/../_fixtures/extract_content_from_rows.php'; |
||
787 | |||
788 | /*$this->storeFixture( |
||
789 | __DIR__ . '/../_fixtures/extract_content_from_rows.php', |
||
790 | $res |
||
791 | );*/ |
||
792 | |||
793 | $this->assertEquals($orig, $res, 'Fixtures differ between what was previously stored(expected) and what it now generates(actual), this hints either some mistake in impl or that the fixture (../_fixtures/extract_content_from_rows.php) and tests needs to be adapted.'); |
||
794 | } |
||
795 | |||
796 | /** |
||
797 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::load |
||
798 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder |
||
799 | */ |
||
800 | View Code Duplication | public function testLoadWithSingleTranslation() |
|
801 | { |
||
802 | $this->insertDatabaseFixture( |
||
803 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
804 | ); |
||
805 | |||
806 | $gateway = $this->getDatabaseGateway(); |
||
807 | $res = $gateway->load(226, 2, ['eng-GB']); |
||
808 | |||
809 | $this->assertValuesInRows( |
||
810 | 'ezcontentobject_attribute_language_code', |
||
811 | ['eng-GB'], |
||
812 | $res |
||
813 | ); |
||
814 | $this->assertValuesInRows( |
||
815 | 'ezcontentobject_attribute_language_id', |
||
816 | ['4'], |
||
817 | $res |
||
818 | ); |
||
819 | $this->assertCount( |
||
820 | 1, |
||
821 | $res |
||
822 | ); |
||
823 | } |
||
824 | |||
825 | /** |
||
826 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::load |
||
827 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder |
||
828 | */ |
||
829 | View Code Duplication | public function testLoadNonExistentTranslation() |
|
830 | { |
||
831 | $this->insertDatabaseFixture( |
||
832 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
833 | ); |
||
834 | |||
835 | $gateway = $this->getDatabaseGateway(); |
||
836 | $res = $gateway->load(226, 2, ['de-DE']); |
||
837 | |||
838 | $this->assertCount( |
||
839 | 0, |
||
840 | $res |
||
841 | ); |
||
842 | } |
||
843 | |||
844 | /** |
||
845 | * Asserts that $columnKey in $actualRows exactly contains $expectedValues. |
||
846 | * |
||
847 | * @param string $columnKey |
||
848 | * @param string[] $expectedValues |
||
849 | * @param string[][] $actualRows |
||
850 | */ |
||
851 | protected function assertValuesInRows($columnKey, array $expectedValues, array $actualRows) |
||
852 | { |
||
853 | $expectedValues = array_fill_keys( |
||
854 | array_values($expectedValues), |
||
855 | true |
||
856 | ); |
||
857 | |||
858 | $containedValues = []; |
||
859 | |||
860 | foreach ($actualRows as $row) { |
||
861 | if (isset($row[$columnKey])) { |
||
862 | $containedValues[$row[$columnKey]] = true; |
||
863 | } |
||
864 | } |
||
865 | |||
866 | $this->assertEquals( |
||
867 | $expectedValues, |
||
868 | $containedValues |
||
869 | ); |
||
870 | } |
||
871 | |||
872 | /** |
||
873 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::getAllLocationIds |
||
874 | */ |
||
875 | View Code Duplication | public function testGetAllLocationIds() |
|
876 | { |
||
877 | $this->insertDatabaseFixture( |
||
878 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
879 | ); |
||
880 | |||
881 | $gateway = $this->getDatabaseGateway(); |
||
882 | |||
883 | $this->assertEquals( |
||
884 | [228], |
||
885 | $gateway->getAllLocationIds(226) |
||
886 | ); |
||
887 | } |
||
888 | |||
889 | /** |
||
890 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::getFieldIdsByType |
||
891 | */ |
||
892 | public function testGetFieldIdsByType() |
||
893 | { |
||
894 | $this->insertDatabaseFixture( |
||
895 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
896 | ); |
||
897 | |||
898 | $gateway = $this->getDatabaseGateway(); |
||
899 | |||
900 | $this->assertEquals( |
||
901 | [ |
||
902 | 'ezstring' => [841], |
||
903 | 'ezimage' => [843], |
||
904 | 'ezkeyword' => [844], |
||
905 | ], |
||
906 | $gateway->getFieldIdsByType(149) |
||
907 | ); |
||
908 | } |
||
909 | |||
910 | /** |
||
911 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::getFieldIdsByType |
||
912 | */ |
||
913 | public function testGetFieldIdsByTypeWithSecondArgument() |
||
914 | { |
||
915 | $this->insertDatabaseFixture( |
||
916 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
917 | ); |
||
918 | |||
919 | $gateway = $this->getDatabaseGateway(); |
||
920 | |||
921 | $this->assertEquals( |
||
922 | [ |
||
923 | 'ezstring' => [4001, 4002], |
||
924 | ], |
||
925 | $gateway->getFieldIdsByType(225, 2) |
||
926 | ); |
||
927 | } |
||
928 | |||
929 | /** |
||
930 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteRelations |
||
931 | */ |
||
932 | View Code Duplication | public function testDeleteRelationsTo() |
|
933 | { |
||
934 | $this->insertDatabaseFixture( |
||
935 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
936 | ); |
||
937 | |||
938 | $beforeCount = [ |
||
939 | 'all' => $this->countContentRelations(), |
||
940 | 'from' => $this->countContentRelations(149), |
||
941 | 'to' => $this->countContentRelations(null, 149), |
||
942 | ]; |
||
943 | |||
944 | $gateway = $this->getDatabaseGateway(); |
||
945 | $gateway->deleteRelations(149); |
||
946 | |||
947 | $this->assertEquals( |
||
948 | // yes, relates to itself! |
||
949 | [ |
||
950 | 'all' => $beforeCount['all'] - 2, |
||
951 | 'from' => $beforeCount['from'] - 1, |
||
952 | 'to' => $beforeCount['to'] - 2, |
||
953 | ], |
||
954 | [ |
||
955 | 'all' => $this->countContentRelations(), |
||
956 | 'from' => $this->countContentRelations(149), |
||
957 | 'to' => $this->countContentRelations(null, 149), |
||
958 | ] |
||
959 | ); |
||
960 | } |
||
961 | |||
962 | /** |
||
963 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteRelations |
||
964 | */ |
||
965 | View Code Duplication | public function testDeleteRelationsFrom() |
|
966 | { |
||
967 | $this->insertDatabaseFixture( |
||
968 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
969 | ); |
||
970 | |||
971 | $beforeCount = [ |
||
972 | 'all' => $this->countContentRelations(), |
||
973 | 'from' => $this->countContentRelations(75), |
||
974 | 'to' => $this->countContentRelations(null, 75), |
||
975 | ]; |
||
976 | |||
977 | $gateway = $this->getDatabaseGateway(); |
||
978 | $gateway->deleteRelations(75); |
||
979 | |||
980 | $this->assertEquals( |
||
981 | [ |
||
982 | 'all' => $beforeCount['all'] - 6, |
||
983 | 'from' => $beforeCount['from'] - 6, |
||
984 | 'to' => $beforeCount['to'], |
||
985 | ], |
||
986 | [ |
||
987 | 'all' => $this->countContentRelations(), |
||
988 | 'from' => $this->countContentRelations(75), |
||
989 | 'to' => $this->countContentRelations(null, 75), |
||
990 | ] |
||
991 | ); |
||
992 | } |
||
993 | |||
994 | /** |
||
995 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteRelations |
||
996 | */ |
||
997 | View Code Duplication | public function testDeleteRelationsWithSecondArgument() |
|
998 | { |
||
999 | $this->insertDatabaseFixture( |
||
1000 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1001 | ); |
||
1002 | |||
1003 | $beforeCount = [ |
||
1004 | 'all' => $this->countContentRelations(), |
||
1005 | 'from' => $this->countContentRelations(225), |
||
1006 | 'to' => $this->countContentRelations(null, 225), |
||
1007 | ]; |
||
1008 | |||
1009 | $gateway = $this->getDatabaseGateway(); |
||
1010 | $gateway->deleteRelations(225, 2); |
||
1011 | |||
1012 | $this->assertEquals( |
||
1013 | [ |
||
1014 | 'all' => $beforeCount['all'] - 1, |
||
1015 | 'from' => $beforeCount['from'] - 1, |
||
1016 | 'to' => $beforeCount['to'], |
||
1017 | ], |
||
1018 | [ |
||
1019 | 'all' => $this->countContentRelations(), |
||
1020 | 'from' => $this->countContentRelations(225), |
||
1021 | 'to' => $this->countContentRelations(null, 225), |
||
1022 | ] |
||
1023 | ); |
||
1024 | } |
||
1025 | |||
1026 | /** |
||
1027 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteField |
||
1028 | */ |
||
1029 | public function testDeleteField() |
||
1030 | { |
||
1031 | $this->insertDatabaseFixture( |
||
1032 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1033 | ); |
||
1034 | |||
1035 | $beforeCount = $this->countContentFields(); |
||
1036 | |||
1037 | $gateway = $this->getDatabaseGateway(); |
||
1038 | $gateway->deleteField(22); |
||
1039 | |||
1040 | $this->assertEquals( |
||
1041 | $beforeCount - 2, |
||
1042 | $this->countContentFields() |
||
1043 | ); |
||
1044 | |||
1045 | $this->assertQueryResult( |
||
1046 | [], |
||
1047 | $this->getDatabaseHandler()->createSelectQuery() |
||
1048 | ->select('*') |
||
1049 | ->from('ezcontentobject_attribute') |
||
1050 | ->where('id=22') |
||
1051 | ); |
||
1052 | } |
||
1053 | |||
1054 | /** |
||
1055 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteFields |
||
1056 | */ |
||
1057 | View Code Duplication | public function testDeleteFields() |
|
1058 | { |
||
1059 | $this->insertDatabaseFixture( |
||
1060 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1061 | ); |
||
1062 | |||
1063 | $beforeCount = [ |
||
1064 | 'all' => $this->countContentFields(), |
||
1065 | 'this' => $this->countContentFields(4), |
||
1066 | ]; |
||
1067 | |||
1068 | $gateway = $this->getDatabaseGateway(); |
||
1069 | $gateway->deleteFields(4); |
||
1070 | |||
1071 | $this->assertEquals( |
||
1072 | [ |
||
1073 | 'all' => $beforeCount['all'] - 2, |
||
1074 | 'this' => 0, |
||
1075 | ], |
||
1076 | [ |
||
1077 | 'all' => $this->countContentFields(), |
||
1078 | 'this' => $this->countContentFields(4), |
||
1079 | ] |
||
1080 | ); |
||
1081 | } |
||
1082 | |||
1083 | /** |
||
1084 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteFields |
||
1085 | */ |
||
1086 | View Code Duplication | public function testDeleteFieldsWithSecondArgument() |
|
1087 | { |
||
1088 | $this->insertDatabaseFixture( |
||
1089 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1090 | ); |
||
1091 | |||
1092 | $beforeCount = [ |
||
1093 | 'all' => $this->countContentFields(), |
||
1094 | 'this' => $this->countContentFields(225), |
||
1095 | ]; |
||
1096 | |||
1097 | $gateway = $this->getDatabaseGateway(); |
||
1098 | $gateway->deleteFields(225, 2); |
||
1099 | |||
1100 | $this->assertEquals( |
||
1101 | [ |
||
1102 | 'all' => $beforeCount['all'] - 2, |
||
1103 | 'this' => $beforeCount['this'] - 2, |
||
1104 | ], |
||
1105 | [ |
||
1106 | 'all' => $this->countContentFields(), |
||
1107 | 'this' => $this->countContentFields(225), |
||
1108 | ] |
||
1109 | ); |
||
1110 | } |
||
1111 | |||
1112 | /** |
||
1113 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteVersions |
||
1114 | */ |
||
1115 | View Code Duplication | public function testDeleteVersions() |
|
1116 | { |
||
1117 | $this->insertDatabaseFixture( |
||
1118 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1119 | ); |
||
1120 | |||
1121 | $beforeCount = [ |
||
1122 | 'all' => $this->countContentVersions(), |
||
1123 | 'this' => $this->countContentVersions(14), |
||
1124 | ]; |
||
1125 | |||
1126 | $gateway = $this->getDatabaseGateway(); |
||
1127 | $gateway->deleteVersions(14); |
||
1128 | |||
1129 | $this->assertEquals( |
||
1130 | [ |
||
1131 | 'all' => $beforeCount['all'] - 2, |
||
1132 | 'this' => 0, |
||
1133 | ], |
||
1134 | [ |
||
1135 | 'all' => $this->countContentVersions(), |
||
1136 | 'this' => $this->countContentVersions(14), |
||
1137 | ] |
||
1138 | ); |
||
1139 | } |
||
1140 | |||
1141 | /** |
||
1142 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteVersions |
||
1143 | */ |
||
1144 | View Code Duplication | public function testDeleteVersionsWithSecondArgument() |
|
1145 | { |
||
1146 | $this->insertDatabaseFixture( |
||
1147 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1148 | ); |
||
1149 | |||
1150 | $beforeCount = [ |
||
1151 | 'all' => $this->countContentVersions(), |
||
1152 | 'this' => $this->countContentVersions(225), |
||
1153 | ]; |
||
1154 | |||
1155 | $gateway = $this->getDatabaseGateway(); |
||
1156 | $gateway->deleteVersions(225, 2); |
||
1157 | |||
1158 | $this->assertEquals( |
||
1159 | [ |
||
1160 | 'all' => $beforeCount['all'] - 1, |
||
1161 | 'this' => $beforeCount['this'] - 1, |
||
1162 | ], |
||
1163 | [ |
||
1164 | 'all' => $this->countContentVersions(), |
||
1165 | 'this' => $this->countContentVersions(225), |
||
1166 | ] |
||
1167 | ); |
||
1168 | } |
||
1169 | |||
1170 | /** |
||
1171 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::setName |
||
1172 | * |
||
1173 | * @throws \Exception |
||
1174 | */ |
||
1175 | public function testSetName() |
||
1176 | { |
||
1177 | $this->insertDatabaseFixture( |
||
1178 | __DIR__ . '/../_fixtures/contentobjects.php' |
||
1179 | ); |
||
1180 | |||
1181 | $gateway = $this->getDatabaseGateway(); |
||
1182 | |||
1183 | $gateway->setName(14, 2, 'Hello world!', 'eng-GB'); |
||
1184 | |||
1185 | $query = $this->getDatabaseHandler()->createSelectQuery(); |
||
1186 | $this->assertQueryResult( |
||
1187 | [['eng-GB', 2, 14, 4, 'Hello world!', 'eng-GB']], |
||
1188 | $query |
||
1189 | ->select( |
||
1190 | [ |
||
1191 | 'content_translation', |
||
1192 | 'content_version', |
||
1193 | 'contentobject_id', |
||
1194 | 'language_id', |
||
1195 | 'name', |
||
1196 | 'real_translation', |
||
1197 | ] |
||
1198 | ) |
||
1199 | ->from('ezcontentobject_name') |
||
1200 | ->where( |
||
1201 | $query->expr->lAnd( |
||
1202 | $query->expr->eq('contentobject_id', 14), |
||
1203 | $query->expr->eq('content_version', 2), |
||
1204 | $query->expr->eq('content_translation', $query->bindValue('eng-GB')) |
||
1205 | ) |
||
1206 | ) |
||
1207 | ); |
||
1208 | } |
||
1209 | |||
1210 | /** |
||
1211 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteNames |
||
1212 | */ |
||
1213 | View Code Duplication | public function testDeleteNames() |
|
1238 | |||
1239 | /** |
||
1240 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteNames |
||
1241 | */ |
||
1242 | View Code Duplication | public function testDeleteNamesWithSecondArgument() |
|
1267 | |||
1268 | /** |
||
1269 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteContent |
||
1270 | */ |
||
1271 | public function testDeleteContent() |
||
1293 | |||
1294 | /** |
||
1295 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadRelations |
||
1296 | * |
||
1297 | * @throws \Doctrine\DBAL\DBALException |
||
1298 | */ |
||
1299 | View Code Duplication | public function testLoadRelations(): void |
|
1300 | { |
||
1301 | $this->insertRelationFixture(); |
||
1302 | |||
1303 | $gateway = $this->getDatabaseGateway(); |
||
1304 | |||
1305 | $relations = $gateway->loadRelations(57); |
||
1306 | |||
1307 | $this->assertCount(3, $relations); |
||
1308 | |||
1309 | $this->assertValuesInRows( |
||
1310 | 'ezcontentobject_link_to_contentobject_id', |
||
1311 | [58, 59, 60], |
||
1312 | $relations |
||
1313 | ); |
||
1314 | |||
1315 | $this->assertValuesInRows( |
||
1316 | 'ezcontentobject_link_from_contentobject_id', |
||
1317 | [57], |
||
1318 | $relations |
||
1319 | ); |
||
1320 | $this->assertValuesInRows( |
||
1321 | 'ezcontentobject_link_from_contentobject_version', |
||
1322 | [2], |
||
1323 | $relations |
||
1324 | ); |
||
1325 | } |
||
1326 | |||
1327 | /** |
||
1328 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadRelations |
||
1329 | */ |
||
1330 | View Code Duplication | public function testLoadRelationsByType() |
|
1352 | |||
1353 | /** |
||
1354 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadRelations |
||
1355 | */ |
||
1356 | View Code Duplication | public function testLoadRelationsByVersion() |
|
1372 | |||
1373 | /** |
||
1374 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadRelations |
||
1375 | */ |
||
1376 | public function testLoadRelationsNoResult() |
||
1386 | |||
1387 | /** |
||
1388 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadReverseRelations |
||
1389 | */ |
||
1390 | View Code Duplication | public function testLoadReverseRelations() |
|
1406 | |||
1407 | /** |
||
1408 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::loadReverseRelations |
||
1409 | */ |
||
1410 | View Code Duplication | public function testLoadReverseRelationsWithType() |
|
1432 | |||
1433 | /** |
||
1434 | * Inserts the relation database fixture from relation_data.php. |
||
1435 | */ |
||
1436 | protected function insertRelationFixture() |
||
1442 | |||
1443 | /* |
||
1444 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::getLastVersionNumber |
||
1445 | * |
||
1446 | * @return void |
||
1447 | */ |
||
1448 | public function testGetLastVersionNumber() |
||
1461 | |||
1462 | /** |
||
1463 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::insertRelation |
||
1464 | */ |
||
1465 | public function testInsertRelation() |
||
1497 | |||
1498 | /** |
||
1499 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteRelation |
||
1500 | */ |
||
1501 | public function testDeleteRelation() |
||
1512 | |||
1513 | /** |
||
1514 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::deleteRelation |
||
1515 | */ |
||
1516 | public function testDeleteRelationWithCompositeBitmask() |
||
1536 | |||
1537 | /** |
||
1538 | * Test for the updateAlwaysAvailableFlag() method. |
||
1539 | * |
||
1540 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateAlwaysAvailableFlag |
||
1541 | */ |
||
1542 | View Code Duplication | public function testUpdateAlwaysAvailableFlagRemove() |
|
1594 | |||
1595 | /** |
||
1596 | * Test for the updateAlwaysAvailableFlag() method. |
||
1597 | * |
||
1598 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateAlwaysAvailableFlag |
||
1599 | */ |
||
1600 | View Code Duplication | public function testUpdateAlwaysAvailableFlagAdd() |
|
1652 | |||
1653 | /** |
||
1654 | * Test for the updateAlwaysAvailableFlag() method. |
||
1655 | * |
||
1656 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateAlwaysAvailableFlag |
||
1657 | */ |
||
1658 | View Code Duplication | public function testUpdateContentAddAlwaysAvailableFlagMultilingual() |
|
1720 | |||
1721 | /** |
||
1722 | * Test for the updateAlwaysAvailableFlag() method. |
||
1723 | * |
||
1724 | * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase::updateAlwaysAvailableFlag |
||
1725 | */ |
||
1726 | View Code Duplication | public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual() |
|
1788 | |||
1789 | View Code Duplication | public function testLoadVersionInfo() |
|
1806 | |||
1807 | /** |
||
1808 | * Counts the number of relations in the database. |
||
1809 | * |
||
1810 | * @param int $fromId |
||
1811 | * @param int $toId |
||
1812 | * |
||
1813 | * @return int |
||
1814 | */ |
||
1815 | protected function countContentRelations($fromId = null, $toId = null) |
||
1837 | |||
1838 | /** |
||
1839 | * Counts the number of fields. |
||
1840 | * |
||
1841 | * @param int $contentId |
||
1842 | * |
||
1843 | * @return int |
||
1844 | */ |
||
1845 | View Code Duplication | protected function countContentFields($contentId = null) |
|
1862 | |||
1863 | /** |
||
1864 | * Counts the number of versions. |
||
1865 | * |
||
1866 | * @param int $contentId |
||
1867 | * |
||
1868 | * @return int |
||
1869 | */ |
||
1870 | View Code Duplication | protected function countContentVersions($contentId = null) |
|
1887 | |||
1888 | /** |
||
1889 | * Counts the number of content names. |
||
1890 | * |
||
1891 | * @param int $contentId |
||
1892 | * |
||
1893 | * @return int |
||
1894 | */ |
||
1895 | View Code Duplication | protected function countContentNames($contentId = null) |
|
1912 | |||
1913 | /** |
||
1914 | * Counts the number of content objects. |
||
1915 | * |
||
1916 | * @param int $contentId |
||
1917 | * |
||
1918 | * @return int |
||
1919 | */ |
||
1920 | View Code Duplication | protected function countContent($contentId = null) |
|
1937 | |||
1938 | /** |
||
1939 | * Stores $fixture in $file to be required as a fixture. |
||
1940 | * |
||
1941 | * @param string $file |
||
1942 | * @param mixed $fixture |
||
1943 | */ |
||
1944 | protected function storeFixture($file, $fixture) |
||
1951 | |||
1952 | /** |
||
1953 | * Returns a Field fixture. |
||
1954 | * |
||
1955 | * @return Field |
||
1956 | */ |
||
1957 | protected function getFieldFixture() |
||
1968 | |||
1969 | /** |
||
1970 | * Returns a Field fixture in a different language. |
||
1971 | * |
||
1972 | * @return Field |
||
1973 | */ |
||
1974 | protected function getOtherLanguageFieldFixture() |
||
1981 | |||
1982 | /** |
||
1983 | * Returns a StorageFieldValue fixture. |
||
1984 | * |
||
1985 | * @return StorageFieldValue |
||
1986 | */ |
||
1987 | protected function getStorageValueFixture() |
||
1999 | |||
2000 | /** |
||
2001 | * Returns a ready to test DoctrineDatabase gateway. |
||
2002 | * |
||
2003 | * @throws \Doctrine\DBAL\DBALException |
||
2004 | */ |
||
2005 | protected function getDatabaseGateway(): DoctrineDatabase |
||
2020 | |||
2021 | /** |
||
2022 | * DoctrineDatabaseTest::getRelationCreateStructFixture(). |
||
2023 | * |
||
2024 | * @return \eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct |
||
2025 | */ |
||
2026 | View Code Duplication | protected function getRelationCreateStructFixture() |
|
2038 | } |
||
2039 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..