Code Duplication    Length = 45-45 lines in 2 locations

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

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