Completed
Push — readme ( 4da83f...7adc69 )
by
unknown
28:00 queued 04:49
created

testParentUserGroupLimitationAllow()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 56
rs 8.9599
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * File containing the ParentUserGroupLimitationTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\API\Repository\Tests\Values\User\Limitation;
10
11
use eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation;
12
13
/**
14
 * Test case for the {@link \eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation}
15
 * class.
16
 *
17
 * @see eZ\Publish\API\Repository\Values\User\Limitation
18
 * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation
19
 * @group integration
20
 * @group limitation
21
 */
22
class ParentUserGroupLimitationTest extends BaseLimitationTest
23
{
24
    /**
25
     * Tests a ParentUserGroupLimitation.
26
     *
27
     * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation
28
     */
29
    public function testParentUserGroupLimitationAllow()
30
    {
31
        $repository = $this->getRepository();
32
        $userService = $repository->getUserService();
33
34
        $parentUserGroupId = $this->generateId('location', 4);
35
        /* BEGIN: Use Case */
36
        $user = $this->createUserVersion1();
37
38
        $userGroupCreate = $userService->newUserGroupCreateStruct('eng-GB');
39
        $userGroupCreate->setField('name', 'Shared wiki');
40
41
        $userGroup = $userService->createUserGroup(
42
            $userGroupCreate,
43
            $userService->loadUserGroup(
44
                $parentUserGroupId
45
            )
46
        );
47
48
        // Assign system user and example user to same group
49
        $userService->assignUserToUserGroup($user, $userGroup);
50
        $userService->assignUserToUserGroup($repository->getCurrentUser(), $userGroup);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
51
52
        $roleService = $repository->getRoleService();
53
54
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
55
        $policyCreate->addLimitation(
56
            new ParentUserGroupLimitation(
57
                [
58
                    'limitationValues' => [true],
59
                ]
60
            )
61
        );
62
63
        $role = $roleService->addPolicy(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\RoleService::addPolicy() has been deprecated with message: since 6.0, use {@see addPolicyByRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
64
            $roleService->loadRoleByIdentifier('Editor'),
65
            $policyCreate
66
        );
67
68
        $role = $roleService->addPolicy(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\RoleService::addPolicy() has been deprecated with message: since 6.0, use {@see addPolicyByRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
69
            $role,
70
            $roleService->newPolicyCreateStruct('content', 'read')
71
        );
72
73
        $roleService->assignRoleToUserGroup($role, $userGroup);
74
75
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
77
        $draft = $this->createWikiPageDraft();
78
        /* END: Use Case */
79
80
        $this->assertEquals(
81
            'An awesome wiki page',
82
            $draft->getFieldValue('title')->text
83
        );
84
    }
85
86
    /**
87
     * Tests a ParentUserGroupLimitation.
88
     *
89
     * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentUserGroupLimitation
90
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
91
     */
92 View Code Duplication
    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(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\RoleService::addPolicy() has been deprecated with message: since 6.0, use {@see addPolicyByRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
126
            $roleService->loadRoleByIdentifier('Editor'),
127
            $policyCreate
128
        );
129
130
        $role = $roleService->addPolicy(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\RoleService::addPolicy() has been deprecated with message: since 6.0, use {@see addPolicyByRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
131
            $role,
132
            $roleService->newPolicyCreateStruct('content', 'read')
133
        );
134
135
        $roleService->assignRoleToUserGroup($role, $userGroup);
136
137
        $repository->setCurrentUser($user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::setCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. Sets the current user to the given $user.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
138
139
        $this->createWikiPageDraft();
140
        /* END: Use Case */
141
    }
142
}
143