Code Duplication    Length = 45-45 lines in 2 locations

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

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