Completed
Push — test-EZP-26707-issearchable-fu... ( 774d65...d743e2 )
by
unknown
24:59
created

testParentDepthLimitationAllowPublish()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 37
rs 8.8571
1
<?php
2
3
/**
4
 * File containing the ParentDepthLimitationTest 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
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\API\Repository\Tests\Values\User\Limitation;
12
13
use eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation;
14
use eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation;
15
16
/**
17
 * Test case for the {@link \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation}
18
 * class.
19
 *
20
 * @see eZ\Publish\API\Repository\Values\User\Limitation
21
 * @see eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
22
 * @group integration
23
 * @group limitation
24
 */
25
class ParentDepthLimitationTest extends BaseLimitationTest
26
{
27
    /**
28
     * Tests a combination of ParentDepthLimitation and ContentTypeLimitation.
29
     *
30
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation
31
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
32
     *
33
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
34
     */
35 View Code Duplication
    public function testParentDepthLimitationForbid()
36
    {
37
        $repository = $this->getRepository();
38
39
        $contentTypeId = $this->generateId('contentType', 22);
40
        /* BEGIN: Use Case */
41
        $user = $this->createUserVersion1();
42
43
        $roleService = $repository->getRoleService();
44
45
        $role = $roleService->loadRoleByIdentifier('Editor');
46
47
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
48
        $policyCreate->addLimitation(
49
            new ParentDepthLimitation(
50
                array('limitationValues' => array(3))
51
            )
52
        );
53
        $policyCreate->addLimitation(
54
            new ContentTypeLimitation(
55
                array('limitationValues' => array($contentTypeId))
56
            )
57
        );
58
59
        $role = $roleService->addPolicy($role, $policyCreate);
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...
60
61
        $roleService->assignRoleToUser($role, $user);
62
63
        $repository->setCurrentUser($user);
64
65
        $draft = $this->createWikiPageDraft();
66
        /* END: Use Case */
67
68
        $this->assertEquals(
69
            'An awesome wiki page',
70
            $draft->getFieldValue('title')->text
71
        );
72
    }
73
74
    /**
75
     * Tests a combination of ParentDepthLimitation and ContentTypeLimitation.
76
     *
77
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation
78
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
79
     */
80
    public function testParentDepthLimitationAllow()
81
    {
82
        $repository = $this->getRepository();
83
84
        $contentTypeId = $this->generateId('contentType', 22);
85
        /* BEGIN: Use Case */
86
        $user = $this->createUserVersion1();
87
88
        $roleService = $repository->getRoleService();
89
90
        $role = $roleService->loadRoleByIdentifier('Editor');
91
92
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
93
        $policyCreate->addLimitation(
94
            new ParentDepthLimitation(
95
                array('limitationValues' => array(1, 2, 3, 4))
96
            )
97
        );
98
        $policyCreate->addLimitation(
99
            new ContentTypeLimitation(
100
                array('limitationValues' => array($contentTypeId))
101
            )
102
        );
103
104
        $role = $roleService->addPolicy($role, $policyCreate);
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...
105
106
        $roleService->assignRoleToUser($role, $user);
107
108
        $repository->setCurrentUser($user);
109
110
        $this->createWikiPageDraft();
111
        /* END: Use Case */
112
    }
113
114
    /**
115
     * Tests a combination of ParentDepthLimitation and ContentTypeLimitation.
116
     *
117
     * @depends testParentDepthLimitationAllow
118
     *
119
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation
120
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
121
     */
122
    public function testParentDepthLimitationAllowPublish()
123
    {
124
        $repository = $this->getRepository();
125
126
        $contentTypeId = $this->generateId('contentType', 22);
127
        /* BEGIN: Use Case */
128
        $user = $this->createUserVersion1();
129
130
        $roleService = $repository->getRoleService();
131
132
        $role = $roleService->loadRoleByIdentifier('Editor');
133
134
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
135
        $policyCreate->addLimitation(
136
            new ParentDepthLimitation(
137
                array('limitationValues' => array(1, 2, 3, 4))
138
            )
139
        );
140
        $policyCreate->addLimitation(
141
            new ContentTypeLimitation(
142
                array('limitationValues' => array($contentTypeId))
143
            )
144
        );
145
146
        $role = $roleService->addPolicy($role, $policyCreate);
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...
147
148
        $roleService->assignRoleToUser($role, $user);
149
150
        $repository->setCurrentUser($user);
151
152
        $draft = $this->createWikiPageDraft();
153
154
        $contentService = $repository->getContentService();
155
156
        $content = $contentService->publishVersion($draft->versionInfo);
0 ignored issues
show
Unused Code introduced by
$content is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
157
        /* END: Use Case */
158
    }
159
}
160