Code Duplication    Length = 36-36 lines in 3 locations

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

@@ 4832-4867 (lines=36) @@
4829
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4830
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4831
     */
4832
    public function testDeleteVersionInTransactionWithRollback()
4833
    {
4834
        $repository = $this->getRepository();
4835
4836
        $contentId = $this->generateId('object', 12);
4837
        /* BEGIN: Use Case */
4838
        // $contentId is the ID of the "Administrator users" user group
4839
4840
        // Get the content service
4841
        $contentService = $repository->getContentService();
4842
4843
        // Start a new transaction
4844
        $repository->beginTransaction();
4845
4846
        try {
4847
            // Create a new draft
4848
            $draft = $contentService->createContentDraft(
4849
                $contentService->loadContentInfo($contentId)
4850
            );
4851
4852
            $contentService->deleteVersion($draft->getVersionInfo());
4853
        } catch (Exception $e) {
4854
            // Cleanup hanging transaction on error
4855
            $repository->rollback();
4856
            throw $e;
4857
        }
4858
4859
        // Rollback all changes.
4860
        $repository->rollback();
4861
4862
        // This array will be empty
4863
        $drafts = $contentService->loadContentDrafts();
4864
        /* END: Use Case */
4865
4866
        $this->assertSame([], $drafts);
4867
    }
4868
4869
    /**
4870
     * Test for the deleteVersion() method.
@@ 4877-4912 (lines=36) @@
4874
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4875
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4876
     */
4877
    public function testDeleteVersionInTransactionWithCommit()
4878
    {
4879
        $repository = $this->getRepository();
4880
4881
        $contentId = $this->generateId('object', 12);
4882
        /* BEGIN: Use Case */
4883
        // $contentId is the ID of the "Administrator users" user group
4884
4885
        // Get the content service
4886
        $contentService = $repository->getContentService();
4887
4888
        // Start a new transaction
4889
        $repository->beginTransaction();
4890
4891
        try {
4892
            // Create a new draft
4893
            $draft = $contentService->createContentDraft(
4894
                $contentService->loadContentInfo($contentId)
4895
            );
4896
4897
            $contentService->deleteVersion($draft->getVersionInfo());
4898
4899
            // Commit all changes.
4900
            $repository->commit();
4901
        } catch (Exception $e) {
4902
            // Cleanup hanging transaction on error
4903
            $repository->rollback();
4904
            throw $e;
4905
        }
4906
4907
        // This array will contain no element
4908
        $drafts = $contentService->loadContentDrafts();
4909
        /* END: Use Case */
4910
4911
        $this->assertSame([], $drafts);
4912
    }
4913
4914
    /**
4915
     * Test for the deleteContent() method.
@@ 4921-4956 (lines=36) @@
4918
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4919
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4920
     */
4921
    public function testDeleteContentInTransactionWithRollback()
4922
    {
4923
        $repository = $this->getRepository();
4924
4925
        $contentId = $this->generateId('object', 11);
4926
        /* BEGIN: Use Case */
4927
        // $contentId is the ID of the "Members" user group in an eZ Publish
4928
        // demo installation
4929
4930
        // Get content service
4931
        $contentService = $repository->getContentService();
4932
4933
        // Load a ContentInfo instance
4934
        $contentInfo = $contentService->loadContentInfo($contentId);
4935
4936
        // Start a new transaction
4937
        $repository->beginTransaction();
4938
4939
        try {
4940
            // Delete content object
4941
            $contentService->deleteContent($contentInfo);
4942
        } catch (Exception $e) {
4943
            // Cleanup hanging transaction on error
4944
            $repository->rollback();
4945
            throw $e;
4946
        }
4947
4948
        // Rollback all changes
4949
        $repository->rollback();
4950
4951
        // This call will return the original content object
4952
        $contentInfo = $contentService->loadContentInfo($contentId);
4953
        /* END: Use Case */
4954
4955
        $this->assertEquals($contentId, $contentInfo->id);
4956
    }
4957
4958
    /**
4959
     * Test for the deleteContent() method.