Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4028-4072 (lines=45) @@
4025
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4026
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4027
     */
4028
    public function testUpdateContentMetadataInTransactionWithRollback()
4029
    {
4030
        $repository = $this->getRepository();
4031
4032
        $contentId = $this->generateId('object', 12);
4033
        /* BEGIN: Use Case */
4034
        // $contentId is the ID of the "Administrator users" user group
4035
4036
        // Get the content service
4037
        $contentService = $repository->getContentService();
4038
4039
        // Load a ContentInfo object
4040
        $contentInfo = $contentService->loadContentInfo($contentId);
4041
4042
        // Store remoteId for later testing
4043
        $remoteId = $contentInfo->remoteId;
4044
4045
        // Start a transaction
4046
        $repository->beginTransaction();
4047
4048
        try {
4049
            // Get metadata update struct and change remoteId
4050
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4051
            $metadataUpdate->remoteId = md5(microtime(true));
4052
4053
            // Update the metadata of the published content object
4054
            $contentService->updateContentMetadata(
4055
                $contentInfo,
4056
                $metadataUpdate
4057
            );
4058
        } catch (Exception $e) {
4059
            // Cleanup hanging transaction on error
4060
            $repository->rollback();
4061
            throw $e;
4062
        }
4063
4064
        // Rollback all changes.
4065
        $repository->rollback();
4066
4067
        // Load current remoteId
4068
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4069
        /* END: Use Case */
4070
4071
        $this->assertEquals($remoteId, $remoteIdReloaded);
4072
    }
4073
4074
    /**
4075
     * Test for the updateContentMetadata() method.
@@ 4081-4125 (lines=45) @@
4078
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4079
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4080
     */
4081
    public function testUpdateContentMetadataInTransactionWithCommit()
4082
    {
4083
        $repository = $this->getRepository();
4084
4085
        $contentId = $this->generateId('object', 12);
4086
        /* BEGIN: Use Case */
4087
        // $contentId is the ID of the "Administrator users" user group
4088
4089
        // Get the content service
4090
        $contentService = $repository->getContentService();
4091
4092
        // Load a ContentInfo object
4093
        $contentInfo = $contentService->loadContentInfo($contentId);
4094
4095
        // Store remoteId for later testing
4096
        $remoteId = $contentInfo->remoteId;
4097
4098
        // Start a transaction
4099
        $repository->beginTransaction();
4100
4101
        try {
4102
            // Get metadata update struct and change remoteId
4103
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4104
            $metadataUpdate->remoteId = md5(microtime(true));
4105
4106
            // Update the metadata of the published content object
4107
            $contentService->updateContentMetadata(
4108
                $contentInfo,
4109
                $metadataUpdate
4110
            );
4111
4112
            // Commit all changes.
4113
            $repository->commit();
4114
        } catch (Exception $e) {
4115
            // Cleanup hanging transaction on error
4116
            $repository->rollback();
4117
            throw $e;
4118
        }
4119
4120
        // Load current remoteId
4121
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4122
        /* END: Use Case */
4123
4124
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4125
    }
4126
4127
    /**
4128
     * Test for the deleteVersion() method.