Code Duplication    Length = 49-51 lines in 2 locations

eZ/Publish/API/Repository/Tests/RepositoryTest.php 1 location

@@ 743-791 (lines=49) @@
740
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
741
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
742
     */
743
    public function testCanUserWithTargetYes()
744
    {
745
        $repository = $this->getRepository();
746
747
        $homeLocationId = $this->generateId('location', 2);
748
749
        /* BEGIN: Use Case */
750
        // $homeLocationId contains the ID of the "Home" location
751
752
        $user = $this->createUserVersion1();
753
754
        // Set created user as current user
755
        $repository->setCurrentUser($user);
756
757
        $contentTypeService = $repository->getContentTypeService();
758
759
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
760
761
        $contentService = $repository->getContentService();
762
763
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
764
        $contentCreateStruct->setField('title', 'My awesome forums');
765
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
766
        $contentCreateStruct->alwaysAvailable = true;
767
768
        $locationService = $repository->getLocationService();
769
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
770
771
        // This call will return true
772
        $canUser = $repository->canUser(
773
            'content',
774
            'create',
775
            $contentCreateStruct,
776
            $locationCreateStruct
777
        );
778
779
        // Performing an action having necessary permissions will succeed
780
        $contentDraft = $contentService->createContent(
781
            $contentCreateStruct,
782
            array($locationCreateStruct)
783
        );
784
        /* END: Use Case */
785
786
        $this->assertTrue($canUser);
787
        $this->assertEquals(
788
            'My awesome forums',
789
            $contentDraft->getFieldValue('title')->text
790
        );
791
    }
792
793
    /**
794
     * Test for the canUser() method.

eZ/Publish/API/Repository/Tests/PermissionResolverTest.php 1 location

@@ 467-517 (lines=51) @@
464
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
465
     * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited
466
     */
467
    public function testCanUserWithTargetYes()
468
    {
469
        $repository = $this->getRepository();
470
471
        $homeLocationId = $this->generateId('location', 2);
472
473
        /* BEGIN: Use Case */
474
        // $homeLocationId contains the ID of the "Home" location
475
476
        $user = $this->createUserVersion1();
477
478
        $permissionResolver = $repository->getPermissionResolver();
479
480
        // Set created user as current user reference
481
        $permissionResolver->setCurrentUserReference($user);
482
483
        $contentTypeService = $repository->getContentTypeService();
484
485
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
486
487
        $contentService = $repository->getContentService();
488
489
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
490
        $contentCreateStruct->setField('title', 'My awesome forums');
491
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
492
        $contentCreateStruct->alwaysAvailable = true;
493
494
        $locationService = $repository->getLocationService();
495
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
496
497
        // This call will return true
498
        $canUser = $permissionResolver->canUser(
499
            'content',
500
            'create',
501
            $contentCreateStruct,
502
            [$locationCreateStruct]
503
        );
504
505
        // Performing an action having necessary permissions will succeed
506
        $contentDraft = $contentService->createContent(
507
            $contentCreateStruct,
508
            array($locationCreateStruct)
509
        );
510
        /* END: Use Case */
511
512
        $this->assertTrue($canUser);
513
        $this->assertEquals(
514
            'My awesome forums',
515
            $contentDraft->getFieldValue('title')->text
516
        );
517
    }
518
519
    /**
520
     * Test for the canUser() method.