|
@@ 4493-4540 (lines=48) @@
|
| 4490 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4491 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4492 |
|
*/ |
| 4493 |
|
public function testCopyContentInTransactionWithRollback() |
| 4494 |
|
{ |
| 4495 |
|
$repository = $this->getRepository(); |
| 4496 |
|
|
| 4497 |
|
$contentId = $this->generateId('object', 11); |
| 4498 |
|
$locationId = $this->generateId('location', 13); |
| 4499 |
|
/* BEGIN: Use Case */ |
| 4500 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4501 |
|
// demo installation |
| 4502 |
|
|
| 4503 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4504 |
|
|
| 4505 |
|
// Get services |
| 4506 |
|
$contentService = $repository->getContentService(); |
| 4507 |
|
$locationService = $repository->getLocationService(); |
| 4508 |
|
|
| 4509 |
|
// Load content object to copy |
| 4510 |
|
$content = $contentService->loadContent($contentId); |
| 4511 |
|
|
| 4512 |
|
// Create new target location |
| 4513 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 4514 |
|
|
| 4515 |
|
// Start a new transaction |
| 4516 |
|
$repository->beginTransaction(); |
| 4517 |
|
|
| 4518 |
|
try { |
| 4519 |
|
// Copy content with all versions and drafts |
| 4520 |
|
$contentService->copyContent( |
| 4521 |
|
$content->contentInfo, |
| 4522 |
|
$locationCreate |
| 4523 |
|
); |
| 4524 |
|
} catch (Exception $e) { |
| 4525 |
|
// Cleanup hanging transaction on error |
| 4526 |
|
$repository->rollback(); |
| 4527 |
|
throw $e; |
| 4528 |
|
} |
| 4529 |
|
|
| 4530 |
|
// Rollback all changes |
| 4531 |
|
$repository->rollback(); |
| 4532 |
|
|
| 4533 |
|
// This array will only contain a single admin user object |
| 4534 |
|
$locations = $locationService->loadLocationChildren( |
| 4535 |
|
$locationService->loadLocation($locationId) |
| 4536 |
|
)->locations; |
| 4537 |
|
/* END: Use Case */ |
| 4538 |
|
|
| 4539 |
|
$this->assertEquals(1, count($locations)); |
| 4540 |
|
} |
| 4541 |
|
|
| 4542 |
|
/** |
| 4543 |
|
* Test for the copyContent() method. |
|
@@ 4551-4600 (lines=50) @@
|
| 4548 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4549 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4550 |
|
*/ |
| 4551 |
|
public function testCopyContentInTransactionWithCommit() |
| 4552 |
|
{ |
| 4553 |
|
$repository = $this->getRepository(); |
| 4554 |
|
|
| 4555 |
|
$contentId = $this->generateId('object', 11); |
| 4556 |
|
$locationId = $this->generateId('location', 13); |
| 4557 |
|
/* BEGIN: Use Case */ |
| 4558 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4559 |
|
// demo installation |
| 4560 |
|
|
| 4561 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4562 |
|
|
| 4563 |
|
// Get services |
| 4564 |
|
$contentService = $repository->getContentService(); |
| 4565 |
|
$locationService = $repository->getLocationService(); |
| 4566 |
|
|
| 4567 |
|
// Load content object to copy |
| 4568 |
|
$content = $contentService->loadContent($contentId); |
| 4569 |
|
|
| 4570 |
|
// Create new target location |
| 4571 |
|
$locationCreate = $locationService->newLocationCreateStruct($locationId); |
| 4572 |
|
|
| 4573 |
|
// Start a new transaction |
| 4574 |
|
$repository->beginTransaction(); |
| 4575 |
|
|
| 4576 |
|
try { |
| 4577 |
|
// Copy content with all versions and drafts |
| 4578 |
|
$contentCopied = $contentService->copyContent( |
| 4579 |
|
$content->contentInfo, |
| 4580 |
|
$locationCreate |
| 4581 |
|
); |
| 4582 |
|
|
| 4583 |
|
// Commit all changes |
| 4584 |
|
$repository->commit(); |
| 4585 |
|
} catch (Exception $e) { |
| 4586 |
|
// Cleanup hanging transaction on error |
| 4587 |
|
$repository->rollback(); |
| 4588 |
|
throw $e; |
| 4589 |
|
} |
| 4590 |
|
|
| 4591 |
|
$this->refreshSearch($repository); |
| 4592 |
|
|
| 4593 |
|
// This will contain the admin user and the new child location |
| 4594 |
|
$locations = $locationService->loadLocationChildren( |
| 4595 |
|
$locationService->loadLocation($locationId) |
| 4596 |
|
)->locations; |
| 4597 |
|
/* END: Use Case */ |
| 4598 |
|
|
| 4599 |
|
$this->assertEquals(2, count($locations)); |
| 4600 |
|
} |
| 4601 |
|
|
| 4602 |
|
public function testURLAliasesCreatedForNewContent() |
| 4603 |
|
{ |