Code Duplication    Length = 42-42 lines in 2 locations

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

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