Code Duplication    Length = 48-50 lines in 2 locations

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

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