Code Duplication    Length = 48-50 lines in 2 locations

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

@@ 4438-4485 (lines=48) @@
4435
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4436
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4437
     */
4438
    public function testCopyContentInTransactionWithRollback()
4439
    {
4440
        $repository = $this->getRepository();
4441
4442
        $contentId = $this->generateId('object', 11);
4443
        $locationId = $this->generateId('location', 13);
4444
        /* BEGIN: Use Case */
4445
        // $contentId is the ID of the "Members" user group in an eZ Publish
4446
        // demo installation
4447
4448
        // $locationId is the ID of the "Administrator users" group location
4449
4450
        // Get services
4451
        $contentService = $repository->getContentService();
4452
        $locationService = $repository->getLocationService();
4453
4454
        // Load content object to copy
4455
        $content = $contentService->loadContent($contentId);
4456
4457
        // Create new target location
4458
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4459
4460
        // Start a new transaction
4461
        $repository->beginTransaction();
4462
4463
        try {
4464
            // Copy content with all versions and drafts
4465
            $contentService->copyContent(
4466
                $content->contentInfo,
4467
                $locationCreate
4468
            );
4469
        } catch (Exception $e) {
4470
            // Cleanup hanging transaction on error
4471
            $repository->rollback();
4472
            throw $e;
4473
        }
4474
4475
        // Rollback all changes
4476
        $repository->rollback();
4477
4478
        // This array will only contain a single admin user object
4479
        $locations = $locationService->loadLocationChildren(
4480
            $locationService->loadLocation($locationId)
4481
        )->locations;
4482
        /* END: Use Case */
4483
4484
        $this->assertEquals(1, count($locations));
4485
    }
4486
4487
    /**
4488
     * Test for the copyContent() method.
@@ 4496-4545 (lines=50) @@
4493
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4494
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4495
     */
4496
    public function testCopyContentInTransactionWithCommit()
4497
    {
4498
        $repository = $this->getRepository();
4499
4500
        $contentId = $this->generateId('object', 11);
4501
        $locationId = $this->generateId('location', 13);
4502
        /* BEGIN: Use Case */
4503
        // $contentId is the ID of the "Members" user group in an eZ Publish
4504
        // demo installation
4505
4506
        // $locationId is the ID of the "Administrator users" group location
4507
4508
        // Get services
4509
        $contentService = $repository->getContentService();
4510
        $locationService = $repository->getLocationService();
4511
4512
        // Load content object to copy
4513
        $content = $contentService->loadContent($contentId);
4514
4515
        // Create new target location
4516
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4517
4518
        // Start a new transaction
4519
        $repository->beginTransaction();
4520
4521
        try {
4522
            // Copy content with all versions and drafts
4523
            $contentCopied = $contentService->copyContent(
4524
                $content->contentInfo,
4525
                $locationCreate
4526
            );
4527
4528
            // Commit all changes
4529
            $repository->commit();
4530
        } catch (Exception $e) {
4531
            // Cleanup hanging transaction on error
4532
            $repository->rollback();
4533
            throw $e;
4534
        }
4535
4536
        $this->refreshSearch($repository);
4537
4538
        // This will contain the admin user and the new child location
4539
        $locations = $locationService->loadLocationChildren(
4540
            $locationService->loadLocation($locationId)
4541
        )->locations;
4542
        /* END: Use Case */
4543
4544
        $this->assertEquals(2, count($locations));
4545
    }
4546
4547
    public function testURLAliasesCreatedForNewContent()
4548
    {