|
@@ 5048-5097 (lines=50) @@
|
| 5045 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 5046 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 5047 |
|
*/ |
| 5048 |
|
public function testCopyContentInTransactionWithRollback() |
| 5049 |
|
{ |
| 5050 |
|
$repository = $this->getRepository(); |
| 5051 |
|
|
| 5052 |
|
$contentId = $this->generateId('object', 11); |
| 5053 |
|
$locationId = $this->generateId('location', 13); |
| 5054 |
|
/* BEGIN: Use Case */ |
| 5055 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 5056 |
|
// demo installation |
| 5057 |
|
|
| 5058 |
|
// $locationId is the ID of the "Administrator users" group location |
| 5059 |
|
|
| 5060 |
|
// Get services |
| 5061 |
|
$contentService = $repository->getContentService(); |
| 5062 |
|
$locationService = $repository->getLocationService(); |
| 5063 |
|
|
| 5064 |
|
// Load content object to copy |
| 5065 |
|
$content = $contentService->loadContent($contentId); |
| 5066 |
|
|
| 5067 |
|
// Create new target location |
| 5068 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 5069 |
|
|
| 5070 |
|
// Start a new transaction |
| 5071 |
|
$repository->beginTransaction(); |
| 5072 |
|
|
| 5073 |
|
try { |
| 5074 |
|
// Copy content with all versions and drafts |
| 5075 |
|
$contentService->copyContent( |
| 5076 |
|
$content->contentInfo, |
| 5077 |
|
$locationCreate |
| 5078 |
|
); |
| 5079 |
|
} catch (Exception $e) { |
| 5080 |
|
// Cleanup hanging transaction on error |
| 5081 |
|
$repository->rollback(); |
| 5082 |
|
throw $e; |
| 5083 |
|
} |
| 5084 |
|
|
| 5085 |
|
// Rollback all changes |
| 5086 |
|
$repository->rollback(); |
| 5087 |
|
|
| 5088 |
|
$this->refreshSearch($repository); |
| 5089 |
|
|
| 5090 |
|
// This array will only contain a single admin user object |
| 5091 |
|
$locations = $locationService->loadLocationChildren( |
| 5092 |
|
$locationService->loadLocation($locationId) |
| 5093 |
|
)->locations; |
| 5094 |
|
/* END: Use Case */ |
| 5095 |
|
|
| 5096 |
|
$this->assertEquals(1, count($locations)); |
| 5097 |
|
} |
| 5098 |
|
|
| 5099 |
|
/** |
| 5100 |
|
* Test for the copyContent() method. |
|
@@ 5108-5157 (lines=50) @@
|
| 5105 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 5106 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 5107 |
|
*/ |
| 5108 |
|
public function testCopyContentInTransactionWithCommit() |
| 5109 |
|
{ |
| 5110 |
|
$repository = $this->getRepository(); |
| 5111 |
|
|
| 5112 |
|
$contentId = $this->generateId('object', 11); |
| 5113 |
|
$locationId = $this->generateId('location', 13); |
| 5114 |
|
/* BEGIN: Use Case */ |
| 5115 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 5116 |
|
// demo installation |
| 5117 |
|
|
| 5118 |
|
// $locationId is the ID of the "Administrator users" group location |
| 5119 |
|
|
| 5120 |
|
// Get services |
| 5121 |
|
$contentService = $repository->getContentService(); |
| 5122 |
|
$locationService = $repository->getLocationService(); |
| 5123 |
|
|
| 5124 |
|
// Load content object to copy |
| 5125 |
|
$content = $contentService->loadContent($contentId); |
| 5126 |
|
|
| 5127 |
|
// Create new target location |
| 5128 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 5129 |
|
|
| 5130 |
|
// Start a new transaction |
| 5131 |
|
$repository->beginTransaction(); |
| 5132 |
|
|
| 5133 |
|
try { |
| 5134 |
|
// Copy content with all versions and drafts |
| 5135 |
|
$contentCopied = $contentService->copyContent( |
| 5136 |
|
$content->contentInfo, |
| 5137 |
|
$locationCreate |
| 5138 |
|
); |
| 5139 |
|
|
| 5140 |
|
// Commit all changes |
| 5141 |
|
$repository->commit(); |
| 5142 |
|
} catch (Exception $e) { |
| 5143 |
|
// Cleanup hanging transaction on error |
| 5144 |
|
$repository->rollback(); |
| 5145 |
|
throw $e; |
| 5146 |
|
} |
| 5147 |
|
|
| 5148 |
|
$this->refreshSearch($repository); |
| 5149 |
|
|
| 5150 |
|
// This will contain the admin user and the new child location |
| 5151 |
|
$locations = $locationService->loadLocationChildren( |
| 5152 |
|
$locationService->loadLocation($locationId) |
| 5153 |
|
)->locations; |
| 5154 |
|
/* END: Use Case */ |
| 5155 |
|
|
| 5156 |
|
$this->assertEquals(2, count($locations)); |
| 5157 |
|
} |
| 5158 |
|
|
| 5159 |
|
public function testURLAliasesCreatedForNewContent() |
| 5160 |
|
{ |