Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4465-4509 (lines=45) @@
4462
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4463
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4464
     */
4465
    public function testUpdateContentMetadataInTransactionWithRollback()
4466
    {
4467
        $repository = $this->getRepository();
4468
4469
        $contentId = $this->generateId('object', 12);
4470
        /* BEGIN: Use Case */
4471
        // $contentId is the ID of the "Administrator users" user group
4472
4473
        // Get the content service
4474
        $contentService = $repository->getContentService();
4475
4476
        // Load a ContentInfo object
4477
        $contentInfo = $contentService->loadContentInfo($contentId);
4478
4479
        // Store remoteId for later testing
4480
        $remoteId = $contentInfo->remoteId;
4481
4482
        // Start a transaction
4483
        $repository->beginTransaction();
4484
4485
        try {
4486
            // Get metadata update struct and change remoteId
4487
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4488
            $metadataUpdate->remoteId = md5(microtime(true));
4489
4490
            // Update the metadata of the published content object
4491
            $contentService->updateContentMetadata(
4492
                $contentInfo,
4493
                $metadataUpdate
4494
            );
4495
        } catch (Exception $e) {
4496
            // Cleanup hanging transaction on error
4497
            $repository->rollback();
4498
            throw $e;
4499
        }
4500
4501
        // Rollback all changes.
4502
        $repository->rollback();
4503
4504
        // Load current remoteId
4505
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4506
        /* END: Use Case */
4507
4508
        $this->assertEquals($remoteId, $remoteIdReloaded);
4509
    }
4510
4511
    /**
4512
     * Test for the updateContentMetadata() method.
@@ 4518-4562 (lines=45) @@
4515
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4516
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4517
     */
4518
    public function testUpdateContentMetadataInTransactionWithCommit()
4519
    {
4520
        $repository = $this->getRepository();
4521
4522
        $contentId = $this->generateId('object', 12);
4523
        /* BEGIN: Use Case */
4524
        // $contentId is the ID of the "Administrator users" user group
4525
4526
        // Get the content service
4527
        $contentService = $repository->getContentService();
4528
4529
        // Load a ContentInfo object
4530
        $contentInfo = $contentService->loadContentInfo($contentId);
4531
4532
        // Store remoteId for later testing
4533
        $remoteId = $contentInfo->remoteId;
4534
4535
        // Start a transaction
4536
        $repository->beginTransaction();
4537
4538
        try {
4539
            // Get metadata update struct and change remoteId
4540
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4541
            $metadataUpdate->remoteId = md5(microtime(true));
4542
4543
            // Update the metadata of the published content object
4544
            $contentService->updateContentMetadata(
4545
                $contentInfo,
4546
                $metadataUpdate
4547
            );
4548
4549
            // Commit all changes.
4550
            $repository->commit();
4551
        } catch (Exception $e) {
4552
            // Cleanup hanging transaction on error
4553
            $repository->rollback();
4554
            throw $e;
4555
        }
4556
4557
        // Load current remoteId
4558
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4559
        /* END: Use Case */
4560
4561
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4562
    }
4563
4564
    /**
4565
     * Test for the deleteVersion() method.