Code Duplication    Length = 48-50 lines in 2 locations

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

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