|
@@ 5008-5057 (lines=50) @@
|
| 5005 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 5006 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 5007 |
|
*/ |
| 5008 |
|
public function testCopyContentInTransactionWithRollback() |
| 5009 |
|
{ |
| 5010 |
|
$repository = $this->getRepository(); |
| 5011 |
|
|
| 5012 |
|
$contentId = $this->generateId('object', 11); |
| 5013 |
|
$locationId = $this->generateId('location', 13); |
| 5014 |
|
/* BEGIN: Use Case */ |
| 5015 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 5016 |
|
// demo installation |
| 5017 |
|
|
| 5018 |
|
// $locationId is the ID of the "Administrator users" group location |
| 5019 |
|
|
| 5020 |
|
// Get services |
| 5021 |
|
$contentService = $repository->getContentService(); |
| 5022 |
|
$locationService = $repository->getLocationService(); |
| 5023 |
|
|
| 5024 |
|
// Load content object to copy |
| 5025 |
|
$content = $contentService->loadContent($contentId); |
| 5026 |
|
|
| 5027 |
|
// Create new target location |
| 5028 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 5029 |
|
|
| 5030 |
|
// Start a new transaction |
| 5031 |
|
$repository->beginTransaction(); |
| 5032 |
|
|
| 5033 |
|
try { |
| 5034 |
|
// Copy content with all versions and drafts |
| 5035 |
|
$contentService->copyContent( |
| 5036 |
|
$content->contentInfo, |
| 5037 |
|
$locationCreate |
| 5038 |
|
); |
| 5039 |
|
} catch (Exception $e) { |
| 5040 |
|
// Cleanup hanging transaction on error |
| 5041 |
|
$repository->rollback(); |
| 5042 |
|
throw $e; |
| 5043 |
|
} |
| 5044 |
|
|
| 5045 |
|
// Rollback all changes |
| 5046 |
|
$repository->rollback(); |
| 5047 |
|
|
| 5048 |
|
$this->refreshSearch($repository); |
| 5049 |
|
|
| 5050 |
|
// This array will only contain a single admin user object |
| 5051 |
|
$locations = $locationService->loadLocationChildren( |
| 5052 |
|
$locationService->loadLocation($locationId) |
| 5053 |
|
)->locations; |
| 5054 |
|
/* END: Use Case */ |
| 5055 |
|
|
| 5056 |
|
$this->assertEquals(1, count($locations)); |
| 5057 |
|
} |
| 5058 |
|
|
| 5059 |
|
/** |
| 5060 |
|
* Test for the copyContent() method. |
|
@@ 5068-5117 (lines=50) @@
|
| 5065 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 5066 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 5067 |
|
*/ |
| 5068 |
|
public function testCopyContentInTransactionWithCommit() |
| 5069 |
|
{ |
| 5070 |
|
$repository = $this->getRepository(); |
| 5071 |
|
|
| 5072 |
|
$contentId = $this->generateId('object', 11); |
| 5073 |
|
$locationId = $this->generateId('location', 13); |
| 5074 |
|
/* BEGIN: Use Case */ |
| 5075 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 5076 |
|
// demo installation |
| 5077 |
|
|
| 5078 |
|
// $locationId is the ID of the "Administrator users" group location |
| 5079 |
|
|
| 5080 |
|
// Get services |
| 5081 |
|
$contentService = $repository->getContentService(); |
| 5082 |
|
$locationService = $repository->getLocationService(); |
| 5083 |
|
|
| 5084 |
|
// Load content object to copy |
| 5085 |
|
$content = $contentService->loadContent($contentId); |
| 5086 |
|
|
| 5087 |
|
// Create new target location |
| 5088 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 5089 |
|
|
| 5090 |
|
// Start a new transaction |
| 5091 |
|
$repository->beginTransaction(); |
| 5092 |
|
|
| 5093 |
|
try { |
| 5094 |
|
// Copy content with all versions and drafts |
| 5095 |
|
$contentCopied = $contentService->copyContent( |
| 5096 |
|
$content->contentInfo, |
| 5097 |
|
$locationCreate |
| 5098 |
|
); |
| 5099 |
|
|
| 5100 |
|
// Commit all changes |
| 5101 |
|
$repository->commit(); |
| 5102 |
|
} catch (Exception $e) { |
| 5103 |
|
// Cleanup hanging transaction on error |
| 5104 |
|
$repository->rollback(); |
| 5105 |
|
throw $e; |
| 5106 |
|
} |
| 5107 |
|
|
| 5108 |
|
$this->refreshSearch($repository); |
| 5109 |
|
|
| 5110 |
|
// This will contain the admin user and the new child location |
| 5111 |
|
$locations = $locationService->loadLocationChildren( |
| 5112 |
|
$locationService->loadLocation($locationId) |
| 5113 |
|
)->locations; |
| 5114 |
|
/* END: Use Case */ |
| 5115 |
|
|
| 5116 |
|
$this->assertEquals(2, count($locations)); |
| 5117 |
|
} |
| 5118 |
|
|
| 5119 |
|
public function testURLAliasesCreatedForNewContent() |
| 5120 |
|
{ |