Code Duplication    Length = 148-149 lines in 2 locations

eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserGroupRoleAssignmentTest.php 1 location

@@ 18-165 (lines=148) @@
15
use eZ\Publish\Core\Repository\Values\User;
16
use eZ\Publish\Core\REST\Server\Values;
17
18
class RestUserGroupRoleAssignmentTest extends ValueObjectVisitorBaseTest
19
{
20
    /**
21
     * Test the RestUserGroupRoleAssignment visitor.
22
     *
23
     * @return string
24
     */
25
    public function testVisit()
26
    {
27
        $visitor = $this->getVisitor();
28
        $generator = $this->getGenerator();
29
30
        $generator->startDocument(null);
31
32
        $userGroupRoleAssignment = new Values\RestUserGroupRoleAssignment(
33
            new User\UserGroupRoleAssignment(
34
                array(
35
                    'role' => new User\Role(
36
                        array(
37
                            'id' => 42,
38
                            'identifier' => 'some-role',
39
                        )
40
                    ),
41
                )
42
            ),
43
            '/1/5/14'
44
        );
45
46
        $this->addRouteExpectation(
47
            'ezpublish_rest_loadRoleAssignmentForUserGroup',
48
            array(
49
                'groupPath' => '1/5/14',
50
                'roleId' => $userGroupRoleAssignment->roleAssignment->role->id,
51
            ),
52
            "/user/groups/1/5/14/roles/{$userGroupRoleAssignment->roleAssignment->role->id}"
53
        );
54
        $this->setVisitValueObjectExpectations([
55
            new Values\ResourceRouteReference('ezpublish_rest_loadRole', ['roleId' => $userGroupRoleAssignment->roleAssignment->role->id]),
56
        ]);
57
58
        $visitor->visit(
59
            $this->getVisitorMock(),
60
            $generator,
61
            $userGroupRoleAssignment
62
        );
63
64
        $result = $generator->endDocument(null);
65
66
        $this->assertNotNull($result);
67
68
        return $result;
69
    }
70
71
    /**
72
     * Test if result contains RoleAssignment element.
73
     *
74
     * @param string $result
75
     *
76
     * @depends testVisit
77
     */
78
    public function testResultContainsRoleAssignmentElement($result)
79
    {
80
        $this->assertXMLTag(
81
            array(
82
                'tag' => 'RoleAssignment',
83
                'children' => array(
84
                    'count' => 1,
85
                ),
86
            ),
87
            $result,
88
            'Invalid <RoleAssignment> element.',
89
            false
90
        );
91
    }
92
93
    /**
94
     * Test if result contains RoleAssignment element attributes.
95
     *
96
     * @param string $result
97
     *
98
     * @depends testVisit
99
     */
100
    public function testResultContainsRoleAssignmentAttributes($result)
101
    {
102
        $this->assertXMLTag(
103
            array(
104
                'tag' => 'RoleAssignment',
105
                'attributes' => array(
106
                    'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
107
                ),
108
            ),
109
            $result,
110
            'Invalid <RoleAssignment> attributes.',
111
            false
112
        );
113
    }
114
115
    /**
116
     * Test if result contains Role element.
117
     *
118
     * @param string $result
119
     *
120
     * @depends testVisit
121
     */
122
    public function testResultContainsRoleElement($result)
123
    {
124
        $this->assertXMLTag(
125
            array(
126
                'tag' => 'Role',
127
            ),
128
            $result,
129
            'Invalid <Role> element.',
130
            false
131
        );
132
    }
133
134
    /**
135
     * Test if result contains Role element attributes.
136
     *
137
     * @param string $result
138
     *
139
     * @depends testVisit
140
     */
141
    public function testResultContainsRoleAttributes($result)
142
    {
143
        $this->assertXMLTag(
144
            array(
145
                'tag' => 'Role',
146
                'attributes' => array(
147
                    'media-type' => 'application/vnd.ez.api.Role+xml',
148
                ),
149
            ),
150
            $result,
151
            'Invalid <Role> attributes.',
152
            false
153
        );
154
    }
155
156
    /**
157
     * Get the RestUserGroupRoleAssignment visitor.
158
     *
159
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserGroupRoleAssignment
160
     */
161
    protected function internalGetVisitor()
162
    {
163
        return new ValueObjectVisitor\RestUserGroupRoleAssignment();
164
    }
165
}
166

eZ/Publish/Core/REST/Server/Tests/Output/ValueObjectVisitor/RestUserRoleAssignmentTest.php 1 location

@@ 19-167 (lines=149) @@
16
use eZ\Publish\Core\REST\Server\Values;
17
use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
18
19
class RestUserRoleAssignmentTest extends ValueObjectVisitorBaseTest
20
{
21
    /**
22
     * Test the RestUserRoleAssignment visitor.
23
     *
24
     * @return string
25
     */
26
    public function testVisit()
27
    {
28
        $visitor = $this->getVisitor();
29
        $generator = $this->getGenerator();
30
31
        $generator->startDocument(null);
32
33
        $userRoleAssignment = new Values\RestUserRoleAssignment(
34
            new User\UserRoleAssignment(
35
                array(
36
                    'role' => new User\Role(
37
                        array(
38
                            'id' => 42,
39
                            'identifier' => 'some-role',
40
                        )
41
                    ),
42
                )
43
            ),
44
            14
45
        );
46
47
        $this->addRouteExpectation(
48
            'ezpublish_rest_loadRoleAssignmentForUser',
49
            array(
50
                'userId' => $userRoleAssignment->id,
51
                'roleId' => $userRoleAssignment->roleAssignment->role->id,
52
            ),
53
            "/user/users/{$userRoleAssignment->id}/roles/{$userRoleAssignment->roleAssignment->role->id}"
54
        );
55
56
        $this->setVisitValueObjectExpectations([
57
            new ResourceRouteReference('ezpublish_rest_loadRole', ['roleId' => $userRoleAssignment->roleAssignment->role->id]),
58
        ]);
59
60
        $visitor->visit(
61
            $this->getVisitorMock(),
62
            $generator,
63
            $userRoleAssignment
64
        );
65
66
        $result = $generator->endDocument(null);
67
68
        $this->assertNotNull($result);
69
70
        return $result;
71
    }
72
73
    /**
74
     * Test if result contains RoleAssignment element.
75
     *
76
     * @param string $result
77
     *
78
     * @depends testVisit
79
     */
80
    public function testResultContainsRoleAssignmentElement($result)
81
    {
82
        $this->assertXMLTag(
83
            array(
84
                'tag' => 'RoleAssignment',
85
                'children' => array(
86
                    'count' => 1,
87
                ),
88
            ),
89
            $result,
90
            'Invalid <RoleAssignment> element.',
91
            false
92
        );
93
    }
94
95
    /**
96
     * Test if result contains RoleAssignment element attributes.
97
     *
98
     * @param string $result
99
     *
100
     * @depends testVisit
101
     */
102
    public function testResultContainsRoleAssignmentAttributes($result)
103
    {
104
        $this->assertXMLTag(
105
            array(
106
                'tag' => 'RoleAssignment',
107
                'attributes' => array(
108
                    'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
109
                ),
110
            ),
111
            $result,
112
            'Invalid <RoleAssignment> attributes.',
113
            false
114
        );
115
    }
116
117
    /**
118
     * Test if result contains Role element.
119
     *
120
     * @param string $result
121
     *
122
     * @depends testVisit
123
     */
124
    public function testResultContainsRoleElement($result)
125
    {
126
        $this->assertXMLTag(
127
            array(
128
                'tag' => 'Role',
129
            ),
130
            $result,
131
            'Invalid <Role> element.',
132
            false
133
        );
134
    }
135
136
    /**
137
     * Test if result contains Role element attributes.
138
     *
139
     * @param string $result
140
     *
141
     * @depends testVisit
142
     */
143
    public function testResultContainsRoleAttributes($result)
144
    {
145
        $this->assertXMLTag(
146
            array(
147
                'tag' => 'Role',
148
                'attributes' => array(
149
                    'media-type' => 'application/vnd.ez.api.Role+xml',
150
                ),
151
            ),
152
            $result,
153
            'Invalid <Role> attributes.',
154
            false
155
        );
156
    }
157
158
    /**
159
     * Get the UserRoleAssignment visitor.
160
     *
161
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserRoleAssignment
162
     */
163
    protected function internalGetVisitor()
164
    {
165
        return new ValueObjectVisitor\RestUserRoleAssignment();
166
    }
167
}
168