Code Duplication    Length = 50-52 lines in 2 locations

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

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

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

@@ 876-925 (lines=50) @@
873
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
874
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
875
     */
876
    public function testCanUserWithMultipleTargetsYes()
877
    {
878
        $repository = $this->getRepository();
879
880
        $imagesLocationId = $this->generateId('location', 51);
881
        $filesLocationId = $this->generateId('location', 52);
882
883
        /* BEGIN: Use Case */
884
        // $imagesLocationId contains the ID of the "Images" location
885
        // $filesLocationId contains the ID of the "Files" location
886
887
        $user = $this->createUserVersion1();
888
889
        // Set created user as current user
890
        $repository->setCurrentUser($user);
891
892
        $contentTypeService = $repository->getContentTypeService();
893
894
        $contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
895
896
        $contentService = $repository->getContentService();
897
898
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
899
        $contentCreateStruct->setField('name', 'My multipurpose folder');
900
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
901
        $contentCreateStruct->alwaysAvailable = true;
902
903
        $locationService = $repository->getLocationService();
904
        $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId);
905
        $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId);
906
        $locationCreateStructs = [$locationCreateStruct1, $locationCreateStruct2];
907
908
        // This call will return true
909
        $canUser = $repository->canUser(
910
            'content',
911
            'create',
912
            $contentCreateStruct,
913
            $locationCreateStructs
914
        );
915
916
        // Performing an action having necessary permissions will succeed
917
        $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs);
918
        /* END: Use Case */
919
920
        $this->assertTrue($canUser);
921
        $this->assertEquals(
922
            'My multipurpose folder',
923
            $contentDraft->getFieldValue('name')->text
924
        );
925
    }
926
927
    /**
928
     * Test for the canUser() method.