Code Duplication    Length = 28-40 lines in 2 locations

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

@@ 92-119 (lines=28) @@
89
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
90
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection
91
     */
92
    public function testUpdateSectionThrowsUnauthorizedException()
93
    {
94
        $repository = $this->getRepository();
95
96
        $standardSectionId = $this->generateId('section', 1);
97
        $anonymousUserId = $this->generateId('user', 10);
98
        /* BEGIN: Use Case */
99
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
100
        // Publish demo installation.
101
        // $standardSectionId is the ID of the "Standard" section in a eZ
102
        // Publish demo installation.
103
104
        $userService = $repository->getUserService();
105
        $sectionService = $repository->getSectionService();
106
107
        $section = $sectionService->loadSection($standardSectionId);
108
109
        $sectionUpdate = $sectionService->newSectionUpdateStruct();
110
        $sectionUpdate->name = 'New section name';
111
        $sectionUpdate->identifier = 'newUniqueKey';
112
113
        // Set anonymous user
114
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
115
116
        // This call will fail with a "UnauthorizedException"
117
        $sectionService->updateSection($section, $sectionUpdate);
118
        /* END: Use Case */
119
    }
120
121
    /**
122
     * Test for the loadSections() method.

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

@@ 67-106 (lines=40) @@
64
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
65
     * @depends eZ\Publish\API\Repository\Tests\ContentTypeServiceTest::testUpdateContentTypeGroup
66
     */
67
    public function testUpdateContentTypeGroupThrowsUnauthorizedException()
68
    {
69
        $repository = $this->getRepository();
70
71
        $modifierId = $this->generateId('user', 42);
72
        $anonymousUserId = $this->generateId('user', 10);
73
        /* BEGIN: Use Case */
74
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
75
        // Publish demo installation.
76
        $userService = $repository->getUserService();
77
        $contentTypeService = $repository->getContentTypeService();
78
79
        $group = $contentTypeService->loadContentTypeGroupByIdentifier('Setup');
80
81
        $groupUpdate = $contentTypeService->newContentTypeGroupUpdateStruct();
82
83
        $groupUpdate->identifier = 'Teardown';
84
        // $modifierId is the ID of a random user
85
        $groupUpdate->modifierId = $modifierId;
86
        $groupUpdate->modificationDate = $this->createDateTime();
87
        /* @todo uncomment when support for multilingual names and descriptions is added EZP-24776
88
        $groupUpdate->mainLanguageCode = 'eng-GB';
89
90
        $groupUpdate->names = array(
91
            'eng-GB' => 'A name',
92
            'eng-US' => 'A name',
93
        );
94
        $groupUpdate->descriptions = array(
95
            'eng-GB' => 'A description',
96
            'eng-US' => 'A description',
97
        );
98
        */
99
100
        // Set anonymous user
101
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
102
103
        // This call will fail with a "UnauthorizedException"
104
        $contentTypeService->updateContentTypeGroup($group, $groupUpdate);
105
        /* END: Use Case */
106
    }
107
108
    /**
109
     * Test for the deleteContentTypeGroup() method.