Code Duplication    Length = 48-50 lines in 2 locations

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

@@ 4539-4586 (lines=48) @@
4536
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4537
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4538
     */
4539
    public function testCopyContentInTransactionWithRollback()
4540
    {
4541
        $repository = $this->getRepository();
4542
4543
        $contentId = $this->generateId('object', 11);
4544
        $locationId = $this->generateId('location', 13);
4545
        /* BEGIN: Use Case */
4546
        // $contentId is the ID of the "Members" user group in an eZ Publish
4547
        // demo installation
4548
4549
        // $locationId is the ID of the "Administrator users" group location
4550
4551
        // Get services
4552
        $contentService = $repository->getContentService();
4553
        $locationService = $repository->getLocationService();
4554
4555
        // Load content object to copy
4556
        $content = $contentService->loadContent($contentId);
4557
4558
        // Create new target location
4559
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4560
4561
        // Start a new transaction
4562
        $repository->beginTransaction();
4563
4564
        try {
4565
            // Copy content with all versions and drafts
4566
            $contentService->copyContent(
4567
                $content->contentInfo,
4568
                $locationCreate
4569
            );
4570
        } catch (Exception $e) {
4571
            // Cleanup hanging transaction on error
4572
            $repository->rollback();
4573
            throw $e;
4574
        }
4575
4576
        // Rollback all changes
4577
        $repository->rollback();
4578
4579
        // This array will only contain a single admin user object
4580
        $locations = $locationService->loadLocationChildren(
4581
            $locationService->loadLocation($locationId)
4582
        )->locations;
4583
        /* END: Use Case */
4584
4585
        $this->assertEquals(1, count($locations));
4586
    }
4587
4588
    /**
4589
     * Test for the copyContent() method.
@@ 4597-4646 (lines=50) @@
4594
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4595
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4596
     */
4597
    public function testCopyContentInTransactionWithCommit()
4598
    {
4599
        $repository = $this->getRepository();
4600
4601
        $contentId = $this->generateId('object', 11);
4602
        $locationId = $this->generateId('location', 13);
4603
        /* BEGIN: Use Case */
4604
        // $contentId is the ID of the "Members" user group in an eZ Publish
4605
        // demo installation
4606
4607
        // $locationId is the ID of the "Administrator users" group location
4608
4609
        // Get services
4610
        $contentService = $repository->getContentService();
4611
        $locationService = $repository->getLocationService();
4612
4613
        // Load content object to copy
4614
        $content = $contentService->loadContent($contentId);
4615
4616
        // Create new target location
4617
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4618
4619
        // Start a new transaction
4620
        $repository->beginTransaction();
4621
4622
        try {
4623
            // Copy content with all versions and drafts
4624
            $contentCopied = $contentService->copyContent(
4625
                $content->contentInfo,
4626
                $locationCreate
4627
            );
4628
4629
            // Commit all changes
4630
            $repository->commit();
4631
        } catch (Exception $e) {
4632
            // Cleanup hanging transaction on error
4633
            $repository->rollback();
4634
            throw $e;
4635
        }
4636
4637
        $this->refreshSearch($repository);
4638
4639
        // This will contain the admin user and the new child location
4640
        $locations = $locationService->loadLocationChildren(
4641
            $locationService->loadLocation($locationId)
4642
        )->locations;
4643
        /* END: Use Case */
4644
4645
        $this->assertEquals(2, count($locations));
4646
    }
4647
4648
    public function testURLAliasesCreatedForNewContent()
4649
    {