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

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