Code Duplication    Length = 50-52 lines in 2 locations

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.

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 = array($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.