Code Duplication    Length = 49-51 lines in 2 locations

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

@@ 467-517 (lines=51) @@
464
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
465
     * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited
466
     */
467
    public function testCanUserWithTargetYes()
468
    {
469
        $repository = $this->getRepository();
470
471
        $homeLocationId = $this->generateId('location', 2);
472
473
        /* BEGIN: Use Case */
474
        // $homeLocationId contains the ID of the "Home" location
475
476
        $user = $this->createUserVersion1();
477
478
        $permissionResolver = $repository->getPermissionResolver();
479
480
        // Set created user as current user reference
481
        $permissionResolver->setCurrentUserReference($user);
482
483
        $contentTypeService = $repository->getContentTypeService();
484
485
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
486
487
        $contentService = $repository->getContentService();
488
489
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
490
        $contentCreateStruct->setField('title', 'My awesome forums');
491
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
492
        $contentCreateStruct->alwaysAvailable = true;
493
494
        $locationService = $repository->getLocationService();
495
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
496
497
        // This call will return true
498
        $canUser = $permissionResolver->canUser(
499
            'content',
500
            'create',
501
            $contentCreateStruct,
502
            [$locationCreateStruct]
503
        );
504
505
        // Performing an action having necessary permissions will succeed
506
        $contentDraft = $contentService->createContent(
507
            $contentCreateStruct,
508
            array($locationCreateStruct)
509
        );
510
        /* END: Use Case */
511
512
        $this->assertTrue($canUser);
513
        $this->assertEquals(
514
            'My awesome forums',
515
            $contentDraft->getFieldValue('title')->text
516
        );
517
    }
518
519
    /**
520
     * Test for the canUser() method.

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

@@ 760-808 (lines=49) @@
757
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
758
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
759
     */
760
    public function testCanUserWithTargetYes()
761
    {
762
        $repository = $this->getRepository();
763
764
        $homeLocationId = $this->generateId('location', 2);
765
766
        /* BEGIN: Use Case */
767
        // $homeLocationId contains the ID of the "Home" location
768
769
        $user = $this->createUserVersion1();
770
771
        // Set created user as current user
772
        $repository->setCurrentUser($user);
773
774
        $contentTypeService = $repository->getContentTypeService();
775
776
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
777
778
        $contentService = $repository->getContentService();
779
780
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
781
        $contentCreateStruct->setField('title', 'My awesome forums');
782
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
783
        $contentCreateStruct->alwaysAvailable = true;
784
785
        $locationService = $repository->getLocationService();
786
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
787
788
        // This call will return true
789
        $canUser = $repository->canUser(
790
            'content',
791
            'create',
792
            $contentCreateStruct,
793
            $locationCreateStruct
794
        );
795
796
        // Performing an action having necessary permissions will succeed
797
        $contentDraft = $contentService->createContent(
798
            $contentCreateStruct,
799
            array($locationCreateStruct)
800
        );
801
        /* END: Use Case */
802
803
        $this->assertTrue($canUser);
804
        $this->assertEquals(
805
            'My awesome forums',
806
            $contentDraft->getFieldValue('title')->text
807
        );
808
    }
809
810
    /**
811
     * Test for the canUser() method.