Code Duplication    Length = 45-45 lines in 2 locations

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

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