Code Duplication    Length = 49-51 lines in 2 locations

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

@@ 734-782 (lines=49) @@
731
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService
732
     * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited
733
     */
734
    public function testCanUserWithTargetYes()
735
    {
736
        $repository = $this->getRepository();
737
738
        $homeLocationId = $this->generateId('location', 2);
739
740
        /* BEGIN: Use Case */
741
        // $homeLocationId contains the ID of the "Home" location
742
743
        $user = $this->createUserVersion1();
744
745
        // Set created user as current user
746
        $repository->setCurrentUser($user);
747
748
        $contentTypeService = $repository->getContentTypeService();
749
750
        $contentType = $contentTypeService->loadContentTypeByIdentifier('forums');
751
752
        $contentService = $repository->getContentService();
753
754
        $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
755
        $contentCreateStruct->setField('title', 'My awesome forums');
756
        $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789';
757
        $contentCreateStruct->alwaysAvailable = true;
758
759
        $locationService = $repository->getLocationService();
760
        $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId);
761
762
        // This call will return true
763
        $canUser = $repository->canUser(
764
            'content',
765
            'create',
766
            $contentCreateStruct,
767
            $locationCreateStruct
768
        );
769
770
        // Performing an action having necessary permissions will succeed
771
        $contentDraft = $contentService->createContent(
772
            $contentCreateStruct,
773
            array($locationCreateStruct)
774
        );
775
        /* END: Use Case */
776
777
        $this->assertTrue($canUser);
778
        $this->assertEquals(
779
            'My awesome forums',
780
            $contentDraft->getFieldValue('title')->text
781
        );
782
    }
783
784
    /**
785
     * Test for the canUser() method.

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.