Code Duplication    Length = 48-50 lines in 2 locations

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

@@ 4334-4381 (lines=48) @@
4331
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4332
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4333
     */
4334
    public function testCopyContentInTransactionWithRollback()
4335
    {
4336
        $repository = $this->getRepository();
4337
4338
        $contentId = $this->generateId('object', 11);
4339
        $locationId = $this->generateId('location', 13);
4340
        /* BEGIN: Use Case */
4341
        // $contentId is the ID of the "Members" user group in an eZ Publish
4342
        // demo installation
4343
4344
        // $locationId is the ID of the "Administrator users" group location
4345
4346
        // Get services
4347
        $contentService = $repository->getContentService();
4348
        $locationService = $repository->getLocationService();
4349
4350
        // Load content object to copy
4351
        $content = $contentService->loadContent($contentId);
4352
4353
        // Create new target location
4354
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4355
4356
        // Start a new transaction
4357
        $repository->beginTransaction();
4358
4359
        try {
4360
            // Copy content with all versions and drafts
4361
            $contentService->copyContent(
4362
                $content->contentInfo,
4363
                $locationCreate
4364
            );
4365
        } catch (Exception $e) {
4366
            // Cleanup hanging transaction on error
4367
            $repository->rollback();
4368
            throw $e;
4369
        }
4370
4371
        // Rollback all changes
4372
        $repository->rollback();
4373
4374
        // This array will only contain a single admin user object
4375
        $locations = $locationService->loadLocationChildren(
4376
            $locationService->loadLocation($locationId)
4377
        )->locations;
4378
        /* END: Use Case */
4379
4380
        $this->assertEquals(1, count($locations));
4381
    }
4382
4383
    /**
4384
     * Test for the copyContent() method.
@@ 4392-4441 (lines=50) @@
4389
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocationChildren
4390
     * @depend(s) eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
4391
     */
4392
    public function testCopyContentInTransactionWithCommit()
4393
    {
4394
        $repository = $this->getRepository();
4395
4396
        $contentId = $this->generateId('object', 11);
4397
        $locationId = $this->generateId('location', 13);
4398
        /* BEGIN: Use Case */
4399
        // $contentId is the ID of the "Members" user group in an eZ Publish
4400
        // demo installation
4401
4402
        // $locationId is the ID of the "Administrator users" group location
4403
4404
        // Get services
4405
        $contentService = $repository->getContentService();
4406
        $locationService = $repository->getLocationService();
4407
4408
        // Load content object to copy
4409
        $content = $contentService->loadContent($contentId);
4410
4411
        // Create new target location
4412
        $locationCreate = $locationService->newLocationCreateStruct($locationId);
4413
4414
        // Start a new transaction
4415
        $repository->beginTransaction();
4416
4417
        try {
4418
            // Copy content with all versions and drafts
4419
            $contentCopied = $contentService->copyContent(
4420
                $content->contentInfo,
4421
                $locationCreate
4422
            );
4423
4424
            // Commit all changes
4425
            $repository->commit();
4426
        } catch (Exception $e) {
4427
            // Cleanup hanging transaction on error
4428
            $repository->rollback();
4429
            throw $e;
4430
        }
4431
4432
        $this->refreshSearch($repository);
4433
4434
        // This will contain the admin user and the new child location
4435
        $locations = $locationService->loadLocationChildren(
4436
            $locationService->loadLocation($locationId)
4437
        )->locations;
4438
        /* END: Use Case */
4439
4440
        $this->assertEquals(2, count($locations));
4441
    }
4442
4443
    /**
4444
     */