Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4569-4613 (lines=45) @@
4566
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4567
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4568
     */
4569
    public function testUpdateContentMetadataInTransactionWithRollback()
4570
    {
4571
        $repository = $this->getRepository();
4572
4573
        $contentId = $this->generateId('object', 12);
4574
        /* BEGIN: Use Case */
4575
        // $contentId is the ID of the "Administrator users" user group
4576
4577
        // Get the content service
4578
        $contentService = $repository->getContentService();
4579
4580
        // Load a ContentInfo object
4581
        $contentInfo = $contentService->loadContentInfo($contentId);
4582
4583
        // Store remoteId for later testing
4584
        $remoteId = $contentInfo->remoteId;
4585
4586
        // Start a transaction
4587
        $repository->beginTransaction();
4588
4589
        try {
4590
            // Get metadata update struct and change remoteId
4591
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4592
            $metadataUpdate->remoteId = md5(microtime(true));
4593
4594
            // Update the metadata of the published content object
4595
            $contentService->updateContentMetadata(
4596
                $contentInfo,
4597
                $metadataUpdate
4598
            );
4599
        } catch (Exception $e) {
4600
            // Cleanup hanging transaction on error
4601
            $repository->rollback();
4602
            throw $e;
4603
        }
4604
4605
        // Rollback all changes.
4606
        $repository->rollback();
4607
4608
        // Load current remoteId
4609
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4610
        /* END: Use Case */
4611
4612
        $this->assertEquals($remoteId, $remoteIdReloaded);
4613
    }
4614
4615
    /**
4616
     * Test for the updateContentMetadata() method.
@@ 4622-4666 (lines=45) @@
4619
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4620
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4621
     */
4622
    public function testUpdateContentMetadataInTransactionWithCommit()
4623
    {
4624
        $repository = $this->getRepository();
4625
4626
        $contentId = $this->generateId('object', 12);
4627
        /* BEGIN: Use Case */
4628
        // $contentId is the ID of the "Administrator users" user group
4629
4630
        // Get the content service
4631
        $contentService = $repository->getContentService();
4632
4633
        // Load a ContentInfo object
4634
        $contentInfo = $contentService->loadContentInfo($contentId);
4635
4636
        // Store remoteId for later testing
4637
        $remoteId = $contentInfo->remoteId;
4638
4639
        // Start a transaction
4640
        $repository->beginTransaction();
4641
4642
        try {
4643
            // Get metadata update struct and change remoteId
4644
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4645
            $metadataUpdate->remoteId = md5(microtime(true));
4646
4647
            // Update the metadata of the published content object
4648
            $contentService->updateContentMetadata(
4649
                $contentInfo,
4650
                $metadataUpdate
4651
            );
4652
4653
            // Commit all changes.
4654
            $repository->commit();
4655
        } catch (Exception $e) {
4656
            // Cleanup hanging transaction on error
4657
            $repository->rollback();
4658
            throw $e;
4659
        }
4660
4661
        // Load current remoteId
4662
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4663
        /* END: Use Case */
4664
4665
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4666
    }
4667
4668
    /**
4669
     * Test for the deleteVersion() method.