Code Duplication    Length = 36-36 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 3 locations

@@ 4873-4908 (lines=36) @@
4870
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4871
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4872
     */
4873
    public function testDeleteVersionInTransactionWithRollback()
4874
    {
4875
        $repository = $this->getRepository();
4876
4877
        $contentId = $this->generateId('object', 12);
4878
        /* BEGIN: Use Case */
4879
        // $contentId is the ID of the "Administrator users" user group
4880
4881
        // Get the content service
4882
        $contentService = $repository->getContentService();
4883
4884
        // Start a new transaction
4885
        $repository->beginTransaction();
4886
4887
        try {
4888
            // Create a new draft
4889
            $draft = $contentService->createContentDraft(
4890
                $contentService->loadContentInfo($contentId)
4891
            );
4892
4893
            $contentService->deleteVersion($draft->getVersionInfo());
4894
        } catch (Exception $e) {
4895
            // Cleanup hanging transaction on error
4896
            $repository->rollback();
4897
            throw $e;
4898
        }
4899
4900
        // Rollback all changes.
4901
        $repository->rollback();
4902
4903
        // This array will be empty
4904
        $drafts = $contentService->loadContentDrafts();
4905
        /* END: Use Case */
4906
4907
        $this->assertSame([], $drafts);
4908
    }
4909
4910
    /**
4911
     * Test for the deleteVersion() method.
@@ 4918-4953 (lines=36) @@
4915
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4916
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4917
     */
4918
    public function testDeleteVersionInTransactionWithCommit()
4919
    {
4920
        $repository = $this->getRepository();
4921
4922
        $contentId = $this->generateId('object', 12);
4923
        /* BEGIN: Use Case */
4924
        // $contentId is the ID of the "Administrator users" user group
4925
4926
        // Get the content service
4927
        $contentService = $repository->getContentService();
4928
4929
        // Start a new transaction
4930
        $repository->beginTransaction();
4931
4932
        try {
4933
            // Create a new draft
4934
            $draft = $contentService->createContentDraft(
4935
                $contentService->loadContentInfo($contentId)
4936
            );
4937
4938
            $contentService->deleteVersion($draft->getVersionInfo());
4939
4940
            // Commit all changes.
4941
            $repository->commit();
4942
        } catch (Exception $e) {
4943
            // Cleanup hanging transaction on error
4944
            $repository->rollback();
4945
            throw $e;
4946
        }
4947
4948
        // This array will contain no element
4949
        $drafts = $contentService->loadContentDrafts();
4950
        /* END: Use Case */
4951
4952
        $this->assertSame([], $drafts);
4953
    }
4954
4955
    /**
4956
     * Test for the deleteContent() method.
@@ 4962-4997 (lines=36) @@
4959
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4960
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4961
     */
4962
    public function testDeleteContentInTransactionWithRollback()
4963
    {
4964
        $repository = $this->getRepository();
4965
4966
        $contentId = $this->generateId('object', 11);
4967
        /* BEGIN: Use Case */
4968
        // $contentId is the ID of the "Members" user group in an eZ Publish
4969
        // demo installation
4970
4971
        // Get content service
4972
        $contentService = $repository->getContentService();
4973
4974
        // Load a ContentInfo instance
4975
        $contentInfo = $contentService->loadContentInfo($contentId);
4976
4977
        // Start a new transaction
4978
        $repository->beginTransaction();
4979
4980
        try {
4981
            // Delete content object
4982
            $contentService->deleteContent($contentInfo);
4983
        } catch (Exception $e) {
4984
            // Cleanup hanging transaction on error
4985
            $repository->rollback();
4986
            throw $e;
4987
        }
4988
4989
        // Rollback all changes
4990
        $repository->rollback();
4991
4992
        // This call will return the original content object
4993
        $contentInfo = $contentService->loadContentInfo($contentId);
4994
        /* END: Use Case */
4995
4996
        $this->assertEquals($contentId, $contentInfo->id);
4997
    }
4998
4999
    /**
5000
     * Test for the deleteContent() method.