Code Duplication    Length = 45-45 lines in 2 locations

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

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