Code Duplication    Length = 48-50 lines in 2 locations

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

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