Code Duplication    Length = 50-52 lines in 2 locations

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

@@ 859-908 (lines=50) @@
856
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
857
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
858
     */
859
    public function testCanUserWithMultipleTargetsYes()
860
    {
861
        $repository = $this->getRepository();
862
863
        $imagesLocationId = $this->generateId('location', 51);
864
        $filesLocationId = $this->generateId('location', 52);
865
866
        /* BEGIN: Use Case */
867
        // $imagesLocationId contains the ID of the "Images" location
868
        // $filesLocationId contains the ID of the "Files" location
869
870
        $user = $this->createUserVersion1();
871
872
        // Set created user as current user
873
        $repository->setCurrentUser($user);
874
875
        $contentTypeService = $repository->getContentTypeService();
876
877
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
878
879
        $contentService = $repository->getContentService();
880
881
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
882
        $contentCreateStruct->setField('name', 'My multipurpose folder');
883
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
884
        $contentCreateStruct->alwaysAvailable = true;
885
886
        $locationService = $repository->getLocationService();
887
        $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId);
888
        $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId);
889
        $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2);
890
891
        // This call will return true
892
        $canUser = $repository->canUser(
893
            'content',
894
            'create',
895
            $contentCreateStruct,
896
            $locationCreateStructs
897
        );
898
899
        // Performing an action having necessary permissions will succeed
900
        $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs);
901
        /* END: Use Case */
902
903
        $this->assertTrue($canUser);
904
        $this->assertEquals(
905
            'My multipurpose folder',
906
            $contentDraft->getFieldValue('name')->text
907
        );
908
    }
909
910
    /**
911
     * Test for the canUser() method.

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

@@ 587-638 (lines=52) @@
584
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
585
     * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited
586
     */
587
    public function testCanUserWithMultipleTargetsYes()
588
    {
589
        $repository = $this->getRepository();
590
591
        $imagesLocationId = $this->generateId('location', 51);
592
        $filesLocationId = $this->generateId('location', 52);
593
594
        /* BEGIN: Use Case */
595
        // $imagesLocationId contains the ID of the "Images" location
596
        // $filesLocationId contains the ID of the "Files" location
597
598
        $user = $this->createUserVersion1();
599
600
        $permissionResolver = $repository->getPermissionResolver();
601
602
        // Set created user as current user reference
603
        $permissionResolver->setCurrentUserReference($user);
604
605
        $contentTypeService = $repository->getContentTypeService();
606
607
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
608
609
        $contentService = $repository->getContentService();
610
611
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
612
        $contentCreateStruct->setField('name', 'My multipurpose folder');
613
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
614
        $contentCreateStruct->alwaysAvailable = true;
615
616
        $locationService = $repository->getLocationService();
617
        $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId);
618
        $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId);
619
        $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2);
620
621
        // This call will return true
622
        $canUser = $permissionResolver->canUser(
623
            'content',
624
            'create',
625
            $contentCreateStruct,
626
            $locationCreateStructs
627
        );
628
629
        // Performing an action having necessary permissions will succeed
630
        $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs);
631
        /* END: Use Case */
632
633
        $this->assertTrue($canUser);
634
        $this->assertEquals(
635
            'My multipurpose folder',
636
            $contentDraft->getFieldValue('name')->text
637
        );
638
    }
639
640
    /**
641
     * Test for the canUser() method.