Code Duplication    Length = 49-51 lines in 2 locations

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

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