Code Duplication    Length = 34-38 lines in 2 locations

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

@@ 82-115 (lines=34) @@
79
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentContentTypeLimitation
80
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
81
     */
82
    public function testParentContentTypeLimitationForbid()
83
    {
84
        $repository = $this->getRepository();
85
86
        $parentContentTypeId = $this->generateId('contentType', 20);
87
        $contentTypeId = $this->generateId('contentType', 33);
88
        /* BEGIN: Use Case */
89
        $user = $this->createUserVersion1();
90
91
        $roleService = $repository->getRoleService();
92
93
        $role = $roleService->loadRoleByIdentifier('Editor');
94
95
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
96
        $policyCreate->addLimitation(
97
            new ParentContentTypeLimitation(
98
                array('limitationValues' => array($parentContentTypeId))
99
            )
100
        );
101
        $policyCreate->addLimitation(
102
            new ContentTypeLimitation(
103
                array('limitationValues' => array($contentTypeId))
104
            )
105
        );
106
107
        $role = $roleService->addPolicy($role, $policyCreate);
108
109
        $roleService->assignRoleToUser($role, $user);
110
111
        $repository->setCurrentUser($user);
112
113
        $this->createWikiPageDraft();
114
        /* END: Use Case */
115
    }
116
}
117

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

@@ 33-70 (lines=38) @@
30
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ContentTypeLimitation
31
     * @see \eZ\Publish\API\Repository\Values\User\Limitation\ParentDepthLimitation
32
     */
33
    public function testParentDepthLimitationAllow()
34
    {
35
        $repository = $this->getRepository();
36
37
        $contentTypeId = $this->generateId('contentType', 22);
38
        /* BEGIN: Use Case */
39
        $user = $this->createUserVersion1();
40
41
        $roleService = $repository->getRoleService();
42
43
        $role = $roleService->loadRoleByIdentifier('Editor');
44
45
        $policyCreate = $roleService->newPolicyCreateStruct('content', 'create');
46
        $policyCreate->addLimitation(
47
            new ParentDepthLimitation(
48
                array('limitationValues' => array(2))
49
            )
50
        );
51
        $policyCreate->addLimitation(
52
            new ContentTypeLimitation(
53
                array('limitationValues' => array($contentTypeId))
54
            )
55
        );
56
57
        $role = $roleService->addPolicy($role, $policyCreate);
58
59
        $roleService->assignRoleToUser($role, $user);
60
61
        $repository->setCurrentUser($user);
62
63
        $draft = $this->createWikiPageDraft();
64
        /* END: Use Case */
65
66
        $this->assertEquals(
67
            'An awesome wiki page',
68
            $draft->getFieldValue('title')->text
69
        );
70
    }
71
72
    /**
73
     * Tests a combination of ParentDepthLimitation and ContentTypeLimitation.