Code Duplication    Length = 45-45 lines in 2 locations

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

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