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 ContentServiceTest 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 ContentServiceTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class ContentServiceTest extends BaseContentServiceTest |
||
| 34 | { |
||
| 35 | /** |
||
| 36 | * Test for the newContentCreateStruct() method. |
||
| 37 | * |
||
| 38 | * @see \eZ\Publish\API\Repository\ContentService::newContentCreateStruct() |
||
| 39 | * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testLoadContentTypeByIdentifier |
||
| 40 | * @group user |
||
| 41 | * @group field-type |
||
| 42 | */ |
||
| 43 | public function testNewContentCreateStruct() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Test for the createContent() method. |
||
| 63 | * |
||
| 64 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 65 | * |
||
| 66 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 67 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
||
| 68 | * @group user |
||
| 69 | * @group field-type |
||
| 70 | */ |
||
| 71 | public function testCreateContent() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Test for the createContent() method. |
||
| 102 | * |
||
| 103 | * Tests made for issue #EZP-20955 where Anonymous user is granted access to create content |
||
| 104 | * and should have access to do that. |
||
| 105 | * |
||
| 106 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 107 | * |
||
| 108 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 109 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentCreateStruct |
||
| 110 | * @group user |
||
| 111 | * @group field-type |
||
| 112 | */ |
||
| 113 | public function testCreateContentAndPublishWithPrivilegedAnonymousUser() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Test for the createContent() method. |
||
| 166 | * |
||
| 167 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 168 | * |
||
| 169 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 170 | * |
||
| 171 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 172 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 173 | */ |
||
| 174 | public function testCreateContentSetsContentInfo($content) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Test for the createContent() method. |
||
| 183 | * |
||
| 184 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 185 | * |
||
| 186 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 187 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsContentInfo |
||
| 188 | */ |
||
| 189 | public function testCreateContentSetsExpectedContentInfo($content) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Test for the createContent() method. |
||
| 222 | * |
||
| 223 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 224 | * |
||
| 225 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 226 | * |
||
| 227 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 228 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 229 | */ |
||
| 230 | public function testCreateContentSetsVersionInfo($content) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Test for the createContent() method. |
||
| 239 | * |
||
| 240 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 241 | * |
||
| 242 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 243 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentSetsVersionInfo |
||
| 244 | */ |
||
| 245 | public function testCreateContentSetsExpectedVersionInfo($content) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Test for the createContent() method. |
||
| 265 | * |
||
| 266 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 267 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 268 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 269 | */ |
||
| 270 | public function testCreateContentThrowsInvalidArgumentException() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Test for the createContent() method. |
||
| 307 | * |
||
| 308 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 309 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 310 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 311 | */ |
||
| 312 | View Code Duplication | public function testCreateContentThrowsInvalidArgumentExceptionOnFieldTypeNotAccept() |
|
| 331 | |||
| 332 | /** |
||
| 333 | * Test for the createContent() method. |
||
| 334 | * |
||
| 335 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 336 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 337 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 338 | */ |
||
| 339 | public function testCreateContentThrowsContentFieldValidationException() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Test for the createContent() method. |
||
| 362 | * |
||
| 363 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 364 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 365 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 366 | */ |
||
| 367 | View Code Duplication | public function testCreateContentRequiredFieldMissing() |
|
| 385 | |||
| 386 | /** |
||
| 387 | * Test for the createContent() method. |
||
| 388 | * |
||
| 389 | * NOTE: We have bidirectional dependencies between the ContentService and |
||
| 390 | * the LocationService, so that we cannot use PHPUnit's test dependencies |
||
| 391 | * here. |
||
| 392 | * |
||
| 393 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 394 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testCreateLocation |
||
| 395 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationByRemoteId |
||
| 396 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 397 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 398 | * @group user |
||
| 399 | */ |
||
| 400 | public function testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Test for the createContent() method. |
||
| 419 | * |
||
| 420 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 421 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 422 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 423 | */ |
||
| 424 | public function testCreateContentThrowsInvalidArgumentExceptionWithLocationCreateParameter() |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Test for the loadContentInfo() method. |
||
| 481 | * |
||
| 482 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
||
| 483 | * @group user |
||
| 484 | */ |
||
| 485 | View Code Duplication | public function testLoadContentInfo() |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Test for the returned value of the loadContentInfo() method. |
||
| 507 | * |
||
| 508 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 509 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfo |
||
| 510 | * |
||
| 511 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 512 | */ |
||
| 513 | public function testLoadContentInfoSetsExpectedContentInfo(ContentInfo $contentInfo) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Test for the loadContentInfo() method. |
||
| 523 | * |
||
| 524 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
||
| 525 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 526 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 527 | */ |
||
| 528 | View Code Duplication | public function testLoadContentInfoThrowsNotFoundException() |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Test for the loadContentInfoByRemoteId() method. |
||
| 543 | * |
||
| 544 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
||
| 545 | */ |
||
| 546 | public function testLoadContentInfoByRemoteId() |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Test for the returned value of the loadContentInfoByRemoteId() method. |
||
| 564 | * |
||
| 565 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
||
| 566 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId |
||
| 567 | * |
||
| 568 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 569 | */ |
||
| 570 | View Code Duplication | public function testLoadContentInfoByRemoteIdSetsExpectedContentInfo(ContentInfo $contentInfo) |
|
| 591 | |||
| 592 | /** |
||
| 593 | * Test for the loadContentInfoByRemoteId() method. |
||
| 594 | * |
||
| 595 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoByRemoteId() |
||
| 596 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 597 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoByRemoteId |
||
| 598 | */ |
||
| 599 | public function testLoadContentInfoByRemoteIdThrowsNotFoundException() |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Test for the loadVersionInfo() method. |
||
| 613 | * |
||
| 614 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
||
| 615 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 616 | * @group user |
||
| 617 | */ |
||
| 618 | public function testLoadVersionInfo() |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Test for the loadVersionInfoById() method. |
||
| 643 | * |
||
| 644 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
||
| 645 | */ |
||
| 646 | View Code Duplication | public function testLoadVersionInfoById() |
|
| 667 | |||
| 668 | /** |
||
| 669 | * Test for the returned value of the loadVersionInfoById() method. |
||
| 670 | * |
||
| 671 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
||
| 672 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById |
||
| 673 | * |
||
| 674 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 675 | */ |
||
| 676 | public function testLoadVersionInfoByIdSetsExpectedVersionInfo(VersionInfo $versionInfo) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Test for the loadVersionInfoById() method. |
||
| 701 | * |
||
| 702 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
||
| 703 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 704 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById |
||
| 705 | */ |
||
| 706 | View Code Duplication | public function testLoadVersionInfoByIdThrowsNotFoundException() |
|
| 718 | |||
| 719 | /** |
||
| 720 | * Test for the loadContentByContentInfo() method. |
||
| 721 | * |
||
| 722 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
||
| 723 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 724 | */ |
||
| 725 | public function testLoadContentByContentInfo() |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Test for the loadContentByVersionInfo() method. |
||
| 750 | * |
||
| 751 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
||
| 752 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 753 | */ |
||
| 754 | public function testLoadContentByVersionInfo() |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Test for the loadContent() method. |
||
| 782 | * |
||
| 783 | * @see \eZ\Publish\API\Repository\ContentService::loadContent() |
||
| 784 | * @group user |
||
| 785 | * @group field-type |
||
| 786 | */ |
||
| 787 | View Code Duplication | public function testLoadContent() |
|
| 806 | |||
| 807 | /** |
||
| 808 | * Test for the loadContent() method. |
||
| 809 | * |
||
| 810 | * @see \eZ\Publish\API\Repository\ContentService::loadContent() |
||
| 811 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 812 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 813 | */ |
||
| 814 | View Code Duplication | public function testLoadContentThrowsNotFoundException() |
|
| 826 | |||
| 827 | /** |
||
| 828 | * Data provider for testLoadContentByRemoteId(). |
||
| 829 | * |
||
| 830 | * @return array |
||
| 831 | */ |
||
| 832 | public function contentRemoteIdVersionLanguageProvider() |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Test for the loadContentByRemoteId() method. |
||
| 848 | * |
||
| 849 | * @covers \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId |
||
| 850 | * @dataProvider contentRemoteIdVersionLanguageProvider |
||
| 851 | * |
||
| 852 | * @param string $remoteId |
||
| 853 | * @param array|null $languages |
||
| 854 | * @param int $versionNo |
||
| 855 | */ |
||
| 856 | public function testLoadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 875 | |||
| 876 | /** |
||
| 877 | * Test for the loadContentByRemoteId() method. |
||
| 878 | * |
||
| 879 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId() |
||
| 880 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 881 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
||
| 882 | */ |
||
| 883 | public function testLoadContentByRemoteIdThrowsNotFoundException() |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Test for the publishVersion() method. |
||
| 898 | * |
||
| 899 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 900 | * |
||
| 901 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 902 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 903 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 904 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 905 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 906 | * @group user |
||
| 907 | * @group field-type |
||
| 908 | */ |
||
| 909 | public function testPublishVersion() |
||
| 924 | |||
| 925 | /** |
||
| 926 | * Test for the publishVersion() method. |
||
| 927 | * |
||
| 928 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 929 | * |
||
| 930 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 931 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 932 | */ |
||
| 933 | public function testPublishVersionSetsExpectedContentInfo($content) |
||
| 963 | |||
| 964 | /** |
||
| 965 | * Test for the publishVersion() method. |
||
| 966 | * |
||
| 967 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 968 | * |
||
| 969 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 970 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 971 | */ |
||
| 972 | public function testPublishVersionSetsExpectedVersionInfo($content) |
||
| 997 | |||
| 998 | /** |
||
| 999 | * Test for the publishVersion() method. |
||
| 1000 | * |
||
| 1001 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1002 | * |
||
| 1003 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1004 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 1005 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1006 | */ |
||
| 1007 | public function testPublishVersionCreatesLocationsDefinedOnCreate() |
||
| 1027 | |||
| 1028 | /** |
||
| 1029 | * Test for the publishVersion() method. |
||
| 1030 | * |
||
| 1031 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1032 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionCreatesLocationsDefinedOnCreate |
||
| 1033 | */ |
||
| 1034 | public function testCreateContentWithLocationCreateParameterCreatesExpectedLocation(array $testData) |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Test for the publishVersion() method. |
||
| 1063 | * |
||
| 1064 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1065 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1066 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1067 | */ |
||
| 1068 | View Code Duplication | public function testPublishVersionThrowsBadStateException() |
|
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Test that publishVersion() does not affect publishedDate (assuming previous version exists). |
||
| 1088 | * |
||
| 1089 | * @covers \eZ\Publish\API\Repository\ContentService::publishVersion |
||
| 1090 | */ |
||
| 1091 | public function testPublishVersionDoesNotChangePublishedDate() |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Test for the createContentDraft() method. |
||
| 1120 | * |
||
| 1121 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1122 | * |
||
| 1123 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1124 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1125 | * @group user |
||
| 1126 | */ |
||
| 1127 | public function testCreateContentDraft() |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * Test for the createContentDraft() method. |
||
| 1150 | * |
||
| 1151 | * Test that editor has access to edit own draft. |
||
| 1152 | * Note: Editors have access to version_read, which is needed to load content drafts. |
||
| 1153 | * |
||
| 1154 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1155 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1156 | * @group user |
||
| 1157 | */ |
||
| 1158 | View Code Duplication | public function testCreateContentDraftAndLoadAccess() |
|
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Test for the createContentDraft() method. |
||
| 1182 | * |
||
| 1183 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1184 | * |
||
| 1185 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1186 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1187 | */ |
||
| 1188 | public function testCreateContentDraftSetsExpectedProperties($draft) |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Test for the createContentDraft() method. |
||
| 1204 | * |
||
| 1205 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1206 | * |
||
| 1207 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1208 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1209 | */ |
||
| 1210 | public function testCreateContentDraftSetsContentInfo($draft) |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Test for the createContentDraft() method. |
||
| 1238 | * |
||
| 1239 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1240 | * |
||
| 1241 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1242 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1243 | */ |
||
| 1244 | public function testCreateContentDraftSetsVersionInfo($draft) |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Test for the createContentDraft() method. |
||
| 1268 | * |
||
| 1269 | * @param \eZ\Publish\API\Repository\Values\Content\Content $draft |
||
| 1270 | * |
||
| 1271 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1272 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1273 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 1274 | */ |
||
| 1275 | public function testCreateContentDraftLoadVersionInfoStillLoadsPublishedVersion($draft) |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Test for the createContentDraft() method. |
||
| 1296 | * |
||
| 1297 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1298 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 1299 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1300 | */ |
||
| 1301 | public function testCreateContentDraftLoadContentStillLoadsPublishedVersion() |
||
| 1319 | |||
| 1320 | /** |
||
| 1321 | * Test for the createContentDraft() method. |
||
| 1322 | * |
||
| 1323 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1324 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteId |
||
| 1325 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1326 | */ |
||
| 1327 | public function testCreateContentDraftLoadContentByRemoteIdStillLoadsPublishedVersion() |
||
| 1345 | |||
| 1346 | /** |
||
| 1347 | * Test for the createContentDraft() method. |
||
| 1348 | * |
||
| 1349 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 1350 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 1351 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1352 | */ |
||
| 1353 | public function testCreateContentDraftLoadContentByContentInfoStillLoadsPublishedVersion() |
||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Test for the newContentUpdateStruct() method. |
||
| 1374 | * |
||
| 1375 | * @covers \eZ\Publish\API\Repository\ContentService::newContentUpdateStruct |
||
| 1376 | * @group user |
||
| 1377 | */ |
||
| 1378 | public function testNewContentUpdateStruct() |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Test for the updateContent() method. |
||
| 1404 | * |
||
| 1405 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1406 | * |
||
| 1407 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1408 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
||
| 1409 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1410 | * @group user |
||
| 1411 | * @group field-type |
||
| 1412 | */ |
||
| 1413 | public function testUpdateContent() |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Test for the updateContent_WithDifferentUser() method. |
||
| 1435 | * |
||
| 1436 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1437 | * |
||
| 1438 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1439 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentUpdateStruct |
||
| 1440 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 1441 | * @group user |
||
| 1442 | * @group field-type |
||
| 1443 | */ |
||
| 1444 | public function testUpdateContentWithDifferentUser() |
||
| 1463 | |||
| 1464 | /** |
||
| 1465 | * Test for the updateContent() method. |
||
| 1466 | * |
||
| 1467 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1468 | * |
||
| 1469 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1470 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1471 | */ |
||
| 1472 | public function testUpdateContentSetsExpectedFields($content) |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * Test for the updateContent() method. |
||
| 1516 | * |
||
| 1517 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1518 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 1519 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1520 | */ |
||
| 1521 | public function testUpdateContentThrowsBadStateException() |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Test for the updateContent() method. |
||
| 1548 | * |
||
| 1549 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1550 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 1551 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1552 | */ |
||
| 1553 | View Code Duplication | public function testUpdateContentThrowsInvalidArgumentExceptionWhenFieldTypeDoesNotAccept() |
|
| 1575 | |||
| 1576 | /** |
||
| 1577 | * Test for the updateContent() method. |
||
| 1578 | * |
||
| 1579 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1580 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 1581 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1582 | */ |
||
| 1583 | View Code Duplication | public function testUpdateContentWhenMandatoryFieldIsEmpty() |
|
| 1607 | |||
| 1608 | /** |
||
| 1609 | * Test for the updateContent() method. |
||
| 1610 | * |
||
| 1611 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1612 | * @expectedException \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
||
| 1613 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1614 | */ |
||
| 1615 | public function testUpdateContentThrowsContentFieldValidationException() |
||
| 1639 | |||
| 1640 | /** |
||
| 1641 | * Test for the updateContent() method. |
||
| 1642 | * |
||
| 1643 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 1644 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1645 | */ |
||
| 1646 | public function testUpdateContentWithNotUpdatingMandatoryField() |
||
| 1684 | |||
| 1685 | /** |
||
| 1686 | * Test for the createContentDraft() method. |
||
| 1687 | * |
||
| 1688 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft($contentInfo, $versionInfo) |
||
| 1689 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1690 | */ |
||
| 1691 | public function testCreateContentDraftWithSecondParameter() |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * Test for the createContentDraft() method with third parameter. |
||
| 1712 | * |
||
| 1713 | * @covers \eZ\Publish\Core\Repository\ContentService::createContentDraft |
||
| 1714 | */ |
||
| 1715 | View Code Duplication | public function testCreateContentDraftWithThirdParameter() |
|
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Test for the publishVersion() method. |
||
| 1738 | * |
||
| 1739 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1740 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1741 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 1742 | */ |
||
| 1743 | View Code Duplication | public function testPublishVersionFromContentDraft() |
|
| 1766 | |||
| 1767 | /** |
||
| 1768 | * Test for the publishVersion() method. |
||
| 1769 | * |
||
| 1770 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1771 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1772 | */ |
||
| 1773 | View Code Duplication | public function testPublishVersionFromContentDraftArchivesOldVersion() |
|
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Test for the publishVersion() method. |
||
| 1799 | * |
||
| 1800 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1801 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1802 | */ |
||
| 1803 | public function testPublishVersionFromContentDraftUpdatesContentInfoCurrentVersion() |
||
| 1811 | |||
| 1812 | /** |
||
| 1813 | * Test for the publishVersion() method. |
||
| 1814 | * |
||
| 1815 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1816 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1817 | */ |
||
| 1818 | public function testPublishVersionFromOldContentDraftArchivesNewerVersionNo() |
||
| 1843 | |||
| 1844 | /** |
||
| 1845 | * Test for the publishVersion() method, and that it creates limited archives. |
||
| 1846 | * |
||
| 1847 | * @todo Adapt this when per content type archive limited is added on repository Content Type model. |
||
| 1848 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 1849 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 1850 | */ |
||
| 1851 | public function testPublishVersionNotCreatingUnlimitedArchives() |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * Test for the newContentMetadataUpdateStruct() method. |
||
| 1911 | * |
||
| 1912 | * @covers \eZ\Publish\API\Repository\ContentService::newContentMetadataUpdateStruct |
||
| 1913 | * @group user |
||
| 1914 | */ |
||
| 1915 | public function testNewContentMetadataUpdateStruct() |
||
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Test for the updateContentMetadata() method. |
||
| 1942 | * |
||
| 1943 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 1944 | * |
||
| 1945 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1946 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 1947 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testNewContentMetadataUpdateStruct |
||
| 1948 | * @group user |
||
| 1949 | */ |
||
| 1950 | public function testUpdateContentMetadata() |
||
| 1982 | |||
| 1983 | /** |
||
| 1984 | * Test for the updateContentMetadata() method. |
||
| 1985 | * |
||
| 1986 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 1987 | * |
||
| 1988 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 1989 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 1990 | */ |
||
| 1991 | public function testUpdateContentMetadataSetsExpectedProperties($content) |
||
| 2020 | |||
| 2021 | /** |
||
| 2022 | * Test for the updateContentMetadata() method. |
||
| 2023 | * |
||
| 2024 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 2025 | * |
||
| 2026 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 2027 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 2028 | */ |
||
| 2029 | public function testUpdateContentMetadataNotUpdatesContentVersion($content) |
||
| 2033 | |||
| 2034 | /** |
||
| 2035 | * Test for the updateContentMetadata() method. |
||
| 2036 | * |
||
| 2037 | * @covers \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 2038 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2039 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 2040 | */ |
||
| 2041 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnDuplicateRemoteId() |
||
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Test for the updateContentMetadata() method. |
||
| 2068 | * |
||
| 2069 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContentMetadata |
||
| 2070 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 2071 | */ |
||
| 2072 | public function testUpdateContentMetadataThrowsInvalidArgumentExceptionOnNoMetadataPropertiesSet() |
||
| 2084 | |||
| 2085 | /** |
||
| 2086 | * Test for the deleteContent() method. |
||
| 2087 | * |
||
| 2088 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 2089 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2090 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2091 | */ |
||
| 2092 | View Code Duplication | public function testDeleteContent() |
|
| 2113 | |||
| 2114 | /** |
||
| 2115 | * Test for the deleteContent() method. |
||
| 2116 | * |
||
| 2117 | * Test for issue EZP-21057: |
||
| 2118 | * "contentService: Unable to delete a content with an empty file attribute" |
||
| 2119 | * |
||
| 2120 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 2121 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2122 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2123 | */ |
||
| 2124 | View Code Duplication | public function testDeleteContentWithEmptyBinaryField() |
|
| 2145 | |||
| 2146 | /** |
||
| 2147 | * Test for the loadContentDrafts() method. |
||
| 2148 | * |
||
| 2149 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2150 | */ |
||
| 2151 | public function testLoadContentDraftsReturnsEmptyArrayByDefault() |
||
| 2163 | |||
| 2164 | /** |
||
| 2165 | * Test for the loadContentDrafts() method. |
||
| 2166 | * |
||
| 2167 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts() |
||
| 2168 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 2169 | */ |
||
| 2170 | public function testLoadContentDrafts() |
||
| 2214 | |||
| 2215 | /** |
||
| 2216 | * Test for the loadContentDrafts() method. |
||
| 2217 | * |
||
| 2218 | * @see \eZ\Publish\API\Repository\ContentService::loadContentDrafts($user) |
||
| 2219 | */ |
||
| 2220 | public function testLoadContentDraftsWithFirstParameter() |
||
| 2265 | |||
| 2266 | /** |
||
| 2267 | * Test for the loadVersionInfo() method. |
||
| 2268 | * |
||
| 2269 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
||
| 2270 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2271 | */ |
||
| 2272 | public function testLoadVersionInfoWithSecondParameter() |
||
| 2295 | |||
| 2296 | /** |
||
| 2297 | * Test for the loadVersionInfo() method. |
||
| 2298 | * |
||
| 2299 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo($contentInfo, $versionNo) |
||
| 2300 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2301 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
||
| 2302 | */ |
||
| 2303 | public function testLoadVersionInfoThrowsNotFoundExceptionWithSecondParameter() |
||
| 2317 | |||
| 2318 | /** |
||
| 2319 | * Test for the loadVersionInfoById() method. |
||
| 2320 | * |
||
| 2321 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
||
| 2322 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoWithSecondParameter |
||
| 2323 | */ |
||
| 2324 | public function testLoadVersionInfoByIdWithSecondParameter() |
||
| 2352 | |||
| 2353 | /** |
||
| 2354 | * Test for the returned value of the loadVersionInfoById() method. |
||
| 2355 | * |
||
| 2356 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter |
||
| 2357 | * @covers \eZ\Publish\API\Repository\ContentService::loadVersionInfoById |
||
| 2358 | * |
||
| 2359 | * @param array $data |
||
| 2360 | */ |
||
| 2361 | public function testLoadVersionInfoByIdWithSecondParameterSetsExpectedVersionInfo(array $data) |
||
| 2401 | |||
| 2402 | /** |
||
| 2403 | * Test for the loadVersionInfoById() method. |
||
| 2404 | * |
||
| 2405 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById($contentId, $versionNo) |
||
| 2406 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2407 | */ |
||
| 2408 | View Code Duplication | public function testLoadVersionInfoByIdThrowsNotFoundExceptionWithSecondParameter() |
|
| 2422 | |||
| 2423 | /** |
||
| 2424 | * Test for the loadContentByVersionInfo() method. |
||
| 2425 | * |
||
| 2426 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo($versionInfo, $languages) |
||
| 2427 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2428 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
||
| 2429 | */ |
||
| 2430 | public function testLoadContentByVersionInfoWithSecondParameter() |
||
| 2512 | |||
| 2513 | /** |
||
| 2514 | * Test for the loadContentByContentInfo() method. |
||
| 2515 | * |
||
| 2516 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages) |
||
| 2517 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 2518 | */ |
||
| 2519 | public function testLoadContentByContentInfoWithLanguageParameters() |
||
| 2648 | |||
| 2649 | /** |
||
| 2650 | * Test for the loadContentByContentInfo() method. |
||
| 2651 | * |
||
| 2652 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
||
| 2653 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
||
| 2654 | */ |
||
| 2655 | View Code Duplication | public function testLoadContentByContentInfoWithVersionNumberParameter() |
|
| 2685 | |||
| 2686 | /** |
||
| 2687 | * Test for the loadContentByContentInfo() method. |
||
| 2688 | * |
||
| 2689 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo($contentInfo, $languages, $versionNo) |
||
| 2690 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2691 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfoWithVersionNumberParameter |
||
| 2692 | */ |
||
| 2693 | View Code Duplication | public function testLoadContentByContentInfoThrowsNotFoundExceptionWithVersionNumberParameter() |
|
| 2707 | |||
| 2708 | /** |
||
| 2709 | * Test for the loadContent() method. |
||
| 2710 | * |
||
| 2711 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages) |
||
| 2712 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2713 | */ |
||
| 2714 | View Code Duplication | public function testLoadContentWithSecondParameter() |
|
| 2731 | |||
| 2732 | /** |
||
| 2733 | * Test for the loadContent() method using undefined translation. |
||
| 2734 | * |
||
| 2735 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithSecondParameter |
||
| 2736 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2737 | * |
||
| 2738 | * @param \eZ\Publish\API\Repository\Values\Content\Content $contentDraft |
||
| 2739 | */ |
||
| 2740 | public function testLoadContentWithSecondParameterThrowsNotFoundException(Content $contentDraft) |
||
| 2748 | |||
| 2749 | /** |
||
| 2750 | * Test for the loadContent() method. |
||
| 2751 | * |
||
| 2752 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
||
| 2753 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2754 | */ |
||
| 2755 | View Code Duplication | public function testLoadContentWithThirdParameter() |
|
| 2778 | |||
| 2779 | /** |
||
| 2780 | * Test for the loadContent() method. |
||
| 2781 | * |
||
| 2782 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
||
| 2783 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2784 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
||
| 2785 | */ |
||
| 2786 | View Code Duplication | public function testLoadContentThrowsNotFoundExceptionWithThirdParameter() |
|
| 2800 | |||
| 2801 | /** |
||
| 2802 | * Test for the loadContentByRemoteId() method. |
||
| 2803 | * |
||
| 2804 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages) |
||
| 2805 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2806 | */ |
||
| 2807 | View Code Duplication | public function testLoadContentByRemoteIdWithSecondParameter() |
|
| 2829 | |||
| 2830 | /** |
||
| 2831 | * Test for the loadContentByRemoteId() method. |
||
| 2832 | * |
||
| 2833 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 2834 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 2835 | */ |
||
| 2836 | View Code Duplication | public function testLoadContentByRemoteIdWithThirdParameter() |
|
| 2863 | |||
| 2864 | /** |
||
| 2865 | * Test for the loadContentByRemoteId() method. |
||
| 2866 | * |
||
| 2867 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByRemoteId($remoteId, $languages, $versionNo) |
||
| 2868 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 2869 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByRemoteIdWithThirdParameter |
||
| 2870 | */ |
||
| 2871 | public function testLoadContentByRemoteIdThrowsNotFoundExceptionWithThirdParameter() |
||
| 2889 | |||
| 2890 | /** |
||
| 2891 | * Test for the deleteVersion() method. |
||
| 2892 | * |
||
| 2893 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2894 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2895 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2896 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2897 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 2898 | */ |
||
| 2899 | public function testDeleteVersion() |
||
| 2925 | |||
| 2926 | /** |
||
| 2927 | * Test for the deleteVersion() method. |
||
| 2928 | * |
||
| 2929 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2930 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 2931 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2932 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2933 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2934 | */ |
||
| 2935 | public function testDeleteVersionThrowsBadStateExceptionOnPublishedVersion() |
||
| 2949 | |||
| 2950 | /** |
||
| 2951 | * Test for the deleteVersion() method. |
||
| 2952 | * |
||
| 2953 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 2954 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 2955 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 2956 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 2957 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2958 | */ |
||
| 2959 | View Code Duplication | public function testDeleteVersionThrowsBadStateExceptionOnLastVersion() |
|
| 2973 | |||
| 2974 | /** |
||
| 2975 | * Test for the loadVersions() method. |
||
| 2976 | * |
||
| 2977 | * @see \eZ\Publish\API\Repository\ContentService::loadVersions() |
||
| 2978 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 2979 | * |
||
| 2980 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] |
||
| 2981 | */ |
||
| 2982 | public function testLoadVersions() |
||
| 3004 | |||
| 3005 | /** |
||
| 3006 | * Test for the loadVersions() method. |
||
| 3007 | * |
||
| 3008 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
||
| 3009 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersions |
||
| 3010 | * |
||
| 3011 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo[] $versions |
||
| 3012 | */ |
||
| 3013 | public function testLoadVersionsSetsExpectedVersionInfo(array $versions) |
||
| 3014 | { |
||
| 3015 | $this->assertCount(2, $versions); |
||
| 3016 | |||
| 3017 | $expectedVersions = [ |
||
| 3018 | [ |
||
| 3019 | 'versionNo' => 1, |
||
| 3020 | 'creatorId' => 14, |
||
| 3021 | 'status' => VersionInfo::STATUS_ARCHIVED, |
||
| 3022 | 'initialLanguageCode' => 'eng-US', |
||
| 3023 | 'languageCodes' => ['eng-US'], |
||
| 3024 | ], |
||
| 3025 | [ |
||
| 3026 | 'versionNo' => 2, |
||
| 3027 | 'creatorId' => 10, |
||
| 3028 | 'status' => VersionInfo::STATUS_PUBLISHED, |
||
| 3029 | 'initialLanguageCode' => 'eng-US', |
||
| 3030 | 'languageCodes' => ['eng-US', 'eng-GB'], |
||
| 3031 | ], |
||
| 3032 | ]; |
||
| 3033 | |||
| 3034 | $this->assertPropertiesCorrect($expectedVersions[0], $versions[0]); |
||
| 3035 | $this->assertPropertiesCorrect($expectedVersions[1], $versions[1]); |
||
| 3036 | $this->assertEquals( |
||
| 3037 | $versions[0]->creationDate->getTimestamp(), |
||
| 3038 | $versions[1]->creationDate->getTimestamp(), |
||
| 3039 | 'Creation time did not match within delta of 2 seconds', |
||
| 3040 | 2 |
||
| 3041 | ); |
||
| 3042 | $this->assertEquals( |
||
| 3043 | $versions[0]->modificationDate->getTimestamp(), |
||
| 3044 | $versions[1]->modificationDate->getTimestamp(), |
||
| 3045 | 'Creation time did not match within delta of 2 seconds', |
||
| 3046 | 2 |
||
| 3047 | ); |
||
| 3048 | } |
||
| 3049 | |||
| 3050 | /** |
||
| 3051 | * Test for the copyContent() method. |
||
| 3052 | * |
||
| 3053 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 3054 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 3055 | * @group field-type |
||
| 3056 | */ |
||
| 3057 | View Code Duplication | public function testCopyContent() |
|
| 3058 | { |
||
| 3059 | $parentLocationId = $this->generateId('location', 56); |
||
| 3060 | |||
| 3061 | $repository = $this->getRepository(); |
||
| 3062 | |||
| 3063 | $contentService = $repository->getContentService(); |
||
| 3064 | $locationService = $repository->getLocationService(); |
||
| 3065 | |||
| 3066 | /* BEGIN: Use Case */ |
||
| 3067 | $contentVersion2 = $this->createMultipleLanguageContentVersion2(); |
||
| 3068 | |||
| 3069 | // Configure new target location |
||
| 3070 | $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
||
| 3071 | |||
| 3072 | $targetLocationCreate->priority = 42; |
||
| 3073 | $targetLocationCreate->hidden = true; |
||
| 3074 | $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
||
| 3075 | $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 3076 | $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
| 3077 | |||
| 3078 | // Copy content with all versions and drafts |
||
| 3079 | $contentCopied = $contentService->copyContent( |
||
| 3080 | $contentVersion2->contentInfo, |
||
| 3081 | $targetLocationCreate |
||
| 3082 | ); |
||
| 3083 | /* END: Use Case */ |
||
| 3084 | |||
| 3085 | $this->assertInstanceOf( |
||
| 3086 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 3087 | $contentCopied |
||
| 3088 | ); |
||
| 3089 | |||
| 3090 | $this->assertNotEquals( |
||
| 3091 | $contentVersion2->contentInfo->remoteId, |
||
| 3092 | $contentCopied->contentInfo->remoteId |
||
| 3093 | ); |
||
| 3094 | |||
| 3095 | $this->assertNotEquals( |
||
| 3096 | $contentVersion2->id, |
||
| 3097 | $contentCopied->id |
||
| 3098 | ); |
||
| 3099 | |||
| 3100 | $this->assertEquals( |
||
| 3101 | 2, |
||
| 3102 | count($contentService->loadVersions($contentCopied->contentInfo)) |
||
| 3103 | ); |
||
| 3104 | |||
| 3105 | $this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo); |
||
| 3106 | |||
| 3107 | $this->assertAllFieldsEquals($contentCopied->getFields()); |
||
| 3108 | |||
| 3109 | $this->assertDefaultContentStates($contentCopied->contentInfo); |
||
| 3110 | |||
| 3111 | $this->assertNotNull( |
||
| 3112 | $contentCopied->contentInfo->mainLocationId, |
||
| 3113 | 'Expected main location to be set given we provided a LocationCreateStruct' |
||
| 3114 | ); |
||
| 3115 | } |
||
| 3116 | |||
| 3117 | /** |
||
| 3118 | * Test for the copyContent() method. |
||
| 3119 | * |
||
| 3120 | * @see \eZ\Publish\API\Repository\ContentService::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo) |
||
| 3121 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 3122 | * |
||
| 3123 | * @todo Fix to more descriptive name |
||
| 3124 | */ |
||
| 3125 | View Code Duplication | public function testCopyContentWithThirdParameter() |
|
| 3126 | { |
||
| 3127 | $parentLocationId = $this->generateId('location', 56); |
||
| 3128 | |||
| 3129 | $repository = $this->getRepository(); |
||
| 3130 | |||
| 3131 | $contentService = $repository->getContentService(); |
||
| 3132 | $locationService = $repository->getLocationService(); |
||
| 3133 | |||
| 3134 | /* BEGIN: Use Case */ |
||
| 3135 | $contentVersion2 = $this->createContentVersion2(); |
||
| 3136 | |||
| 3137 | // Configure new target location |
||
| 3138 | $targetLocationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
||
| 3139 | |||
| 3140 | $targetLocationCreate->priority = 42; |
||
| 3141 | $targetLocationCreate->hidden = true; |
||
| 3142 | $targetLocationCreate->remoteId = '01234abcdef5678901234abcdef56789'; |
||
| 3143 | $targetLocationCreate->sortField = Location::SORT_FIELD_NODE_ID; |
||
| 3144 | $targetLocationCreate->sortOrder = Location::SORT_ORDER_DESC; |
||
| 3145 | |||
| 3146 | // Copy only the initial version |
||
| 3147 | $contentCopied = $contentService->copyContent( |
||
| 3148 | $contentVersion2->contentInfo, |
||
| 3149 | $targetLocationCreate, |
||
| 3150 | $contentService->loadVersionInfo($contentVersion2->contentInfo, 1) |
||
| 3151 | ); |
||
| 3152 | /* END: Use Case */ |
||
| 3153 | |||
| 3154 | $this->assertInstanceOf( |
||
| 3155 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
||
| 3156 | $contentCopied |
||
| 3157 | ); |
||
| 3158 | |||
| 3159 | $this->assertNotEquals( |
||
| 3160 | $contentVersion2->contentInfo->remoteId, |
||
| 3161 | $contentCopied->contentInfo->remoteId |
||
| 3162 | ); |
||
| 3163 | |||
| 3164 | $this->assertNotEquals( |
||
| 3165 | $contentVersion2->id, |
||
| 3166 | $contentCopied->id |
||
| 3167 | ); |
||
| 3168 | |||
| 3169 | $this->assertEquals( |
||
| 3170 | 1, |
||
| 3171 | count($contentService->loadVersions($contentCopied->contentInfo)) |
||
| 3172 | ); |
||
| 3173 | |||
| 3174 | $this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo); |
||
| 3175 | |||
| 3176 | $this->assertNotNull( |
||
| 3177 | $contentCopied->contentInfo->mainLocationId, |
||
| 3178 | 'Expected main location to be set given we provided a LocationCreateStruct' |
||
| 3179 | ); |
||
| 3180 | } |
||
| 3181 | |||
| 3182 | /** |
||
| 3183 | * Test for the addRelation() method. |
||
| 3184 | * |
||
| 3185 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 3186 | * |
||
| 3187 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3188 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft |
||
| 3189 | */ |
||
| 3190 | public function testAddRelation() |
||
| 3191 | { |
||
| 3192 | $repository = $this->getRepository(); |
||
| 3193 | |||
| 3194 | $contentService = $repository->getContentService(); |
||
| 3195 | |||
| 3196 | /* BEGIN: Use Case */ |
||
| 3197 | // RemoteId of the "Media" content of an eZ Publish demo installation |
||
| 3198 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3199 | |||
| 3200 | $draft = $this->createContentDraftVersion1(); |
||
| 3201 | |||
| 3202 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3203 | |||
| 3204 | // Create relation between new content object and "Media" page |
||
| 3205 | $relation = $contentService->addRelation( |
||
| 3206 | $draft->getVersionInfo(), |
||
| 3207 | $media |
||
| 3208 | ); |
||
| 3209 | /* END: Use Case */ |
||
| 3210 | |||
| 3211 | $this->assertInstanceOf( |
||
| 3212 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Relation', |
||
| 3213 | $relation |
||
| 3214 | ); |
||
| 3215 | |||
| 3216 | return $contentService->loadRelations($draft->getVersionInfo()); |
||
| 3217 | } |
||
| 3218 | |||
| 3219 | /** |
||
| 3220 | * Test for the addRelation() method. |
||
| 3221 | * |
||
| 3222 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3223 | * |
||
| 3224 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3225 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3226 | */ |
||
| 3227 | public function testAddRelationAddsRelationToContent($relations) |
||
| 3228 | { |
||
| 3229 | $this->assertEquals( |
||
| 3230 | 1, |
||
| 3231 | count($relations) |
||
| 3232 | ); |
||
| 3233 | } |
||
| 3234 | |||
| 3235 | /** |
||
| 3236 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3237 | */ |
||
| 3238 | protected function assertExpectedRelations($relations) |
||
| 3239 | { |
||
| 3240 | $this->assertEquals( |
||
| 3241 | array( |
||
| 3242 | 'type' => Relation::COMMON, |
||
| 3243 | 'sourceFieldDefinitionIdentifier' => null, |
||
| 3244 | 'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3245 | 'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3246 | ), |
||
| 3247 | array( |
||
| 3248 | 'type' => $relations[0]->type, |
||
| 3249 | 'sourceFieldDefinitionIdentifier' => $relations[0]->sourceFieldDefinitionIdentifier, |
||
| 3250 | 'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
||
| 3251 | 'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
||
| 3252 | ) |
||
| 3253 | ); |
||
| 3254 | } |
||
| 3255 | |||
| 3256 | /** |
||
| 3257 | * Test for the addRelation() method. |
||
| 3258 | * |
||
| 3259 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3260 | * |
||
| 3261 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3262 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3263 | */ |
||
| 3264 | public function testAddRelationSetsExpectedRelations($relations) |
||
| 3265 | { |
||
| 3266 | $this->assertExpectedRelations($relations); |
||
| 3267 | } |
||
| 3268 | |||
| 3269 | /** |
||
| 3270 | * Test for the createContentDraft() method. |
||
| 3271 | * |
||
| 3272 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 3273 | * |
||
| 3274 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 3275 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
||
| 3276 | */ |
||
| 3277 | View Code Duplication | public function testCreateContentDraftWithRelations() |
|
| 3278 | { |
||
| 3279 | $repository = $this->getRepository(); |
||
| 3280 | |||
| 3281 | $contentService = $repository->getContentService(); |
||
| 3282 | |||
| 3283 | // RemoteId of the "Media" content of an eZ Publish demo installation |
||
| 3284 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3285 | $draft = $this->createContentDraftVersion1(); |
||
| 3286 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3287 | |||
| 3288 | // Create relation between new content object and "Media" page |
||
| 3289 | $contentService->addRelation( |
||
| 3290 | $draft->getVersionInfo(), |
||
| 3291 | $media |
||
| 3292 | ); |
||
| 3293 | |||
| 3294 | $content = $contentService->publishVersion($draft->versionInfo); |
||
| 3295 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
||
| 3296 | |||
| 3297 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
||
| 3298 | } |
||
| 3299 | |||
| 3300 | /** |
||
| 3301 | * Test for the createContentDraft() method. |
||
| 3302 | * |
||
| 3303 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3304 | * |
||
| 3305 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 3306 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelations |
||
| 3307 | */ |
||
| 3308 | public function testCreateContentDraftWithRelationsCreatesRelations($relations) |
||
| 3309 | { |
||
| 3310 | $this->assertEquals( |
||
| 3311 | 1, |
||
| 3312 | count($relations) |
||
| 3313 | ); |
||
| 3314 | |||
| 3315 | return $relations; |
||
| 3316 | } |
||
| 3317 | |||
| 3318 | /** |
||
| 3319 | * Test for the createContentDraft() method. |
||
| 3320 | * |
||
| 3321 | * @param \eZ\Publish\API\Repository\Values\Content\Relation[] $relations |
||
| 3322 | * |
||
| 3323 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithRelationsCreatesRelations |
||
| 3324 | */ |
||
| 3325 | public function testCreateContentDraftWithRelationsCreatesExpectedRelations($relations) |
||
| 3326 | { |
||
| 3327 | $this->assertExpectedRelations($relations); |
||
| 3328 | } |
||
| 3329 | |||
| 3330 | /** |
||
| 3331 | * Test for the addRelation() method. |
||
| 3332 | * |
||
| 3333 | * @see \eZ\Publish\API\Repository\ContentService::addRelation() |
||
| 3334 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 3335 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3336 | */ |
||
| 3337 | View Code Duplication | public function testAddRelationThrowsBadStateException() |
|
| 3338 | { |
||
| 3339 | $repository = $this->getRepository(); |
||
| 3340 | |||
| 3341 | $contentService = $repository->getContentService(); |
||
| 3342 | |||
| 3343 | /* BEGIN: Use Case */ |
||
| 3344 | // RemoteId of the "Media" page of an eZ Publish demo installation |
||
| 3345 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3346 | |||
| 3347 | $content = $this->createContentVersion1(); |
||
| 3348 | |||
| 3349 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3350 | |||
| 3351 | // This call will fail with a "BadStateException", because content is |
||
| 3352 | // published and not a draft. |
||
| 3353 | $contentService->addRelation( |
||
| 3354 | $content->getVersionInfo(), |
||
| 3355 | $media |
||
| 3356 | ); |
||
| 3357 | /* END: Use Case */ |
||
| 3358 | } |
||
| 3359 | |||
| 3360 | /** |
||
| 3361 | * Test for the loadRelations() method. |
||
| 3362 | * |
||
| 3363 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3364 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3365 | */ |
||
| 3366 | public function testLoadRelations() |
||
| 3367 | { |
||
| 3368 | $repository = $this->getRepository(); |
||
| 3369 | |||
| 3370 | $contentService = $repository->getContentService(); |
||
| 3371 | |||
| 3372 | /* BEGIN: Use Case */ |
||
| 3373 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3374 | // of a eZ Publish demo installation. |
||
| 3375 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3376 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3377 | |||
| 3378 | $draft = $this->createContentDraftVersion1(); |
||
| 3379 | |||
| 3380 | // Load other content objects |
||
| 3381 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3382 | $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
||
| 3383 | |||
| 3384 | // Create relation between new content object and "Media" page |
||
| 3385 | $contentService->addRelation( |
||
| 3386 | $draft->getVersionInfo(), |
||
| 3387 | $media |
||
| 3388 | ); |
||
| 3389 | |||
| 3390 | // Create another relation with the "Demo Design" page |
||
| 3391 | $contentService->addRelation( |
||
| 3392 | $draft->getVersionInfo(), |
||
| 3393 | $demoDesign |
||
| 3394 | ); |
||
| 3395 | |||
| 3396 | // Load all relations |
||
| 3397 | $relations = $contentService->loadRelations($draft->getVersionInfo()); |
||
| 3398 | /* END: Use Case */ |
||
| 3399 | |||
| 3400 | usort( |
||
| 3401 | $relations, |
||
| 3402 | function ($rel1, $rel2) { |
||
| 3403 | return strcasecmp( |
||
| 3404 | $rel2->getDestinationContentInfo()->remoteId, |
||
| 3405 | $rel1->getDestinationContentInfo()->remoteId |
||
| 3406 | ); |
||
| 3407 | } |
||
| 3408 | ); |
||
| 3409 | |||
| 3410 | $this->assertEquals( |
||
| 3411 | array( |
||
| 3412 | array( |
||
| 3413 | 'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3414 | 'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3415 | ), |
||
| 3416 | array( |
||
| 3417 | 'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3418 | 'destinationContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f', |
||
| 3419 | ), |
||
| 3420 | ), |
||
| 3421 | array( |
||
| 3422 | array( |
||
| 3423 | 'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
||
| 3424 | 'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
||
| 3425 | ), |
||
| 3426 | array( |
||
| 3427 | 'sourceContentInfo' => $relations[1]->sourceContentInfo->remoteId, |
||
| 3428 | 'destinationContentInfo' => $relations[1]->destinationContentInfo->remoteId, |
||
| 3429 | ), |
||
| 3430 | ) |
||
| 3431 | ); |
||
| 3432 | } |
||
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Test for the loadRelations() method. |
||
| 3436 | * |
||
| 3437 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3438 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3439 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3440 | */ |
||
| 3441 | public function testLoadRelationsSkipsArchivedContent() |
||
| 3442 | { |
||
| 3443 | $repository = $this->getRepository(); |
||
| 3444 | |||
| 3445 | $contentService = $repository->getContentService(); |
||
| 3446 | |||
| 3447 | /* BEGIN: Use Case */ |
||
| 3448 | $trashService = $repository->getTrashService(); |
||
| 3449 | $locationService = $repository->getLocationService(); |
||
| 3450 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3451 | // of a eZ Publish demo installation. |
||
| 3452 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3453 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3454 | |||
| 3455 | $draft = $this->createContentDraftVersion1(); |
||
| 3456 | |||
| 3457 | // Load other content objects |
||
| 3458 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3459 | $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
||
| 3460 | |||
| 3461 | // Create relation between new content object and "Media" page |
||
| 3462 | $contentService->addRelation( |
||
| 3463 | $draft->getVersionInfo(), |
||
| 3464 | $media |
||
| 3465 | ); |
||
| 3466 | |||
| 3467 | // Create another relation with the "Demo Design" page |
||
| 3468 | $contentService->addRelation( |
||
| 3469 | $draft->getVersionInfo(), |
||
| 3470 | $demoDesign |
||
| 3471 | ); |
||
| 3472 | |||
| 3473 | $demoDesignLocation = $locationService->loadLocation($demoDesign->mainLocationId); |
||
| 3474 | |||
| 3475 | // Trashing Content's last Location will change its status to archived, |
||
| 3476 | // in this case relation towards it will not be loaded. |
||
| 3477 | $trashService->trash($demoDesignLocation); |
||
| 3478 | |||
| 3479 | // Load all relations |
||
| 3480 | $relations = $contentService->loadRelations($draft->getVersionInfo()); |
||
| 3481 | /* END: Use Case */ |
||
| 3482 | |||
| 3483 | $this->assertCount(1, $relations); |
||
| 3484 | $this->assertEquals( |
||
| 3485 | array( |
||
| 3486 | array( |
||
| 3487 | 'sourceContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3488 | 'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3489 | ), |
||
| 3490 | ), |
||
| 3491 | array( |
||
| 3492 | array( |
||
| 3493 | 'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
||
| 3494 | 'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
||
| 3495 | ), |
||
| 3496 | ) |
||
| 3497 | ); |
||
| 3498 | } |
||
| 3499 | |||
| 3500 | /** |
||
| 3501 | * Test for the loadRelations() method. |
||
| 3502 | * |
||
| 3503 | * @see \eZ\Publish\API\Repository\ContentService::loadRelations() |
||
| 3504 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3505 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3506 | */ |
||
| 3507 | public function testLoadRelationsSkipsDraftContent() |
||
| 3508 | { |
||
| 3509 | $repository = $this->getRepository(); |
||
| 3510 | |||
| 3511 | $contentService = $repository->getContentService(); |
||
| 3512 | |||
| 3513 | /* BEGIN: Use Case */ |
||
| 3514 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3515 | // of a eZ Publish demo installation. |
||
| 3516 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3517 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3518 | |||
| 3519 | $draft = $this->createContentDraftVersion1(); |
||
| 3520 | |||
| 3521 | // Load other content objects |
||
| 3522 | $media = $contentService->loadContentByRemoteId($mediaRemoteId); |
||
| 3523 | $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
||
| 3524 | |||
| 3525 | // Create draft of "Media" page |
||
| 3526 | $mediaDraft = $contentService->createContentDraft($media->contentInfo); |
||
| 3527 | |||
| 3528 | // Create relation between "Media" page and new content object draft. |
||
| 3529 | // This relation will not be loaded before the draft is published. |
||
| 3530 | $contentService->addRelation( |
||
| 3531 | $mediaDraft->getVersionInfo(), |
||
| 3532 | $draft->getVersionInfo()->getContentInfo() |
||
| 3533 | ); |
||
| 3534 | |||
| 3535 | // Create another relation with the "Demo Design" page |
||
| 3536 | $contentService->addRelation( |
||
| 3537 | $mediaDraft->getVersionInfo(), |
||
| 3538 | $demoDesign |
||
| 3539 | ); |
||
| 3540 | |||
| 3541 | // Load all relations |
||
| 3542 | $relations = $contentService->loadRelations($mediaDraft->getVersionInfo()); |
||
| 3543 | /* END: Use Case */ |
||
| 3544 | |||
| 3545 | $this->assertCount(1, $relations); |
||
| 3546 | $this->assertEquals( |
||
| 3547 | array( |
||
| 3548 | array( |
||
| 3549 | 'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3550 | 'destinationContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f', |
||
| 3551 | ), |
||
| 3552 | ), |
||
| 3553 | array( |
||
| 3554 | array( |
||
| 3555 | 'sourceContentInfo' => $relations[0]->sourceContentInfo->remoteId, |
||
| 3556 | 'destinationContentInfo' => $relations[0]->destinationContentInfo->remoteId, |
||
| 3557 | ), |
||
| 3558 | ) |
||
| 3559 | ); |
||
| 3560 | } |
||
| 3561 | |||
| 3562 | /** |
||
| 3563 | * Test for the loadReverseRelations() method. |
||
| 3564 | * |
||
| 3565 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3566 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3567 | */ |
||
| 3568 | public function testLoadReverseRelations() |
||
| 3569 | { |
||
| 3570 | $repository = $this->getRepository(); |
||
| 3571 | |||
| 3572 | $contentService = $repository->getContentService(); |
||
| 3573 | |||
| 3574 | /* BEGIN: Use Case */ |
||
| 3575 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3576 | // of a eZ Publish demo installation. |
||
| 3577 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3578 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3579 | |||
| 3580 | $versionInfo = $this->createContentVersion1()->getVersionInfo(); |
||
| 3581 | $contentInfo = $versionInfo->getContentInfo(); |
||
| 3582 | |||
| 3583 | // Create some drafts |
||
| 3584 | $mediaDraft = $contentService->createContentDraft( |
||
| 3585 | $contentService->loadContentInfoByRemoteId($mediaRemoteId) |
||
| 3586 | ); |
||
| 3587 | $demoDesignDraft = $contentService->createContentDraft( |
||
| 3588 | $contentService->loadContentInfoByRemoteId($demoDesignRemoteId) |
||
| 3589 | ); |
||
| 3590 | |||
| 3591 | // Create relation between new content object and "Media" page |
||
| 3592 | $relation1 = $contentService->addRelation( |
||
| 3593 | $mediaDraft->getVersionInfo(), |
||
| 3594 | $contentInfo |
||
| 3595 | ); |
||
| 3596 | |||
| 3597 | // Create another relation with the "Demo Design" page |
||
| 3598 | $relation2 = $contentService->addRelation( |
||
| 3599 | $demoDesignDraft->getVersionInfo(), |
||
| 3600 | $contentInfo |
||
| 3601 | ); |
||
| 3602 | |||
| 3603 | // Publish drafts, so relations become active |
||
| 3604 | $contentService->publishVersion($mediaDraft->getVersionInfo()); |
||
| 3605 | $contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
||
| 3606 | |||
| 3607 | // Load all relations |
||
| 3608 | $relations = $contentService->loadRelations($versionInfo); |
||
| 3609 | $reverseRelations = $contentService->loadReverseRelations($contentInfo); |
||
| 3610 | /* END: Use Case */ |
||
| 3611 | |||
| 3612 | $this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id); |
||
| 3613 | $this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id); |
||
| 3614 | |||
| 3615 | $this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id); |
||
| 3616 | $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
||
| 3617 | |||
| 3618 | $this->assertEquals(0, count($relations)); |
||
| 3619 | $this->assertEquals(2, count($reverseRelations)); |
||
| 3620 | |||
| 3621 | usort( |
||
| 3622 | $reverseRelations, |
||
| 3623 | function ($rel1, $rel2) { |
||
| 3624 | return strcasecmp( |
||
| 3625 | $rel2->getSourceContentInfo()->remoteId, |
||
| 3626 | $rel1->getSourceContentInfo()->remoteId |
||
| 3627 | ); |
||
| 3628 | } |
||
| 3629 | ); |
||
| 3630 | |||
| 3631 | $this->assertEquals( |
||
| 3632 | array( |
||
| 3633 | array( |
||
| 3634 | 'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3635 | 'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3636 | ), |
||
| 3637 | array( |
||
| 3638 | 'sourceContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f', |
||
| 3639 | 'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3640 | ), |
||
| 3641 | ), |
||
| 3642 | array( |
||
| 3643 | array( |
||
| 3644 | 'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
||
| 3645 | 'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
||
| 3646 | ), |
||
| 3647 | array( |
||
| 3648 | 'sourceContentInfo' => $reverseRelations[1]->sourceContentInfo->remoteId, |
||
| 3649 | 'destinationContentInfo' => $reverseRelations[1]->destinationContentInfo->remoteId, |
||
| 3650 | ), |
||
| 3651 | ) |
||
| 3652 | ); |
||
| 3653 | } |
||
| 3654 | |||
| 3655 | /** |
||
| 3656 | * Test for the loadReverseRelations() method. |
||
| 3657 | * |
||
| 3658 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3659 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3660 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
||
| 3661 | */ |
||
| 3662 | public function testLoadReverseRelationsSkipsArchivedContent() |
||
| 3663 | { |
||
| 3664 | $repository = $this->getRepository(); |
||
| 3665 | |||
| 3666 | $contentService = $repository->getContentService(); |
||
| 3667 | |||
| 3668 | /* BEGIN: Use Case */ |
||
| 3669 | $trashService = $repository->getTrashService(); |
||
| 3670 | $locationService = $repository->getLocationService(); |
||
| 3671 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3672 | // of a eZ Publish demo installation. |
||
| 3673 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3674 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3675 | |||
| 3676 | $versionInfo = $this->createContentVersion1()->getVersionInfo(); |
||
| 3677 | $contentInfo = $versionInfo->getContentInfo(); |
||
| 3678 | |||
| 3679 | // Create some drafts |
||
| 3680 | $mediaDraft = $contentService->createContentDraft( |
||
| 3681 | $contentService->loadContentInfoByRemoteId($mediaRemoteId) |
||
| 3682 | ); |
||
| 3683 | $demoDesignDraft = $contentService->createContentDraft( |
||
| 3684 | $contentService->loadContentInfoByRemoteId($demoDesignRemoteId) |
||
| 3685 | ); |
||
| 3686 | |||
| 3687 | // Create relation between new content object and "Media" page |
||
| 3688 | $relation1 = $contentService->addRelation( |
||
| 3689 | $mediaDraft->getVersionInfo(), |
||
| 3690 | $contentInfo |
||
| 3691 | ); |
||
| 3692 | |||
| 3693 | // Create another relation with the "Demo Design" page |
||
| 3694 | $relation2 = $contentService->addRelation( |
||
| 3695 | $demoDesignDraft->getVersionInfo(), |
||
| 3696 | $contentInfo |
||
| 3697 | ); |
||
| 3698 | |||
| 3699 | // Publish drafts, so relations become active |
||
| 3700 | $contentService->publishVersion($mediaDraft->getVersionInfo()); |
||
| 3701 | $contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
||
| 3702 | |||
| 3703 | $demoDesignLocation = $locationService->loadLocation($demoDesignDraft->contentInfo->mainLocationId); |
||
| 3704 | |||
| 3705 | // Trashing Content's last Location will change its status to archived, |
||
| 3706 | // in this case relation from it will not be loaded. |
||
| 3707 | $trashService->trash($demoDesignLocation); |
||
| 3708 | |||
| 3709 | // Load all relations |
||
| 3710 | $relations = $contentService->loadRelations($versionInfo); |
||
| 3711 | $reverseRelations = $contentService->loadReverseRelations($contentInfo); |
||
| 3712 | /* END: Use Case */ |
||
| 3713 | |||
| 3714 | $this->assertEquals($contentInfo->id, $relation1->getDestinationContentInfo()->id); |
||
| 3715 | $this->assertEquals($mediaDraft->id, $relation1->getSourceContentInfo()->id); |
||
| 3716 | |||
| 3717 | $this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id); |
||
| 3718 | $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
||
| 3719 | |||
| 3720 | $this->assertEquals(0, count($relations)); |
||
| 3721 | $this->assertEquals(1, count($reverseRelations)); |
||
| 3722 | |||
| 3723 | $this->assertEquals( |
||
| 3724 | array( |
||
| 3725 | array( |
||
| 3726 | 'sourceContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3727 | 'destinationContentInfo' => 'abcdef0123456789abcdef0123456789', |
||
| 3728 | ), |
||
| 3729 | ), |
||
| 3730 | array( |
||
| 3731 | array( |
||
| 3732 | 'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
||
| 3733 | 'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
||
| 3734 | ), |
||
| 3735 | ) |
||
| 3736 | ); |
||
| 3737 | } |
||
| 3738 | |||
| 3739 | /** |
||
| 3740 | * Test for the loadReverseRelations() method. |
||
| 3741 | * |
||
| 3742 | * @see \eZ\Publish\API\Repository\ContentService::loadReverseRelations() |
||
| 3743 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation |
||
| 3744 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadReverseRelations |
||
| 3745 | */ |
||
| 3746 | public function testLoadReverseRelationsSkipsDraftContent() |
||
| 3747 | { |
||
| 3748 | $repository = $this->getRepository(); |
||
| 3749 | |||
| 3750 | $contentService = $repository->getContentService(); |
||
| 3751 | |||
| 3752 | /* BEGIN: Use Case */ |
||
| 3753 | // Remote ids of the "Media" and the "eZ Publish Demo Design ..." page |
||
| 3754 | // of a eZ Publish demo installation. |
||
| 3755 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3756 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3757 | |||
| 3758 | // Load "Media" page Content |
||
| 3759 | $media = $contentService->loadContentByRemoteId($mediaRemoteId); |
||
| 3760 | |||
| 3761 | // Create some drafts |
||
| 3762 | $newDraftVersionInfo = $this->createContentDraftVersion1()->getVersionInfo(); |
||
| 3763 | $demoDesignDraft = $contentService->createContentDraft( |
||
| 3764 | $contentService->loadContentInfoByRemoteId($demoDesignRemoteId) |
||
| 3765 | ); |
||
| 3766 | |||
| 3767 | // Create relation between "Media" page and new content object |
||
| 3768 | $relation1 = $contentService->addRelation( |
||
| 3769 | $newDraftVersionInfo, |
||
| 3770 | $media->contentInfo |
||
| 3771 | ); |
||
| 3772 | |||
| 3773 | // Create another relation with the "Demo Design" page |
||
| 3774 | $relation2 = $contentService->addRelation( |
||
| 3775 | $demoDesignDraft->getVersionInfo(), |
||
| 3776 | $media->contentInfo |
||
| 3777 | ); |
||
| 3778 | |||
| 3779 | // Publish drafts, so relations become active |
||
| 3780 | $contentService->publishVersion($demoDesignDraft->getVersionInfo()); |
||
| 3781 | // We will not publish new Content draft, therefore relation from it |
||
| 3782 | // will not be loaded as reverse relation for "Media" page |
||
| 3783 | //$contentService->publishVersion( $newDraftVersionInfo ); |
||
| 3784 | |||
| 3785 | // Load all relations |
||
| 3786 | $relations = $contentService->loadRelations($media->versionInfo); |
||
| 3787 | $reverseRelations = $contentService->loadReverseRelations($media->contentInfo); |
||
| 3788 | /* END: Use Case */ |
||
| 3789 | |||
| 3790 | $this->assertEquals($media->contentInfo->id, $relation1->getDestinationContentInfo()->id); |
||
| 3791 | $this->assertEquals($newDraftVersionInfo->contentInfo->id, $relation1->getSourceContentInfo()->id); |
||
| 3792 | |||
| 3793 | $this->assertEquals($media->contentInfo->id, $relation2->getDestinationContentInfo()->id); |
||
| 3794 | $this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id); |
||
| 3795 | |||
| 3796 | $this->assertEquals(0, count($relations)); |
||
| 3797 | $this->assertEquals(1, count($reverseRelations)); |
||
| 3798 | |||
| 3799 | $this->assertEquals( |
||
| 3800 | array( |
||
| 3801 | array( |
||
| 3802 | 'sourceContentInfo' => '8b8b22fe3c6061ed500fbd2b377b885f', |
||
| 3803 | 'destinationContentInfo' => 'a6e35cbcb7cd6ae4b691f3eee30cd262', |
||
| 3804 | ), |
||
| 3805 | ), |
||
| 3806 | array( |
||
| 3807 | array( |
||
| 3808 | 'sourceContentInfo' => $reverseRelations[0]->sourceContentInfo->remoteId, |
||
| 3809 | 'destinationContentInfo' => $reverseRelations[0]->destinationContentInfo->remoteId, |
||
| 3810 | ), |
||
| 3811 | ) |
||
| 3812 | ); |
||
| 3813 | } |
||
| 3814 | |||
| 3815 | /** |
||
| 3816 | * Test for the deleteRelation() method. |
||
| 3817 | * |
||
| 3818 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3819 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations |
||
| 3820 | */ |
||
| 3821 | public function testDeleteRelation() |
||
| 3822 | { |
||
| 3823 | $repository = $this->getRepository(); |
||
| 3824 | |||
| 3825 | $contentService = $repository->getContentService(); |
||
| 3826 | |||
| 3827 | /* BEGIN: Use Case */ |
||
| 3828 | // Remote ids of the "Media" and the "Demo Design" page of a eZ Publish |
||
| 3829 | // demo installation. |
||
| 3830 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3831 | $demoDesignRemoteId = '8b8b22fe3c6061ed500fbd2b377b885f'; |
||
| 3832 | |||
| 3833 | $draft = $this->createContentDraftVersion1(); |
||
| 3834 | |||
| 3835 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3836 | $demoDesign = $contentService->loadContentInfoByRemoteId($demoDesignRemoteId); |
||
| 3837 | |||
| 3838 | // Establish some relations |
||
| 3839 | $contentService->addRelation($draft->getVersionInfo(), $media); |
||
| 3840 | $contentService->addRelation($draft->getVersionInfo(), $demoDesign); |
||
| 3841 | |||
| 3842 | // Delete one of the currently created relations |
||
| 3843 | $contentService->deleteRelation($draft->getVersionInfo(), $media); |
||
| 3844 | |||
| 3845 | // The relations array now contains only one element |
||
| 3846 | $relations = $contentService->loadRelations($draft->getVersionInfo()); |
||
| 3847 | /* END: Use Case */ |
||
| 3848 | |||
| 3849 | $this->assertEquals(1, count($relations)); |
||
| 3850 | } |
||
| 3851 | |||
| 3852 | /** |
||
| 3853 | * Test for the deleteRelation() method. |
||
| 3854 | * |
||
| 3855 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3856 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 3857 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
||
| 3858 | */ |
||
| 3859 | View Code Duplication | public function testDeleteRelationThrowsBadStateException() |
|
| 3860 | { |
||
| 3861 | $repository = $this->getRepository(); |
||
| 3862 | |||
| 3863 | $contentService = $repository->getContentService(); |
||
| 3864 | |||
| 3865 | /* BEGIN: Use Case */ |
||
| 3866 | // RemoteId of the "Media" page of an eZ Publish demo installation |
||
| 3867 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3868 | |||
| 3869 | $content = $this->createContentVersion1(); |
||
| 3870 | |||
| 3871 | // Load the destination object |
||
| 3872 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3873 | |||
| 3874 | // Create a new draft |
||
| 3875 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
||
| 3876 | |||
| 3877 | // Add a relation |
||
| 3878 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
||
| 3879 | |||
| 3880 | // Publish new version |
||
| 3881 | $contentVersion2 = $contentService->publishVersion( |
||
| 3882 | $draftVersion2->getVersionInfo() |
||
| 3883 | ); |
||
| 3884 | |||
| 3885 | // This call will fail with a "BadStateException", because content is |
||
| 3886 | // published and not a draft. |
||
| 3887 | $contentService->deleteRelation( |
||
| 3888 | $contentVersion2->getVersionInfo(), |
||
| 3889 | $media |
||
| 3890 | ); |
||
| 3891 | /* END: Use Case */ |
||
| 3892 | } |
||
| 3893 | |||
| 3894 | /** |
||
| 3895 | * Test for the deleteRelation() method. |
||
| 3896 | * |
||
| 3897 | * @see \eZ\Publish\API\Repository\ContentService::deleteRelation() |
||
| 3898 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 3899 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
||
| 3900 | */ |
||
| 3901 | View Code Duplication | public function testDeleteRelationThrowsInvalidArgumentException() |
|
| 3902 | { |
||
| 3903 | $repository = $this->getRepository(); |
||
| 3904 | |||
| 3905 | $contentService = $repository->getContentService(); |
||
| 3906 | |||
| 3907 | /* BEGIN: Use Case */ |
||
| 3908 | // RemoteId of the "Media" page of an eZ Publish demo installation |
||
| 3909 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
||
| 3910 | |||
| 3911 | $draft = $this->createContentDraftVersion1(); |
||
| 3912 | |||
| 3913 | // Load the destination object |
||
| 3914 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
||
| 3915 | |||
| 3916 | // This call will fail with a "InvalidArgumentException", because no |
||
| 3917 | // relation exists between $draft and $media. |
||
| 3918 | $contentService->deleteRelation( |
||
| 3919 | $draft->getVersionInfo(), |
||
| 3920 | $media |
||
| 3921 | ); |
||
| 3922 | /* END: Use Case */ |
||
| 3923 | } |
||
| 3924 | |||
| 3925 | /** |
||
| 3926 | * Test for the createContent() method. |
||
| 3927 | * |
||
| 3928 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 3929 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 3930 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 3931 | */ |
||
| 3932 | public function testCreateContentInTransactionWithRollback() |
||
| 3933 | { |
||
| 3934 | if ($this->isVersion4()) { |
||
| 3935 | $this->markTestSkipped('This test requires eZ Publish 5'); |
||
| 3936 | } |
||
| 3937 | |||
| 3938 | $repository = $this->getRepository(); |
||
| 3939 | |||
| 3940 | /* BEGIN: Use Case */ |
||
| 3941 | $contentTypeService = $repository->getContentTypeService(); |
||
| 3942 | $contentService = $repository->getContentService(); |
||
| 3943 | |||
| 3944 | // Start a transaction |
||
| 3945 | $repository->beginTransaction(); |
||
| 3946 | |||
| 3947 | try { |
||
| 3948 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
||
| 3949 | |||
| 3950 | // Get a content create struct and set mandatory properties |
||
| 3951 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
||
| 3952 | $contentCreate->setField('name', 'Sindelfingen forum'); |
||
| 3953 | |||
| 3954 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 3955 | $contentCreate->alwaysAvailable = true; |
||
| 3956 | |||
| 3957 | // Create a new content object |
||
| 3958 | $contentId = $contentService->createContent($contentCreate)->id; |
||
| 3959 | } catch (Exception $e) { |
||
| 3960 | // Cleanup hanging transaction on error |
||
| 3961 | $repository->rollback(); |
||
| 3962 | throw $e; |
||
| 3963 | } |
||
| 3964 | |||
| 3965 | // Rollback all changes |
||
| 3966 | $repository->rollback(); |
||
| 3967 | |||
| 3968 | try { |
||
| 3969 | // This call will fail with a "NotFoundException" |
||
| 3970 | $contentService->loadContent($contentId); |
||
| 3971 | } catch (NotFoundException $e) { |
||
| 3972 | // This is expected |
||
| 3973 | return; |
||
| 3974 | } |
||
| 3975 | /* END: Use Case */ |
||
| 3976 | |||
| 3977 | $this->fail('Content object still exists after rollback.'); |
||
| 3978 | } |
||
| 3979 | |||
| 3980 | /** |
||
| 3981 | * Test for the createContent() method. |
||
| 3982 | * |
||
| 3983 | * @see \eZ\Publish\API\Repository\ContentService::createContent() |
||
| 3984 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 3985 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 3986 | */ |
||
| 3987 | public function testCreateContentInTransactionWithCommit() |
||
| 3988 | { |
||
| 3989 | if ($this->isVersion4()) { |
||
| 3990 | $this->markTestSkipped('This test requires eZ Publish 5'); |
||
| 3991 | } |
||
| 3992 | |||
| 3993 | $repository = $this->getRepository(); |
||
| 3994 | |||
| 3995 | /* BEGIN: Use Case */ |
||
| 3996 | $contentTypeService = $repository->getContentTypeService(); |
||
| 3997 | $contentService = $repository->getContentService(); |
||
| 3998 | |||
| 3999 | // Start a transaction |
||
| 4000 | $repository->beginTransaction(); |
||
| 4001 | |||
| 4002 | try { |
||
| 4003 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
||
| 4004 | |||
| 4005 | // Get a content create struct and set mandatory properties |
||
| 4006 | $contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
||
| 4007 | $contentCreate->setField('name', 'Sindelfingen forum'); |
||
| 4008 | |||
| 4009 | $contentCreate->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 4010 | $contentCreate->alwaysAvailable = true; |
||
| 4011 | |||
| 4012 | // Create a new content object |
||
| 4013 | $contentId = $contentService->createContent($contentCreate)->id; |
||
| 4014 | |||
| 4015 | // Commit changes |
||
| 4016 | $repository->commit(); |
||
| 4017 | } catch (Exception $e) { |
||
| 4018 | // Cleanup hanging transaction on error |
||
| 4019 | $repository->rollback(); |
||
| 4020 | throw $e; |
||
| 4021 | } |
||
| 4022 | |||
| 4023 | // Load the new content object |
||
| 4024 | $content = $contentService->loadContent($contentId); |
||
| 4025 | /* END: Use Case */ |
||
| 4026 | |||
| 4027 | $this->assertEquals($contentId, $content->id); |
||
| 4028 | } |
||
| 4029 | |||
| 4030 | /** |
||
| 4031 | * Test for the createContent() method. |
||
| 4032 | * |
||
| 4033 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 4034 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 4035 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
||
| 4036 | */ |
||
| 4037 | public function testCreateContentWithLocationCreateParameterInTransactionWithRollback() |
||
| 4038 | { |
||
| 4039 | $repository = $this->getRepository(); |
||
| 4040 | |||
| 4041 | $contentService = $repository->getContentService(); |
||
| 4042 | |||
| 4043 | /* BEGIN: Use Case */ |
||
| 4044 | // Start a transaction |
||
| 4045 | $repository->beginTransaction(); |
||
| 4046 | |||
| 4047 | try { |
||
| 4048 | $draft = $this->createContentDraftVersion1(); |
||
| 4049 | } catch (Exception $e) { |
||
| 4050 | // Cleanup hanging transaction on error |
||
| 4051 | $repository->rollback(); |
||
| 4052 | throw $e; |
||
| 4053 | } |
||
| 4054 | |||
| 4055 | $contentId = $draft->id; |
||
| 4056 | |||
| 4057 | // Roleback the transaction |
||
| 4058 | $repository->rollback(); |
||
| 4059 | |||
| 4060 | try { |
||
| 4061 | // This call will fail with a "NotFoundException" |
||
| 4062 | $contentService->loadContent($contentId); |
||
| 4063 | } catch (NotFoundException $e) { |
||
| 4064 | return; |
||
| 4065 | } |
||
| 4066 | /* END: Use Case */ |
||
| 4067 | |||
| 4068 | $this->fail('Can still load content object after rollback.'); |
||
| 4069 | } |
||
| 4070 | |||
| 4071 | /** |
||
| 4072 | * Test for the createContent() method. |
||
| 4073 | * |
||
| 4074 | * @see \eZ\Publish\API\Repository\ContentService::createContent($contentCreateStruct, $locationCreateStructs) |
||
| 4075 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately |
||
| 4076 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException |
||
| 4077 | */ |
||
| 4078 | View Code Duplication | public function testCreateContentWithLocationCreateParameterInTransactionWithCommit() |
|
| 4079 | { |
||
| 4080 | $repository = $this->getRepository(); |
||
| 4081 | |||
| 4082 | $contentService = $repository->getContentService(); |
||
| 4083 | |||
| 4084 | /* BEGIN: Use Case */ |
||
| 4085 | // Start a transaction |
||
| 4086 | $repository->beginTransaction(); |
||
| 4087 | |||
| 4088 | try { |
||
| 4089 | $draft = $this->createContentDraftVersion1(); |
||
| 4090 | |||
| 4091 | $contentId = $draft->id; |
||
| 4092 | |||
| 4093 | // Roleback the transaction |
||
| 4094 | $repository->commit(); |
||
| 4095 | } catch (Exception $e) { |
||
| 4096 | // Cleanup hanging transaction on error |
||
| 4097 | $repository->rollback(); |
||
| 4098 | throw $e; |
||
| 4099 | } |
||
| 4100 | |||
| 4101 | // Load the new content object |
||
| 4102 | $content = $contentService->loadContent($contentId); |
||
| 4103 | /* END: Use Case */ |
||
| 4104 | |||
| 4105 | $this->assertEquals($contentId, $content->id); |
||
| 4106 | } |
||
| 4107 | |||
| 4108 | /** |
||
| 4109 | * Test for the createContentDraft() method. |
||
| 4110 | * |
||
| 4111 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 4112 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 4113 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4114 | */ |
||
| 4115 | public function testCreateContentDraftInTransactionWithRollback() |
||
| 4116 | { |
||
| 4117 | $repository = $this->getRepository(); |
||
| 4118 | |||
| 4119 | $contentId = $this->generateId('object', 12); |
||
| 4120 | /* BEGIN: Use Case */ |
||
| 4121 | // $contentId is the ID of the "Administrator users" user group |
||
| 4122 | |||
| 4123 | // Get the content service |
||
| 4124 | $contentService = $repository->getContentService(); |
||
| 4125 | |||
| 4126 | // Load the user group content object |
||
| 4127 | $content = $contentService->loadContent($contentId); |
||
| 4128 | |||
| 4129 | // Start a new transaction |
||
| 4130 | $repository->beginTransaction(); |
||
| 4131 | |||
| 4132 | try { |
||
| 4133 | // Create a new draft |
||
| 4134 | $drafted = $contentService->createContentDraft($content->contentInfo); |
||
| 4135 | |||
| 4136 | // Store version number for later reuse |
||
| 4137 | $versionNo = $drafted->versionInfo->versionNo; |
||
| 4138 | } catch (Exception $e) { |
||
| 4139 | // Cleanup hanging transaction on error |
||
| 4140 | $repository->rollback(); |
||
| 4141 | throw $e; |
||
| 4142 | } |
||
| 4143 | |||
| 4144 | // Rollback |
||
| 4145 | $repository->rollback(); |
||
| 4146 | |||
| 4147 | try { |
||
| 4148 | // This call will fail with a "NotFoundException" |
||
| 4149 | $contentService->loadContent($contentId, null, $versionNo); |
||
| 4150 | } catch (NotFoundException $e) { |
||
| 4151 | return; |
||
| 4152 | } |
||
| 4153 | /* END: Use Case */ |
||
| 4154 | |||
| 4155 | $this->fail('Can still load content draft after rollback'); |
||
| 4156 | } |
||
| 4157 | |||
| 4158 | /** |
||
| 4159 | * Test for the createContentDraft() method. |
||
| 4160 | * |
||
| 4161 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
||
| 4162 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
||
| 4163 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4164 | */ |
||
| 4165 | View Code Duplication | public function testCreateContentDraftInTransactionWithCommit() |
|
| 4166 | { |
||
| 4167 | $repository = $this->getRepository(); |
||
| 4168 | |||
| 4169 | $contentId = $this->generateId('object', 12); |
||
| 4170 | /* BEGIN: Use Case */ |
||
| 4171 | // $contentId is the ID of the "Administrator users" user group |
||
| 4172 | |||
| 4173 | // Get the content service |
||
| 4174 | $contentService = $repository->getContentService(); |
||
| 4175 | |||
| 4176 | // Load the user group content object |
||
| 4177 | $content = $contentService->loadContent($contentId); |
||
| 4178 | |||
| 4179 | // Start a new transaction |
||
| 4180 | $repository->beginTransaction(); |
||
| 4181 | |||
| 4182 | try { |
||
| 4183 | // Create a new draft |
||
| 4184 | $drafted = $contentService->createContentDraft($content->contentInfo); |
||
| 4185 | |||
| 4186 | // Store version number for later reuse |
||
| 4187 | $versionNo = $drafted->versionInfo->versionNo; |
||
| 4188 | |||
| 4189 | // Commit all changes |
||
| 4190 | $repository->commit(); |
||
| 4191 | } catch (Exception $e) { |
||
| 4192 | // Cleanup hanging transaction on error |
||
| 4193 | $repository->rollback(); |
||
| 4194 | throw $e; |
||
| 4195 | } |
||
| 4196 | |||
| 4197 | $content = $contentService->loadContent($contentId, null, $versionNo); |
||
| 4198 | /* END: Use Case */ |
||
| 4199 | |||
| 4200 | $this->assertEquals( |
||
| 4201 | $versionNo, |
||
| 4202 | $content->getVersionInfo()->versionNo |
||
| 4203 | ); |
||
| 4204 | } |
||
| 4205 | |||
| 4206 | /** |
||
| 4207 | * Test for the publishVersion() method. |
||
| 4208 | * |
||
| 4209 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 4210 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 4211 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4212 | */ |
||
| 4213 | View Code Duplication | public function testPublishVersionInTransactionWithRollback() |
|
| 4214 | { |
||
| 4215 | $repository = $this->getRepository(); |
||
| 4216 | |||
| 4217 | $contentId = $this->generateId('object', 12); |
||
| 4218 | /* BEGIN: Use Case */ |
||
| 4219 | // $contentId is the ID of the "Administrator users" user group |
||
| 4220 | |||
| 4221 | // Get the content service |
||
| 4222 | $contentService = $repository->getContentService(); |
||
| 4223 | |||
| 4224 | // Load the user group content object |
||
| 4225 | $content = $contentService->loadContent($contentId); |
||
| 4226 | |||
| 4227 | // Start a new transaction |
||
| 4228 | $repository->beginTransaction(); |
||
| 4229 | |||
| 4230 | try { |
||
| 4231 | $draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
||
| 4232 | |||
| 4233 | // Publish a new version |
||
| 4234 | $content = $contentService->publishVersion($draftVersion); |
||
| 4235 | |||
| 4236 | // Store version number for later reuse |
||
| 4237 | $versionNo = $content->versionInfo->versionNo; |
||
| 4238 | } catch (Exception $e) { |
||
| 4239 | // Cleanup hanging transaction on error |
||
| 4240 | $repository->rollback(); |
||
| 4241 | throw $e; |
||
| 4242 | } |
||
| 4243 | |||
| 4244 | // Rollback |
||
| 4245 | $repository->rollback(); |
||
| 4246 | |||
| 4247 | try { |
||
| 4248 | // This call will fail with a "NotFoundException" |
||
| 4249 | $contentService->loadContent($contentId, null, $versionNo); |
||
| 4250 | } catch (NotFoundException $e) { |
||
| 4251 | return; |
||
| 4252 | } |
||
| 4253 | /* END: Use Case */ |
||
| 4254 | |||
| 4255 | $this->fail('Can still load content draft after rollback'); |
||
| 4256 | } |
||
| 4257 | |||
| 4258 | /** |
||
| 4259 | * Test for the publishVersion() method. |
||
| 4260 | * |
||
| 4261 | * @see \eZ\Publish\API\Repository\ContentService::publishVersion() |
||
| 4262 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
||
| 4263 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
||
| 4264 | */ |
||
| 4265 | View Code Duplication | public function testPublishVersionInTransactionWithCommit() |
|
| 4266 | { |
||
| 4267 | $repository = $this->getRepository(); |
||
| 4268 | |||
| 4269 | /* BEGIN: Use Case */ |
||
| 4270 | // ID of the "Administrator users" user group |
||
| 4271 | $contentId = 12; |
||
| 4272 | |||
| 4273 | // Get the content service |
||
| 4274 | $contentService = $repository->getContentService(); |
||
| 4275 | |||
| 4276 | // Load the user group content object |
||
| 4277 | $template = $contentService->loadContent($contentId); |
||
| 4278 | |||
| 4279 | // Start a new transaction |
||
| 4280 | $repository->beginTransaction(); |
||
| 4281 | |||
| 4282 | try { |
||
| 4283 | // Publish a new version |
||
| 4284 | $content = $contentService->publishVersion( |
||
| 4285 | $contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
||
| 4286 | ); |
||
| 4287 | |||
| 4288 | // Store version number for later reuse |
||
| 4289 | $versionNo = $content->versionInfo->versionNo; |
||
| 4290 | |||
| 4291 | // Commit all changes |
||
| 4292 | $repository->commit(); |
||
| 4293 | } catch (Exception $e) { |
||
| 4294 | // Cleanup hanging transaction on error |
||
| 4295 | $repository->rollback(); |
||
| 4296 | throw $e; |
||
| 4297 | } |
||
| 4298 | |||
| 4299 | // Load current version info |
||
| 4300 | $versionInfo = $contentService->loadVersionInfo($content->contentInfo); |
||
| 4301 | /* END: Use Case */ |
||
| 4302 | |||
| 4303 | $this->assertEquals($versionNo, $versionInfo->versionNo); |
||
| 4304 | } |
||
| 4305 | |||
| 4306 | /** |
||
| 4307 | * Test for the updateContent() method. |
||
| 4308 | * |
||
| 4309 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 4310 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 4311 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4312 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4313 | */ |
||
| 4314 | View Code Duplication | public function testUpdateContentInTransactionWithRollback() |
|
| 4315 | { |
||
| 4316 | $repository = $this->getRepository(); |
||
| 4317 | |||
| 4318 | $contentId = $this->generateId('object', 12); |
||
| 4319 | /* BEGIN: Use Case */ |
||
| 4320 | // $contentId is the ID of the "Administrator users" user group |
||
| 4321 | |||
| 4322 | // Load content service |
||
| 4323 | $contentService = $repository->getContentService(); |
||
| 4324 | |||
| 4325 | // Create a new user group draft |
||
| 4326 | $draft = $contentService->createContentDraft( |
||
| 4327 | $contentService->loadContentInfo($contentId) |
||
| 4328 | ); |
||
| 4329 | |||
| 4330 | // Get an update struct and change the group name |
||
| 4331 | $contentUpdate = $contentService->newContentUpdateStruct(); |
||
| 4332 | $contentUpdate->setField('name', 'Administrators', 'eng-US'); |
||
| 4333 | |||
| 4334 | // Start a transaction |
||
| 4335 | $repository->beginTransaction(); |
||
| 4336 | |||
| 4337 | try { |
||
| 4338 | // Update the group name |
||
| 4339 | $draft = $contentService->updateContent( |
||
| 4340 | $draft->getVersionInfo(), |
||
| 4341 | $contentUpdate |
||
| 4342 | ); |
||
| 4343 | |||
| 4344 | // Publish updated version |
||
| 4345 | $contentService->publishVersion($draft->getVersionInfo()); |
||
| 4346 | } catch (Exception $e) { |
||
| 4347 | // Cleanup hanging transaction on error |
||
| 4348 | $repository->rollback(); |
||
| 4349 | throw $e; |
||
| 4350 | } |
||
| 4351 | |||
| 4352 | // Rollback all changes. |
||
| 4353 | $repository->rollback(); |
||
| 4354 | |||
| 4355 | // Name will still be "Administrator users" |
||
| 4356 | $name = $contentService->loadContent($contentId)->getFieldValue('name'); |
||
| 4357 | /* END: Use Case */ |
||
| 4358 | |||
| 4359 | $this->assertEquals('Administrator users', $name); |
||
| 4360 | } |
||
| 4361 | |||
| 4362 | /** |
||
| 4363 | * Test for the updateContent() method. |
||
| 4364 | * |
||
| 4365 | * @see \eZ\Publish\API\Repository\ContentService::updateContent() |
||
| 4366 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContent |
||
| 4367 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
||
| 4368 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4369 | */ |
||
| 4370 | View Code Duplication | public function testUpdateContentInTransactionWithCommit() |
|
| 4371 | { |
||
| 4372 | $repository = $this->getRepository(); |
||
| 4373 | |||
| 4374 | $contentId = $this->generateId('object', 12); |
||
| 4375 | /* BEGIN: Use Case */ |
||
| 4376 | // $contentId is the ID of the "Administrator users" user group |
||
| 4377 | |||
| 4378 | // Load content service |
||
| 4379 | $contentService = $repository->getContentService(); |
||
| 4380 | |||
| 4381 | // Create a new user group draft |
||
| 4382 | $draft = $contentService->createContentDraft( |
||
| 4383 | $contentService->loadContentInfo($contentId) |
||
| 4384 | ); |
||
| 4385 | |||
| 4386 | // Get an update struct and change the group name |
||
| 4387 | $contentUpdate = $contentService->newContentUpdateStruct(); |
||
| 4388 | $contentUpdate->setField('name', 'Administrators', 'eng-US'); |
||
| 4389 | |||
| 4390 | // Start a transaction |
||
| 4391 | $repository->beginTransaction(); |
||
| 4392 | |||
| 4393 | try { |
||
| 4394 | // Update the group name |
||
| 4395 | $draft = $contentService->updateContent( |
||
| 4396 | $draft->getVersionInfo(), |
||
| 4397 | $contentUpdate |
||
| 4398 | ); |
||
| 4399 | |||
| 4400 | // Publish updated version |
||
| 4401 | $contentService->publishVersion($draft->getVersionInfo()); |
||
| 4402 | |||
| 4403 | // Commit all changes. |
||
| 4404 | $repository->commit(); |
||
| 4405 | } catch (Exception $e) { |
||
| 4406 | // Cleanup hanging transaction on error |
||
| 4407 | $repository->rollback(); |
||
| 4408 | throw $e; |
||
| 4409 | } |
||
| 4410 | |||
| 4411 | // Name is now "Administrators" |
||
| 4412 | $name = $contentService->loadContent($contentId)->getFieldValue('name', 'eng-US'); |
||
| 4413 | /* END: Use Case */ |
||
| 4414 | |||
| 4415 | $this->assertEquals('Administrators', $name); |
||
| 4416 | } |
||
| 4417 | |||
| 4418 | /** |
||
| 4419 | * Test for the updateContentMetadata() method. |
||
| 4420 | * |
||
| 4421 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 4422 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 4423 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4424 | */ |
||
| 4425 | View Code Duplication | public function testUpdateContentMetadataInTransactionWithRollback() |
|
| 4426 | { |
||
| 4427 | $repository = $this->getRepository(); |
||
| 4428 | |||
| 4429 | $contentId = $this->generateId('object', 12); |
||
| 4430 | /* BEGIN: Use Case */ |
||
| 4431 | // $contentId is the ID of the "Administrator users" user group |
||
| 4432 | |||
| 4433 | // Get the content service |
||
| 4434 | $contentService = $repository->getContentService(); |
||
| 4435 | |||
| 4436 | // Load a ContentInfo object |
||
| 4437 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
| 4438 | |||
| 4439 | // Store remoteId for later testing |
||
| 4440 | $remoteId = $contentInfo->remoteId; |
||
| 4441 | |||
| 4442 | // Start a transaction |
||
| 4443 | $repository->beginTransaction(); |
||
| 4444 | |||
| 4445 | try { |
||
| 4446 | // Get metadata update struct and change remoteId |
||
| 4447 | $metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
||
| 4448 | $metadataUpdate->remoteId = md5(microtime(true)); |
||
| 4449 | |||
| 4450 | // Update the metadata of the published content object |
||
| 4451 | $contentService->updateContentMetadata( |
||
| 4452 | $contentInfo, |
||
| 4453 | $metadataUpdate |
||
| 4454 | ); |
||
| 4455 | } catch (Exception $e) { |
||
| 4456 | // Cleanup hanging transaction on error |
||
| 4457 | $repository->rollback(); |
||
| 4458 | throw $e; |
||
| 4459 | } |
||
| 4460 | |||
| 4461 | // Rollback all changes. |
||
| 4462 | $repository->rollback(); |
||
| 4463 | |||
| 4464 | // Load current remoteId |
||
| 4465 | $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
||
| 4466 | /* END: Use Case */ |
||
| 4467 | |||
| 4468 | $this->assertEquals($remoteId, $remoteIdReloaded); |
||
| 4469 | } |
||
| 4470 | |||
| 4471 | /** |
||
| 4472 | * Test for the updateContentMetadata() method. |
||
| 4473 | * |
||
| 4474 | * @see \eZ\Publish\API\Repository\ContentService::updateContentMetadata() |
||
| 4475 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata |
||
| 4476 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4477 | */ |
||
| 4478 | View Code Duplication | public function testUpdateContentMetadataInTransactionWithCommit() |
|
| 4479 | { |
||
| 4480 | $repository = $this->getRepository(); |
||
| 4481 | |||
| 4482 | $contentId = $this->generateId('object', 12); |
||
| 4483 | /* BEGIN: Use Case */ |
||
| 4484 | // $contentId is the ID of the "Administrator users" user group |
||
| 4485 | |||
| 4486 | // Get the content service |
||
| 4487 | $contentService = $repository->getContentService(); |
||
| 4488 | |||
| 4489 | // Load a ContentInfo object |
||
| 4490 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
| 4491 | |||
| 4492 | // Store remoteId for later testing |
||
| 4493 | $remoteId = $contentInfo->remoteId; |
||
| 4494 | |||
| 4495 | // Start a transaction |
||
| 4496 | $repository->beginTransaction(); |
||
| 4497 | |||
| 4498 | try { |
||
| 4499 | // Get metadata update struct and change remoteId |
||
| 4500 | $metadataUpdate = $contentService->newContentMetadataUpdateStruct(); |
||
| 4501 | $metadataUpdate->remoteId = md5(microtime(true)); |
||
| 4502 | |||
| 4503 | // Update the metadata of the published content object |
||
| 4504 | $contentService->updateContentMetadata( |
||
| 4505 | $contentInfo, |
||
| 4506 | $metadataUpdate |
||
| 4507 | ); |
||
| 4508 | |||
| 4509 | // Commit all changes. |
||
| 4510 | $repository->commit(); |
||
| 4511 | } catch (Exception $e) { |
||
| 4512 | // Cleanup hanging transaction on error |
||
| 4513 | $repository->rollback(); |
||
| 4514 | throw $e; |
||
| 4515 | } |
||
| 4516 | |||
| 4517 | // Load current remoteId |
||
| 4518 | $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId; |
||
| 4519 | /* END: Use Case */ |
||
| 4520 | |||
| 4521 | $this->assertNotEquals($remoteId, $remoteIdReloaded); |
||
| 4522 | } |
||
| 4523 | |||
| 4524 | /** |
||
| 4525 | * Test for the deleteVersion() method. |
||
| 4526 | * |
||
| 4527 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 4528 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 4529 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4530 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
||
| 4531 | */ |
||
| 4532 | public function testDeleteVersionInTransactionWithRollback() |
||
| 4533 | { |
||
| 4534 | $repository = $this->getRepository(); |
||
| 4535 | |||
| 4536 | $contentId = $this->generateId('object', 12); |
||
| 4537 | /* BEGIN: Use Case */ |
||
| 4538 | // $contentId is the ID of the "Administrator users" user group |
||
| 4539 | |||
| 4540 | // Get the content service |
||
| 4541 | $contentService = $repository->getContentService(); |
||
| 4542 | |||
| 4543 | // Start a new transaction |
||
| 4544 | $repository->beginTransaction(); |
||
| 4545 | |||
| 4546 | try { |
||
| 4547 | // Create a new draft |
||
| 4548 | $draft = $contentService->createContentDraft( |
||
| 4549 | $contentService->loadContentInfo($contentId) |
||
| 4550 | ); |
||
| 4551 | |||
| 4552 | $contentService->deleteVersion($draft->getVersionInfo()); |
||
| 4553 | } catch (Exception $e) { |
||
| 4554 | // Cleanup hanging transaction on error |
||
| 4555 | $repository->rollback(); |
||
| 4556 | throw $e; |
||
| 4557 | } |
||
| 4558 | |||
| 4559 | // Rollback all changes. |
||
| 4560 | $repository->rollback(); |
||
| 4561 | |||
| 4562 | // This array will be empty |
||
| 4563 | $drafts = $contentService->loadContentDrafts(); |
||
| 4564 | /* END: Use Case */ |
||
| 4565 | |||
| 4566 | $this->assertSame(array(), $drafts); |
||
| 4567 | } |
||
| 4568 | |||
| 4569 | /** |
||
| 4570 | * Test for the deleteVersion() method. |
||
| 4571 | * |
||
| 4572 | * @see \eZ\Publish\API\Repository\ContentService::deleteVersion() |
||
| 4573 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent |
||
| 4574 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4575 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
||
| 4576 | */ |
||
| 4577 | public function testDeleteVersionInTransactionWithCommit() |
||
| 4578 | { |
||
| 4579 | $repository = $this->getRepository(); |
||
| 4580 | |||
| 4581 | $contentId = $this->generateId('object', 12); |
||
| 4582 | /* BEGIN: Use Case */ |
||
| 4583 | // $contentId is the ID of the "Administrator users" user group |
||
| 4584 | |||
| 4585 | // Get the content service |
||
| 4586 | $contentService = $repository->getContentService(); |
||
| 4587 | |||
| 4588 | // Start a new transaction |
||
| 4589 | $repository->beginTransaction(); |
||
| 4590 | |||
| 4591 | try { |
||
| 4592 | // Create a new draft |
||
| 4593 | $draft = $contentService->createContentDraft( |
||
| 4594 | $contentService->loadContentInfo($contentId) |
||
| 4595 | ); |
||
| 4596 | |||
| 4597 | $contentService->deleteVersion($draft->getVersionInfo()); |
||
| 4598 | |||
| 4599 | // Commit all changes. |
||
| 4600 | $repository->commit(); |
||
| 4601 | } catch (Exception $e) { |
||
| 4602 | // Cleanup hanging transaction on error |
||
| 4603 | $repository->rollback(); |
||
| 4604 | throw $e; |
||
| 4605 | } |
||
| 4606 | |||
| 4607 | // This array will contain no element |
||
| 4608 | $drafts = $contentService->loadContentDrafts(); |
||
| 4609 | /* END: Use Case */ |
||
| 4610 | |||
| 4611 | $this->assertSame(array(), $drafts); |
||
| 4612 | } |
||
| 4613 | |||
| 4614 | /** |
||
| 4615 | * Test for the deleteContent() method. |
||
| 4616 | * |
||
| 4617 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 4618 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
||
| 4619 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4620 | */ |
||
| 4621 | public function testDeleteContentInTransactionWithRollback() |
||
| 4622 | { |
||
| 4623 | $repository = $this->getRepository(); |
||
| 4624 | |||
| 4625 | $contentId = $this->generateId('object', 11); |
||
| 4626 | /* BEGIN: Use Case */ |
||
| 4627 | // $contentId is the ID of the "Members" user group in an eZ Publish |
||
| 4628 | // demo installation |
||
| 4629 | |||
| 4630 | // Get content service |
||
| 4631 | $contentService = $repository->getContentService(); |
||
| 4632 | |||
| 4633 | // Load a ContentInfo instance |
||
| 4634 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
| 4635 | |||
| 4636 | // Start a new transaction |
||
| 4637 | $repository->beginTransaction(); |
||
| 4638 | |||
| 4639 | try { |
||
| 4640 | // Delete content object |
||
| 4641 | $contentService->deleteContent($contentInfo); |
||
| 4642 | } catch (Exception $e) { |
||
| 4643 | // Cleanup hanging transaction on error |
||
| 4644 | $repository->rollback(); |
||
| 4645 | throw $e; |
||
| 4646 | } |
||
| 4647 | |||
| 4648 | // Rollback all changes |
||
| 4649 | $repository->rollback(); |
||
| 4650 | |||
| 4651 | // This call will return the original content object |
||
| 4652 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
| 4653 | /* END: Use Case */ |
||
| 4654 | |||
| 4655 | $this->assertEquals($contentId, $contentInfo->id); |
||
| 4656 | } |
||
| 4657 | |||
| 4658 | /** |
||
| 4659 | * Test for the deleteContent() method. |
||
| 4660 | * |
||
| 4661 | * @see \eZ\Publish\API\Repository\ContentService::deleteContent() |
||
| 4662 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
||
| 4663 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
||
| 4664 | */ |
||
| 4665 | public function testDeleteContentInTransactionWithCommit() |
||
| 4666 | { |
||
| 4667 | $repository = $this->getRepository(); |
||
| 4668 | |||
| 4669 | $contentId = $this->generateId('object', 11); |
||
| 4670 | /* BEGIN: Use Case */ |
||
| 4671 | // $contentId is the ID of the "Members" user group in an eZ Publish |
||
| 4672 | // demo installation |
||
| 4673 | |||
| 4674 | // Get content service |
||
| 4675 | $contentService = $repository->getContentService(); |
||
| 4676 | |||
| 4677 | // Load a ContentInfo instance |
||
| 4678 | $contentInfo = $contentService->loadContentInfo($contentId); |
||
| 4679 | |||
| 4680 | // Start a new transaction |
||
| 4681 | $repository->beginTransaction(); |
||
| 4682 | |||
| 4683 | try { |
||
| 4684 | // Delete content object |
||
| 4685 | $contentService->deleteContent($contentInfo); |
||
| 4686 | |||
| 4687 | // Commit all changes |
||
| 4688 | $repository->commit(); |
||
| 4689 | } catch (Exception $e) { |
||
| 4690 | // Cleanup hanging transaction on error |
||
| 4691 | $repository->rollback(); |
||
| 4692 | throw $e; |
||
| 4693 | } |
||
| 4694 | |||
| 4695 | // Deleted content info is not found anymore |
||
| 4696 | try { |
||
| 4697 | $contentService->loadContentInfo($contentId); |
||
| 4698 | } catch (NotFoundException $e) { |
||
| 4699 | return; |
||
| 4700 | } |
||
| 4701 | /* END: Use Case */ |
||
| 4702 | |||
| 4703 | $this->fail('Can still load ContentInfo after commit.'); |
||
| 4704 | } |
||
| 4705 | |||
| 4706 | /** |
||
| 4707 | * Test for the copyContent() method. |
||
| 4708 | * |
||
| 4709 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 4710 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 4711 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
| 4712 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
| 4713 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
| 4714 | */ |
||
| 4715 | View Code Duplication | public function testCopyContentInTransactionWithRollback() |
|
| 4716 | { |
||
| 4717 | $repository = $this->getRepository(); |
||
| 4718 | |||
| 4719 | $contentId = $this->generateId('object', 11); |
||
| 4720 | $locationId = $this->generateId('location', 13); |
||
| 4721 | /* BEGIN: Use Case */ |
||
| 4722 | // $contentId is the ID of the "Members" user group in an eZ Publish |
||
| 4723 | // demo installation |
||
| 4724 | |||
| 4725 | // $locationId is the ID of the "Administrator users" group location |
||
| 4726 | |||
| 4727 | // Get services |
||
| 4728 | $contentService = $repository->getContentService(); |
||
| 4729 | $locationService = $repository->getLocationService(); |
||
| 4730 | |||
| 4731 | // Load content object to copy |
||
| 4732 | $content = $contentService->loadContent($contentId); |
||
| 4733 | |||
| 4734 | // Create new target location |
||
| 4735 | $locationCreate = $locationService->newLocationCreateStruct($locationId); |
||
| 4736 | |||
| 4737 | // Start a new transaction |
||
| 4738 | $repository->beginTransaction(); |
||
| 4739 | |||
| 4740 | try { |
||
| 4741 | // Copy content with all versions and drafts |
||
| 4742 | $contentService->copyContent( |
||
| 4743 | $content->contentInfo, |
||
| 4744 | $locationCreate |
||
| 4745 | ); |
||
| 4746 | } catch (Exception $e) { |
||
| 4747 | // Cleanup hanging transaction on error |
||
| 4748 | $repository->rollback(); |
||
| 4749 | throw $e; |
||
| 4750 | } |
||
| 4751 | |||
| 4752 | // Rollback all changes |
||
| 4753 | $repository->rollback(); |
||
| 4754 | |||
| 4755 | // This array will only contain a single admin user object |
||
| 4756 | $locations = $locationService->loadLocationChildren( |
||
| 4757 | $locationService->loadLocation($locationId) |
||
| 4758 | )->locations; |
||
| 4759 | /* END: Use Case */ |
||
| 4760 | |||
| 4761 | $this->assertEquals(1, count($locations)); |
||
| 4762 | } |
||
| 4763 | |||
| 4764 | /** |
||
| 4765 | * Test for the copyContent() method. |
||
| 4766 | * |
||
| 4767 | * @see \eZ\Publish\API\Repository\ContentService::copyContent() |
||
| 4768 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCopyContent |
||
| 4769 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
||
| 4770 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
||
| 4771 | * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
||
| 4772 | */ |
||
| 4773 | View Code Duplication | public function testCopyContentInTransactionWithCommit() |
|
| 4774 | { |
||
| 4775 | $repository = $this->getRepository(); |
||
| 4776 | |||
| 4777 | $contentId = $this->generateId('object', 11); |
||
| 4778 | $locationId = $this->generateId('location', 13); |
||
| 4779 | /* BEGIN: Use Case */ |
||
| 4780 | // $contentId is the ID of the "Members" user group in an eZ Publish |
||
| 4781 | // demo installation |
||
| 4782 | |||
| 4783 | // $locationId is the ID of the "Administrator users" group location |
||
| 4784 | |||
| 4785 | // Get services |
||
| 4786 | $contentService = $repository->getContentService(); |
||
| 4787 | $locationService = $repository->getLocationService(); |
||
| 4788 | |||
| 4789 | // Load content object to copy |
||
| 4790 | $content = $contentService->loadContent($contentId); |
||
| 4791 | |||
| 4792 | // Create new target location |
||
| 4793 | $locationCreate = $locationService->newLocationCreateStruct($locationId); |
||
| 4794 | |||
| 4795 | // Start a new transaction |
||
| 4796 | $repository->beginTransaction(); |
||
| 4797 | |||
| 4798 | try { |
||
| 4799 | // Copy content with all versions and drafts |
||
| 4800 | $contentCopied = $contentService->copyContent( |
||
| 4801 | $content->contentInfo, |
||
| 4802 | $locationCreate |
||
| 4803 | ); |
||
| 4804 | |||
| 4805 | // Commit all changes |
||
| 4806 | $repository->commit(); |
||
| 4807 | } catch (Exception $e) { |
||
| 4808 | // Cleanup hanging transaction on error |
||
| 4809 | $repository->rollback(); |
||
| 4810 | throw $e; |
||
| 4811 | } |
||
| 4812 | |||
| 4813 | $this->refreshSearch($repository); |
||
| 4814 | |||
| 4815 | // This will contain the admin user and the new child location |
||
| 4816 | $locations = $locationService->loadLocationChildren( |
||
| 4817 | $locationService->loadLocation($locationId) |
||
| 4818 | )->locations; |
||
| 4819 | /* END: Use Case */ |
||
| 4820 | |||
| 4821 | $this->assertEquals(2, count($locations)); |
||
| 4822 | } |
||
| 4823 | |||
| 4824 | public function testURLAliasesCreatedForNewContent() |
||
| 4825 | { |
||
| 4826 | $repository = $this->getRepository(); |
||
| 4827 | |||
| 4828 | $contentService = $repository->getContentService(); |
||
| 4829 | $locationService = $repository->getLocationService(); |
||
| 4830 | $urlAliasService = $repository->getURLAliasService(); |
||
| 4831 | |||
| 4832 | /* BEGIN: Use Case */ |
||
| 4833 | $draft = $this->createContentDraftVersion1(); |
||
| 4834 | |||
| 4835 | // Automatically creates a new URLAlias for the content |
||
| 4836 | $liveContent = $contentService->publishVersion($draft->getVersionInfo()); |
||
| 4837 | /* END: Use Case */ |
||
| 4838 | |||
| 4839 | $location = $locationService->loadLocation( |
||
| 4840 | $liveContent->getVersionInfo()->getContentInfo()->mainLocationId |
||
| 4841 | ); |
||
| 4842 | |||
| 4843 | $aliases = $urlAliasService->listLocationAliases($location, false); |
||
| 4844 | |||
| 4845 | $this->assertAliasesCorrect( |
||
| 4846 | array( |
||
| 4847 | '/Design/Plain-site/An-awesome-forum' => array( |
||
| 4848 | 'type' => URLAlias::LOCATION, |
||
| 4849 | 'destination' => $location->id, |
||
| 4850 | 'path' => '/Design/Plain-site/An-awesome-forum', |
||
| 4851 | 'languageCodes' => array('eng-US'), |
||
| 4852 | 'isHistory' => false, |
||
| 4853 | 'isCustom' => false, |
||
| 4854 | 'forward' => false, |
||
| 4855 | ), |
||
| 4856 | ), |
||
| 4857 | $aliases |
||
| 4858 | ); |
||
| 4859 | } |
||
| 4860 | |||
| 4861 | public function testURLAliasesCreatedForUpdatedContent() |
||
| 4933 | |||
| 4934 | public function testCustomURLAliasesNotHistorizedOnUpdatedContent() |
||
| 4935 | { |
||
| 4936 | $repository = $this->getRepository(); |
||
| 4937 | |||
| 4938 | $contentService = $repository->getContentService(); |
||
| 4939 | |||
| 4940 | /* BEGIN: Use Case */ |
||
| 4941 | $urlAliasService = $repository->getURLAliasService(); |
||
| 4942 | $locationService = $repository->getLocationService(); |
||
| 4943 | |||
| 4944 | $content = $this->createContentVersion1(); |
||
| 4945 | |||
| 4946 | // Create a custom URL alias |
||
| 4947 | $urlAliasService->createUrlAlias( |
||
| 4948 | $locationService->loadLocation( |
||
| 4949 | $content->getVersionInfo()->getContentInfo()->mainLocationId |
||
| 4950 | ), |
||
| 4951 | '/my/fancy/story-about-ez-publish', |
||
| 4952 | 'eng-US' |
||
| 4953 | ); |
||
| 4954 | |||
| 4955 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
||
| 4956 | |||
| 4957 | $contentUpdate = $contentService->newContentUpdateStruct(); |
||
| 4958 | $contentUpdate->initialLanguageCode = 'eng-US'; |
||
| 4959 | $contentUpdate->setField('name', 'Amazing Bielefeld forum'); |
||
| 4960 | |||
| 4961 | $draftVersion2 = $contentService->updateContent( |
||
| 4962 | $draftVersion2->getVersionInfo(), |
||
| 4963 | $contentUpdate |
||
| 4964 | ); |
||
| 4965 | |||
| 4966 | // Only marks auto-generated aliases as history |
||
| 4967 | // the custom one is left untouched |
||
| 4968 | $liveContent = $contentService->publishVersion($draftVersion2->getVersionInfo()); |
||
| 4969 | /* END: Use Case */ |
||
| 4970 | |||
| 4971 | $location = $locationService->loadLocation( |
||
| 4972 | $liveContent->getVersionInfo()->getContentInfo()->mainLocationId |
||
| 4993 | |||
| 4994 | /** |
||
| 4995 | * Test to ensure that old versions are not affected by updates to newer |
||
| 4996 | * drafts. |
||
| 4997 | */ |
||
| 4998 | public function testUpdatingDraftDoesNotUpdateOldVersions() |
||
| 5016 | |||
| 5017 | /** |
||
| 5018 | * Test scenario with writer and publisher users. |
||
| 5019 | * Writer can only create content. Publisher can publish this content. |
||
| 5020 | */ |
||
| 5021 | public function testPublishWorkflow() |
||
| 5059 | |||
| 5060 | /** |
||
| 5061 | * Test publish / content policy is required to be able to publish content. |
||
| 5062 | * |
||
| 5063 | * @expectedException \eZ\Publish\Core\Base\Exceptions\UnauthorizedException |
||
| 5064 | * @expectedExceptionMessageRegExp /User does not have access to 'publish' 'content'/ |
||
| 5065 | */ |
||
| 5066 | public function testPublishContentWithoutPublishPolicyThrowsException() |
||
| 5085 | |||
| 5086 | /** |
||
| 5087 | * Test for the newTranslationInfo() method. |
||
| 5088 | * |
||
| 5089 | * @covers \eZ\Publish\Core\Repository\ContentService::newTranslationInfo |
||
| 5090 | */ |
||
| 5091 | public function testNewTranslationInfo() |
||
| 5107 | |||
| 5108 | /** |
||
| 5109 | * Simplify creating custom role with limited set of policies. |
||
| 5110 | * |
||
| 5111 | * @param $roleName |
||
| 5112 | * @param array $policies e.g. [ ['content', 'create'], ['content', 'edit'], ] |
||
| 5113 | */ |
||
| 5114 | private function createRoleWithPolicies($roleName, array $policies) |
||
| 5128 | |||
| 5129 | /** |
||
| 5130 | * Asserts that all aliases defined in $expectedAliasProperties with the |
||
| 5131 | * given properties are available in $actualAliases and not more. |
||
| 5132 | * |
||
| 5133 | * @param array $expectedAliasProperties |
||
| 5134 | * @param array $actualAliases |
||
| 5135 | */ |
||
| 5136 | private function assertAliasesCorrect(array $expectedAliasProperties, array $actualAliases) |
||
| 5174 | |||
| 5175 | /** |
||
| 5176 | * Asserts that the given fields are equal to the default fields fixture. |
||
| 5177 | * |
||
| 5178 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5179 | */ |
||
| 5180 | private function assertAllFieldsEquals(array $fields) |
||
| 5187 | |||
| 5188 | /** |
||
| 5189 | * Asserts that the given fields are equal to a language filtered set of the |
||
| 5190 | * default fields fixture. |
||
| 5191 | * |
||
| 5192 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5193 | * @param string $languageCode |
||
| 5194 | */ |
||
| 5195 | private function assertLocaleFieldsEquals(array $fields, $languageCode) |
||
| 5209 | |||
| 5210 | /** |
||
| 5211 | * This method normalizes a set of fields and returns a normalized set. |
||
| 5212 | * |
||
| 5213 | * Normalization means it resets the storage specific field id to zero and |
||
| 5214 | * it sorts the field by their identifier and their language code. In |
||
| 5215 | * addition, the field value is removed, since this one depends on the |
||
| 5216 | * specific FieldType, which is tested in a dedicated integration test. |
||
| 5217 | * |
||
| 5218 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $fields |
||
| 5219 | * |
||
| 5220 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 5221 | */ |
||
| 5222 | private function normalizeFields(array $fields) |
||
| 5248 | |||
| 5249 | /** |
||
| 5250 | * Returns a filtered set of the default fields fixture. |
||
| 5251 | * |
||
| 5252 | * @param string $languageCode |
||
| 5253 | * |
||
| 5254 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 5255 | */ |
||
| 5256 | private function createLocaleFieldsFixture($languageCode) |
||
| 5267 | |||
| 5268 | /** |
||
| 5269 | * Asserts that given Content has default ContentStates. |
||
| 5270 | * |
||
| 5271 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 5272 | */ |
||
| 5273 | View Code Duplication | private function assertDefaultContentStates(ContentInfo $contentInfo) |
|
| 5292 | |||
| 5293 | /** |
||
| 5294 | * Returns the default fixture of fields used in most tests. |
||
| 5295 | * |
||
| 5296 | * @return \eZ\Publish\API\Repository\Values\Content\Field[] |
||
| 5297 | */ |
||
| 5298 | private function createFieldsFixture() |
||
| 5335 | |||
| 5336 | /** |
||
| 5337 | * Gets expected property values for the "Media" ContentInfo ValueObject. |
||
| 5338 | * |
||
| 5339 | * @return array |
||
| 5340 | */ |
||
| 5341 | View Code Duplication | private function getExpectedMediaContentInfoProperties() |
|
| 5359 | } |
||
| 5360 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.