|
@@ 4621-4666 (lines=46) @@
|
| 4618 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4619 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4620 |
|
*/ |
| 4621 |
|
public function testCopyContentInTransactionWithRollback() |
| 4622 |
|
{ |
| 4623 |
|
$repository = $this->getRepository(); |
| 4624 |
|
|
| 4625 |
|
$contentId = $this->generateId('object', 11); |
| 4626 |
|
$locationId = $this->generateId('location', 13); |
| 4627 |
|
/* BEGIN: Use Case */ |
| 4628 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4629 |
|
// demo installation |
| 4630 |
|
|
| 4631 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4632 |
|
|
| 4633 |
|
// Load content object to copy |
| 4634 |
|
$content = $this->contentService->loadContent($contentId); |
| 4635 |
|
|
| 4636 |
|
// Create new target location |
| 4637 |
|
$locationCreate = $this->locationService->newLocationCreateStruct($locationId); |
| 4638 |
|
|
| 4639 |
|
// Start a new transaction |
| 4640 |
|
$repository->beginTransaction(); |
| 4641 |
|
|
| 4642 |
|
try { |
| 4643 |
|
// Copy content with all versions and drafts |
| 4644 |
|
$this->contentService->copyContent( |
| 4645 |
|
$content->contentInfo, |
| 4646 |
|
$locationCreate |
| 4647 |
|
); |
| 4648 |
|
} catch (Exception $e) { |
| 4649 |
|
// Cleanup hanging transaction on error |
| 4650 |
|
$repository->rollback(); |
| 4651 |
|
throw $e; |
| 4652 |
|
} |
| 4653 |
|
|
| 4654 |
|
// Rollback all changes |
| 4655 |
|
$repository->rollback(); |
| 4656 |
|
|
| 4657 |
|
$this->refreshSearch($repository); |
| 4658 |
|
|
| 4659 |
|
// This array will only contain a single admin user object |
| 4660 |
|
$locations = $this->locationService->loadLocationChildren( |
| 4661 |
|
$this->locationService->loadLocation($locationId) |
| 4662 |
|
)->locations; |
| 4663 |
|
/* END: Use Case */ |
| 4664 |
|
|
| 4665 |
|
$this->assertEquals(1, count($locations)); |
| 4666 |
|
} |
| 4667 |
|
|
| 4668 |
|
/** |
| 4669 |
|
* Test for the copyContent() method. |
|
@@ 4677-4722 (lines=46) @@
|
| 4674 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren |
| 4675 |
|
* @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation |
| 4676 |
|
*/ |
| 4677 |
|
public function testCopyContentInTransactionWithCommit() |
| 4678 |
|
{ |
| 4679 |
|
$repository = $this->getRepository(); |
| 4680 |
|
|
| 4681 |
|
$contentId = $this->generateId('object', 11); |
| 4682 |
|
$locationId = $this->generateId('location', 13); |
| 4683 |
|
/* BEGIN: Use Case */ |
| 4684 |
|
// $contentId is the ID of the "Members" user group in an eZ Publish |
| 4685 |
|
// demo installation |
| 4686 |
|
|
| 4687 |
|
// $locationId is the ID of the "Administrator users" group location |
| 4688 |
|
|
| 4689 |
|
// Load content object to copy |
| 4690 |
|
$content = $this->contentService->loadContent($contentId); |
| 4691 |
|
|
| 4692 |
|
// Create new target location |
| 4693 |
|
$locationCreate = $this->locationService->newLocationCreateStruct($locationId); |
| 4694 |
|
|
| 4695 |
|
// Start a new transaction |
| 4696 |
|
$repository->beginTransaction(); |
| 4697 |
|
|
| 4698 |
|
try { |
| 4699 |
|
// Copy content with all versions and drafts |
| 4700 |
|
$contentCopied = $this->contentService->copyContent( |
| 4701 |
|
$content->contentInfo, |
| 4702 |
|
$locationCreate |
| 4703 |
|
); |
| 4704 |
|
|
| 4705 |
|
// Commit all changes |
| 4706 |
|
$repository->commit(); |
| 4707 |
|
} catch (Exception $e) { |
| 4708 |
|
// Cleanup hanging transaction on error |
| 4709 |
|
$repository->rollback(); |
| 4710 |
|
throw $e; |
| 4711 |
|
} |
| 4712 |
|
|
| 4713 |
|
$this->refreshSearch($repository); |
| 4714 |
|
|
| 4715 |
|
// This will contain the admin user and the new child location |
| 4716 |
|
$locations = $this->locationService->loadLocationChildren( |
| 4717 |
|
$this->locationService->loadLocation($locationId) |
| 4718 |
|
)->locations; |
| 4719 |
|
/* END: Use Case */ |
| 4720 |
|
|
| 4721 |
|
$this->assertEquals(2, count($locations)); |
| 4722 |
|
} |
| 4723 |
|
|
| 4724 |
|
public function testURLAliasesCreatedForNewContent() |
| 4725 |
|
{ |