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

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