Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a )
by
unknown
36:29
created

RestUserGroupRoleAssignmentTest::testVisit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 27

Duplication

Lines 45
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
nc 1
nop 0
dl 45
loc 45
rs 8.8571
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 RestUserGroupRoleAssignmentTest 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 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]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadRole' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        ]);
57
58
        $visitor->visit(
59
            $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...
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