Code Duplication    Length = 48-50 lines in 2 locations

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

@@ 4399-4446 (lines=48) @@
4396
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4397
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4398
     */
4399
    public function testCopyContentInTransactionWithRollback()
4400
    {
4401
        $repository = $this->getRepository();
4402
4403
        $contentId = $this->generateId('object', 11);
4404
        $locationId = $this->generateId('location', 13);
4405
        /* BEGIN: Use Case */
4406
        // $contentId is the ID of the "Members" user group in an eZ Publish
4407
        // demo installation
4408
4409
        // $locationId is the ID of the "Administrator users" group location
4410
4411
        // Get services
4412
        $contentService = $repository->getContentService();
4413
        $locationService = $repository->getLocationService();
4414
4415
        // Load content object to copy
4416
        $content = $contentService->loadContent($contentId);
4417
4418
        // Create new target location
4419
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4420
4421
        // Start a new transaction
4422
        $repository->beginTransaction();
4423
4424
        try {
4425
            // Copy content with all versions and drafts
4426
            $contentService->copyContent(
4427
                $content->contentInfo,
4428
                $locationCreate
4429
            );
4430
        } catch (Exception $e) {
4431
            // Cleanup hanging transaction on error
4432
            $repository->rollback();
4433
            throw $e;
4434
        }
4435
4436
        // Rollback all changes
4437
        $repository->rollback();
4438
4439
        // This array will only contain a single admin user object
4440
        $locations = $locationService->loadLocationChildren(
4441
            $locationService->loadLocation($locationId)
4442
        )->locations;
4443
        /* END: Use Case */
4444
4445
        $this->assertEquals(1, count($locations));
4446
    }
4447
4448
    /**
4449
     * Test for the copyContent() method.
@@ 4457-4506 (lines=50) @@
4454
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4455
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4456
     */
4457
    public function testCopyContentInTransactionWithCommit()
4458
    {
4459
        $repository = $this->getRepository();
4460
4461
        $contentId = $this->generateId('object', 11);
4462
        $locationId = $this->generateId('location', 13);
4463
        /* BEGIN: Use Case */
4464
        // $contentId is the ID of the "Members" user group in an eZ Publish
4465
        // demo installation
4466
4467
        // $locationId is the ID of the "Administrator users" group location
4468
4469
        // Get services
4470
        $contentService = $repository->getContentService();
4471
        $locationService = $repository->getLocationService();
4472
4473
        // Load content object to copy
4474
        $content = $contentService->loadContent($contentId);
4475
4476
        // Create new target location
4477
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4478
4479
        // Start a new transaction
4480
        $repository->beginTransaction();
4481
4482
        try {
4483
            // Copy content with all versions and drafts
4484
            $contentCopied = $contentService->copyContent(
4485
                $content->contentInfo,
4486
                $locationCreate
4487
            );
4488
4489
            // Commit all changes
4490
            $repository->commit();
4491
        } catch (Exception $e) {
4492
            // Cleanup hanging transaction on error
4493
            $repository->rollback();
4494
            throw $e;
4495
        }
4496
4497
        $this->refreshSearch($repository);
4498
4499
        // This will contain the admin user and the new child location
4500
        $locations = $locationService->loadLocationChildren(
4501
            $locationService->loadLocation($locationId)
4502
        )->locations;
4503
        /* END: Use Case */
4504
4505
        $this->assertEquals(2, count($locations));
4506
    }
4507
4508
    /**
4509
     */