Code Duplication    Length = 50-52 lines in 2 locations

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

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