Code Duplication    Length = 36-36 lines in 3 locations

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

@@ 4772-4807 (lines=36) @@
4769
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4770
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4771
     */
4772
    public function testDeleteVersionInTransactionWithRollback()
4773
    {
4774
        $repository = $this->getRepository();
4775
4776
        $contentId = $this->generateId('object', 12);
4777
        /* BEGIN: Use Case */
4778
        // $contentId is the ID of the "Administrator users" user group
4779
4780
        // Get the content service
4781
        $contentService = $repository->getContentService();
4782
4783
        // Start a new transaction
4784
        $repository->beginTransaction();
4785
4786
        try {
4787
            // Create a new draft
4788
            $draft = $contentService->createContentDraft(
4789
                $contentService->loadContentInfo($contentId)
4790
            );
4791
4792
            $contentService->deleteVersion($draft->getVersionInfo());
4793
        } catch (Exception $e) {
4794
            // Cleanup hanging transaction on error
4795
            $repository->rollback();
4796
            throw $e;
4797
        }
4798
4799
        // Rollback all changes.
4800
        $repository->rollback();
4801
4802
        // This array will be empty
4803
        $drafts = $contentService->loadContentDrafts();
4804
        /* END: Use Case */
4805
4806
        $this->assertSame([], $drafts);
4807
    }
4808
4809
    /**
4810
     * Test for the deleteVersion() method.
@@ 4817-4852 (lines=36) @@
4814
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4815
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts
4816
     */
4817
    public function testDeleteVersionInTransactionWithCommit()
4818
    {
4819
        $repository = $this->getRepository();
4820
4821
        $contentId = $this->generateId('object', 12);
4822
        /* BEGIN: Use Case */
4823
        // $contentId is the ID of the "Administrator users" user group
4824
4825
        // Get the content service
4826
        $contentService = $repository->getContentService();
4827
4828
        // Start a new transaction
4829
        $repository->beginTransaction();
4830
4831
        try {
4832
            // Create a new draft
4833
            $draft = $contentService->createContentDraft(
4834
                $contentService->loadContentInfo($contentId)
4835
            );
4836
4837
            $contentService->deleteVersion($draft->getVersionInfo());
4838
4839
            // Commit all changes.
4840
            $repository->commit();
4841
        } catch (Exception $e) {
4842
            // Cleanup hanging transaction on error
4843
            $repository->rollback();
4844
            throw $e;
4845
        }
4846
4847
        // This array will contain no element
4848
        $drafts = $contentService->loadContentDrafts();
4849
        /* END: Use Case */
4850
4851
        $this->assertSame([], $drafts);
4852
    }
4853
4854
    /**
4855
     * Test for the deleteContent() method.
@@ 4861-4896 (lines=36) @@
4858
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent
4859
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4860
     */
4861
    public function testDeleteContentInTransactionWithRollback()
4862
    {
4863
        $repository = $this->getRepository();
4864
4865
        $contentId = $this->generateId('object', 11);
4866
        /* BEGIN: Use Case */
4867
        // $contentId is the ID of the "Members" user group in an eZ Publish
4868
        // demo installation
4869
4870
        // Get content service
4871
        $contentService = $repository->getContentService();
4872
4873
        // Load a ContentInfo instance
4874
        $contentInfo = $contentService->loadContentInfo($contentId);
4875
4876
        // Start a new transaction
4877
        $repository->beginTransaction();
4878
4879
        try {
4880
            // Delete content object
4881
            $contentService->deleteContent($contentInfo);
4882
        } catch (Exception $e) {
4883
            // Cleanup hanging transaction on error
4884
            $repository->rollback();
4885
            throw $e;
4886
        }
4887
4888
        // Rollback all changes
4889
        $repository->rollback();
4890
4891
        // This call will return the original content object
4892
        $contentInfo = $contentService->loadContentInfo($contentId);
4893
        /* END: Use Case */
4894
4895
        $this->assertEquals($contentId, $contentInfo->id);
4896
    }
4897
4898
    /**
4899
     * Test for the deleteContent() method.