|
@@ 3784-3823 (lines=40) @@
|
| 3781 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
| 3782 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 3783 |
|
*/ |
| 3784 |
|
public function testCreateContentDraftInTransactionWithCommit() |
| 3785 |
|
{ |
| 3786 |
|
$repository = $this->getRepository(); |
| 3787 |
|
|
| 3788 |
|
$contentId = $this->generateId('object', 12); |
| 3789 |
|
/* BEGIN: Use Case */ |
| 3790 |
|
// $contentId is the ID of the "Administrator users" user group |
| 3791 |
|
|
| 3792 |
|
// Get the content service |
| 3793 |
|
$contentService = $repository->getContentService(); |
| 3794 |
|
|
| 3795 |
|
// Load the user group content object |
| 3796 |
|
$content = $contentService->loadContent($contentId); |
| 3797 |
|
|
| 3798 |
|
// Start a new transaction |
| 3799 |
|
$repository->beginTransaction(); |
| 3800 |
|
|
| 3801 |
|
try { |
| 3802 |
|
// Create a new draft |
| 3803 |
|
$drafted = $contentService->createContentDraft($content->contentInfo); |
| 3804 |
|
|
| 3805 |
|
// Store version number for later reuse |
| 3806 |
|
$versionNo = $drafted->versionInfo->versionNo; |
| 3807 |
|
|
| 3808 |
|
// Commit all changes |
| 3809 |
|
$repository->commit(); |
| 3810 |
|
} catch (Exception $e) { |
| 3811 |
|
// Cleanup hanging transaction on error |
| 3812 |
|
$repository->rollback(); |
| 3813 |
|
throw $e; |
| 3814 |
|
} |
| 3815 |
|
|
| 3816 |
|
$content = $contentService->loadContent($contentId, null, $versionNo); |
| 3817 |
|
/* END: Use Case */ |
| 3818 |
|
|
| 3819 |
|
$this->assertEquals( |
| 3820 |
|
$versionNo, |
| 3821 |
|
$content->getVersionInfo()->versionNo |
| 3822 |
|
); |
| 3823 |
|
} |
| 3824 |
|
|
| 3825 |
|
/** |
| 3826 |
|
* Test for the publishVersion() method. |
|
@@ 3832-3875 (lines=44) @@
|
| 3829 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 3830 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContent |
| 3831 |
|
*/ |
| 3832 |
|
public function testPublishVersionInTransactionWithRollback() |
| 3833 |
|
{ |
| 3834 |
|
$repository = $this->getRepository(); |
| 3835 |
|
|
| 3836 |
|
$contentId = $this->generateId('object', 12); |
| 3837 |
|
/* BEGIN: Use Case */ |
| 3838 |
|
// $contentId is the ID of the "Administrator users" user group |
| 3839 |
|
|
| 3840 |
|
// Get the content service |
| 3841 |
|
$contentService = $repository->getContentService(); |
| 3842 |
|
|
| 3843 |
|
// Load the user group content object |
| 3844 |
|
$content = $contentService->loadContent($contentId); |
| 3845 |
|
|
| 3846 |
|
// Start a new transaction |
| 3847 |
|
$repository->beginTransaction(); |
| 3848 |
|
|
| 3849 |
|
try { |
| 3850 |
|
$draftVersion = $contentService->createContentDraft($content->contentInfo)->getVersionInfo(); |
| 3851 |
|
|
| 3852 |
|
// Publish a new version |
| 3853 |
|
$content = $contentService->publishVersion($draftVersion); |
| 3854 |
|
|
| 3855 |
|
// Store version number for later reuse |
| 3856 |
|
$versionNo = $content->versionInfo->versionNo; |
| 3857 |
|
} catch (Exception $e) { |
| 3858 |
|
// Cleanup hanging transaction on error |
| 3859 |
|
$repository->rollback(); |
| 3860 |
|
throw $e; |
| 3861 |
|
} |
| 3862 |
|
|
| 3863 |
|
// Rollback |
| 3864 |
|
$repository->rollback(); |
| 3865 |
|
|
| 3866 |
|
try { |
| 3867 |
|
// This call will fail with a "NotFoundException" |
| 3868 |
|
$contentService->loadContent($contentId, null, $versionNo); |
| 3869 |
|
} catch (NotFoundException $e) { |
| 3870 |
|
return; |
| 3871 |
|
} |
| 3872 |
|
/* END: Use Case */ |
| 3873 |
|
|
| 3874 |
|
$this->fail('Can still load content draft after rollback'); |
| 3875 |
|
} |
| 3876 |
|
|
| 3877 |
|
/** |
| 3878 |
|
* Test for the publishVersion() method. |
|
@@ 3884-3923 (lines=40) @@
|
| 3881 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersion |
| 3882 |
|
* @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
| 3883 |
|
*/ |
| 3884 |
|
public function testPublishVersionInTransactionWithCommit() |
| 3885 |
|
{ |
| 3886 |
|
$repository = $this->getRepository(); |
| 3887 |
|
|
| 3888 |
|
/* BEGIN: Use Case */ |
| 3889 |
|
// ID of the "Administrator users" user group |
| 3890 |
|
$contentId = 12; |
| 3891 |
|
|
| 3892 |
|
// Get the content service |
| 3893 |
|
$contentService = $repository->getContentService(); |
| 3894 |
|
|
| 3895 |
|
// Load the user group content object |
| 3896 |
|
$template = $contentService->loadContent($contentId); |
| 3897 |
|
|
| 3898 |
|
// Start a new transaction |
| 3899 |
|
$repository->beginTransaction(); |
| 3900 |
|
|
| 3901 |
|
try { |
| 3902 |
|
// Publish a new version |
| 3903 |
|
$content = $contentService->publishVersion( |
| 3904 |
|
$contentService->createContentDraft($template->contentInfo)->getVersionInfo() |
| 3905 |
|
); |
| 3906 |
|
|
| 3907 |
|
// Store version number for later reuse |
| 3908 |
|
$versionNo = $content->versionInfo->versionNo; |
| 3909 |
|
|
| 3910 |
|
// Commit all changes |
| 3911 |
|
$repository->commit(); |
| 3912 |
|
} catch (Exception $e) { |
| 3913 |
|
// Cleanup hanging transaction on error |
| 3914 |
|
$repository->rollback(); |
| 3915 |
|
throw $e; |
| 3916 |
|
} |
| 3917 |
|
|
| 3918 |
|
// Load current version info |
| 3919 |
|
$versionInfo = $contentService->loadVersionInfo($content->contentInfo); |
| 3920 |
|
/* END: Use Case */ |
| 3921 |
|
|
| 3922 |
|
$this->assertEquals($versionNo, $versionInfo->versionNo); |
| 3923 |
|
} |
| 3924 |
|
|
| 3925 |
|
/** |
| 3926 |
|
* Test for the updateContent() method. |