Code Duplication    Length = 42-50 lines in 2 locations

eZ/Publish/API/Repository/Tests/Values/User/Limitation/NewSectionLimitationTest.php 1 location

@@ 82-123 (lines=42) @@
79
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\NewSectionLimitation
80
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
81
     */
82
    public function testNewSectionLimitationForbid()
83
    {
84
        $repository = $this->getRepository();
85
86
        $contentId = $this->generateId('content', 58);
87
        $sectionId = $this->generateId('section', 6);
88
        $otherSectionId = $this->generateId('section', 1);
89
        /* BEGIN: Use Case */
90
        $user = $this->createUserVersion1();
91
92
        $roleService = $repository->getRoleService();
93
94
        $policyCreate = $roleService->newPolicyCreateStruct('section', 'assign');
95
        $policyCreate->addLimitation(
96
            new NewSectionLimitation(
97
                ['limitationValues' => [$sectionId]]
98
            )
99
        );
100
101
        $role = $roleService->addPolicy(
102
            $roleService->loadRoleByIdentifier('Editor'),
103
            $policyCreate
104
        );
105
        $role = $roleService->addPolicy(
106
            $role,
107
            $roleService->newPolicyCreateStruct('section', 'view')
108
        );
109
110
        $roleService->assignRoleToUser($role, $user);
111
112
        $repository->setCurrentUser($user);
113
114
        $contentService = $repository->getContentService();
115
        $contentInfo = $contentService->loadContentInfo($contentId);
116
117
        $sectionService = $repository->getSectionService();
118
        $sectionService->assignSection(
119
            $contentInfo,
120
            $sectionService->loadSection($otherSectionId)
121
        );
122
        /* END: Use Case */
123
    }
124
}
125

eZ/Publish/API/Repository/Tests/Values/User/Limitation/ParentUserGroupLimitationTest.php 1 location

@@ 92-141 (lines=50) @@
89
     * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation
90
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
91
     */
92
    public function testParentUserGroupLimitationForbid()
93
    {
94
        $repository = $this->getRepository();
95
        $userService = $repository->getUserService();
96
97
        $parentUserGroupId = $this->generateId('location', 4);
98
        /* BEGIN: Use Case */
99
        $user = $this->createUserVersion1();
100
101
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB');
102
        $userGroupCreate->setField('name', 'Shared wiki');
103
104
        $userGroup = $userService->createUserGroup(
105
            $userGroupCreate,
106
            $userService->loadUserGroup(
107
                $parentUserGroupId
108
            )
109
        );
110
111
        // Assign only example user to new group
112
        $userService->assignUserToUserGroup($user, $userGroup);
113
114
        $roleService = $repository->getRoleService();
115
116
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
117
        $policyCreate->addLimitation(
118
            new ParentUserGroupLimitation(
119
                [
120
                    'limitationValues' => [true],
121
                ]
122
            )
123
        );
124
125
        $role = $roleService->addPolicy(
126
            $roleService->loadRoleByIdentifier('Editor'),
127
            $policyCreate
128
        );
129
130
        $role = $roleService->addPolicy(
131
            $role,
132
            $roleService->newPolicyCreateStruct('content', 'read')
133
        );
134
135
        $roleService->assignRoleToUserGroup($role, $userGroup);
136
137
        $repository->setCurrentUser($user);
138
139
        $this->createWikiPageDraft();
140
        /* END: Use Case */
141
    }
142
}
143