Code Duplication    Length = 48-50 lines in 2 locations

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

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