Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4511-4555 (lines=45) @@
4508
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4509
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4510
     */
4511
    public function testUpdateContentMetadataInTransactionWithRollback()
4512
    {
4513
        $repository = $this->getRepository();
4514
4515
        $contentId = $this->generateId('object', 12);
4516
        /* BEGIN: Use Case */
4517
        // $contentId is the ID of the "Administrator users" user group
4518
4519
        // Get the content service
4520
        $contentService = $repository->getContentService();
4521
4522
        // Load a ContentInfo object
4523
        $contentInfo = $contentService->loadContentInfo($contentId);
4524
4525
        // Store remoteId for later testing
4526
        $remoteId = $contentInfo->remoteId;
4527
4528
        // Start a transaction
4529
        $repository->beginTransaction();
4530
4531
        try {
4532
            // Get metadata update struct and change remoteId
4533
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4534
            $metadataUpdate->remoteId = md5(microtime(true));
4535
4536
            // Update the metadata of the published content object
4537
            $contentService->updateContentMetadata(
4538
                $contentInfo,
4539
                $metadataUpdate
4540
            );
4541
        } catch (Exception $e) {
4542
            // Cleanup hanging transaction on error
4543
            $repository->rollback();
4544
            throw $e;
4545
        }
4546
4547
        // Rollback all changes.
4548
        $repository->rollback();
4549
4550
        // Load current remoteId
4551
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4552
        /* END: Use Case */
4553
4554
        $this->assertEquals($remoteId, $remoteIdReloaded);
4555
    }
4556
4557
    /**
4558
     * Test for the updateContentMetadata() method.
@@ 4564-4608 (lines=45) @@
4561
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4562
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4563
     */
4564
    public function testUpdateContentMetadataInTransactionWithCommit()
4565
    {
4566
        $repository = $this->getRepository();
4567
4568
        $contentId = $this->generateId('object', 12);
4569
        /* BEGIN: Use Case */
4570
        // $contentId is the ID of the "Administrator users" user group
4571
4572
        // Get the content service
4573
        $contentService = $repository->getContentService();
4574
4575
        // Load a ContentInfo object
4576
        $contentInfo = $contentService->loadContentInfo($contentId);
4577
4578
        // Store remoteId for later testing
4579
        $remoteId = $contentInfo->remoteId;
4580
4581
        // Start a transaction
4582
        $repository->beginTransaction();
4583
4584
        try {
4585
            // Get metadata update struct and change remoteId
4586
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4587
            $metadataUpdate->remoteId = md5(microtime(true));
4588
4589
            // Update the metadata of the published content object
4590
            $contentService->updateContentMetadata(
4591
                $contentInfo,
4592
                $metadataUpdate
4593
            );
4594
4595
            // Commit all changes.
4596
            $repository->commit();
4597
        } catch (Exception $e) {
4598
            // Cleanup hanging transaction on error
4599
            $repository->rollback();
4600
            throw $e;
4601
        }
4602
4603
        // Load current remoteId
4604
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4605
        /* END: Use Case */
4606
4607
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4608
    }
4609
4610
    /**
4611
     * Test for the deleteVersion() method.