Code Duplication    Length = 49-51 lines in 2 locations

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.

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

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