Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a...6abe82 )
by
unknown
79:54 queued 33:48
created

testResultContainsRoleElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing a test 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\Core\REST\Server\Tests\Output\ValueObjectVisitor;
12
13
use eZ\Publish\Core\REST\Common\Tests\Output\ValueObjectVisitorBaseTest;
14
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
15
use eZ\Publish\Core\Repository\Values\User;
16
use eZ\Publish\Core\REST\Server\Values;
17
18 View Code Duplication
class RestUserRoleAssignmentTest extends ValueObjectVisitorBaseTest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * Test the RestUserRoleAssignment 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
        $userRoleAssignment = new Values\RestUserRoleAssignment(
33
            new User\UserRoleAssignment(
34
                array(
35
                    'role' => new User\Role(
36
                        array(
37
                            'id' => 42,
38
                            'identifier' => 'some-role',
39
                        )
40
                    ),
41
                )
42
            ),
43
            14
44
        );
45
46
        $this->addRouteExpectation(
47
            'ezpublish_rest_loadRoleAssignmentForUser',
48
            array(
49
                'userId' => $userRoleAssignment->id,
50
                'roleId' => $userRoleAssignment->roleAssignment->role->id,
51
            ),
52
            "/user/users/{$userRoleAssignment->id}/roles/{$userRoleAssignment->roleAssignment->role->id}"
53
        );
54
55
        $this->addRouteExpectation(
56
            'ezpublish_rest_loadRole',
57
            array('roleId' => $userRoleAssignment->roleAssignment->role->id),
58
            "/user/roles/{$userRoleAssignment->roleAssignment->role->id}"
59
        );
60
61
        $visitor->visit(
62
            $this->getVisitorMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getVisitorMock() targeting eZ\Publish\Core\REST\Com...eTest::getVisitorMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\REST\Com...eObjectVisitor::visit() does only seem to accept object<eZ\Publish\Core\R...\Common\Output\Visitor>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
63
            $generator,
64
            $userRoleAssignment
65
        );
66
67
        $result = $generator->endDocument(null);
68
69
        $this->assertNotNull($result);
70
71
        return $result;
72
    }
73
74
    /**
75
     * Test if result contains RoleAssignment element.
76
     *
77
     * @param string $result
78
     *
79
     * @depends testVisit
80
     */
81
    public function testResultContainsRoleAssignmentElement($result)
82
    {
83
        $this->assertXMLTag(
84
            array(
85
                'tag' => 'RoleAssignment',
86
                'children' => array(
87
                    'count' => 1,
88
                ),
89
            ),
90
            $result,
91
            'Invalid <RoleAssignment> element.',
92
            false
93
        );
94
    }
95
96
    /**
97
     * Test if result contains RoleAssignment element attributes.
98
     *
99
     * @param string $result
100
     *
101
     * @depends testVisit
102
     */
103
    public function testResultContainsRoleAssignmentAttributes($result)
104
    {
105
        $this->assertXMLTag(
106
            array(
107
                'tag' => 'RoleAssignment',
108
                'attributes' => array(
109
                    'media-type' => 'application/vnd.ez.api.RoleAssignment+xml',
110
                    'href' => '/user/users/14/roles/42',
111
                ),
112
            ),
113
            $result,
114
            'Invalid <RoleAssignment> attributes.',
115
            false
116
        );
117
    }
118
119
    /**
120
     * Test if result contains Role element.
121
     *
122
     * @param string $result
123
     *
124
     * @depends testVisit
125
     */
126
    public function testResultContainsRoleElement($result)
127
    {
128
        $this->assertXMLTag(
129
            array(
130
                'tag' => 'Role',
131
            ),
132
            $result,
133
            'Invalid <Role> element.',
134
            false
135
        );
136
    }
137
138
    /**
139
     * Test if result contains Role element attributes.
140
     *
141
     * @param string $result
142
     *
143
     * @depends testVisit
144
     */
145
    public function testResultContainsRoleAttributes($result)
146
    {
147
        $this->assertXMLTag(
148
            array(
149
                'tag' => 'Role',
150
                'attributes' => array(
151
                    'media-type' => 'application/vnd.ez.api.Role+xml',
152
                    'href' => '/user/roles/42',
153
                ),
154
            ),
155
            $result,
156
            'Invalid <Role> attributes.',
157
            false
158
        );
159
    }
160
161
    /**
162
     * Get the UserRoleAssignment visitor.
163
     *
164
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserRoleAssignment
165
     */
166
    protected function internalGetVisitor()
167
    {
168
        return new ValueObjectVisitor\RestUserRoleAssignment();
169
    }
170
}
171