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

UserGroupRefListTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 10

Importance

Changes 0
Metric Value
dl 0
loc 128
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testUserGroupRefListMediaTypeCorrect() 0 4 1
A testFirstUserGroupMediaTypeCorrect() 0 4 1
A testSecondUserGroupMediaTypeCorrect() 0 4 1
A internalGetVisitor() 0 4 1
A testVisit() 0 60 1
A testFirstUserGroupUnassignMethodCorrect() 0 4 1
A testSecondUserGroupUnassignMethodCorrect() 0 4 1
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\Repository\Values\User\UserGroup;
15
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
16
use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
17
use eZ\Publish\Core\REST\Server\Values\UserGroupRefList;
18
use eZ\Publish\Core\REST\Server\Values\RestUserGroup;
19
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
20
use eZ\Publish\Core\Repository\Values\Content\Location;
21
22
class UserGroupRefListTest extends ValueObjectVisitorBaseTest
23
{
24
    /**
25
     * Test the UserGroupRefList visitor.
26
     *
27
     * @return \DOMDocument
28
     */
29
    public function testVisit()
30
    {
31
        $visitor = $this->getVisitor();
32
        $generator = $this->getGenerator();
33
34
        $generator->startDocument(null);
35
36
        $UserGroupRefList = new UserGroupRefList(
37
            array(
38
                new RestUserGroup(
39
                    new UserGroup(),
40
                    $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'),
41
                    new ContentInfo(),
42
                    new Location(
43
                        array(
44
                            'pathString' => '/1/5/14',
45
                            'path' => array(1, 5, 14),
46
                        )
47
                    ),
48
                    array()
49
                ),
50
                new RestUserGroup(
51
                    new UserGroup(),
52
                    $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'),
53
                    new ContentInfo(),
54
                    new Location(
55
                        array(
56
                            'pathString' => '/1/5/13',
57
                            'path' => array(1, 5, 13),
58
                        )
59
                    ),
60
                    array()
61
                ),
62
            ),
63
            '/some/path',
64
            14
65
        );
66
67
        $this->setVisitValueObjectExpectations([
68
            new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/5/14']),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadUserGroup' 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...
69
            new ResourceRouteReference('ezpublish_rest_unassignUserFromUserGroup', ['userId' => $UserGroupRefList->userId, 'groupPath' => 14]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_unassignUserFromUserGroup' 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...
70
            new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/5/13']),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadUserGroup' 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...
71
            new ResourceRouteReference('ezpublish_rest_unassignUserFromUserGroup', ['userId' => $UserGroupRefList->userId, 'groupPath' => 13]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_unassignUserFromUserGroup' 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...
72
        ]);
73
74
        $visitor->visit(
75
            $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...
76
            $generator,
77
            $UserGroupRefList
78
        );
79
80
        $result = $generator->endDocument(null);
81
82
        $this->assertNotNull($result);
83
84
        $dom = new \DOMDocument();
85
        $dom->loadXml($result);
86
87
        return $dom;
88
    }
89
90
    /**
91
     * @param \DOMDocument $dom
92
     *
93
     * @depends testVisit
94
     */
95
    public function testUserGroupRefListMediaTypeCorrect(\DOMDocument $dom)
96
    {
97
        $this->assertXPath($dom, '/UserGroupRefList[@media-type="application/vnd.ez.api.UserGroupRefList+xml"]');
98
    }
99
100
    /**
101
     * @param \DOMDocument $dom
102
     *
103
     * @depends testVisit
104
     */
105
    public function testFirstUserGroupMediaTypeCorrect(\DOMDocument $dom)
106
    {
107
        $this->assertXPath($dom, '/UserGroupRefList/UserGroup[1][@media-type="application/vnd.ez.api.UserGroup+xml"]');
108
    }
109
110
    /**
111
     * @param \DOMDocument $dom
112
     *
113
     * @depends testVisit
114
     */
115
    public function testFirstUserGroupUnassignMethodCorrect(\DOMDocument $dom)
116
    {
117
        $this->assertXPath($dom, '/UserGroupRefList/UserGroup[1]/unassign[@method="DELETE"]');
118
    }
119
120
    /**
121
     * @param \DOMDocument $dom
122
     *
123
     * @depends testVisit
124
     */
125
    public function testSecondUserGroupMediaTypeCorrect(\DOMDocument $dom)
126
    {
127
        $this->assertXPath($dom, '/UserGroupRefList/UserGroup[2][@media-type="application/vnd.ez.api.UserGroup+xml"]');
128
    }
129
130
    /**
131
     * @param \DOMDocument $dom
132
     *
133
     * @depends testVisit
134
     */
135
    public function testSecondUserGroupUnassignMethodCorrect(\DOMDocument $dom)
136
    {
137
        $this->assertXPath($dom, '/UserGroupRefList/UserGroup[2]/unassign[@method="DELETE"]');
138
    }
139
140
    /**
141
     * Get the UserGroupRefList visitor.
142
     *
143
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\UserGroupRefList
144
     */
145
    protected function internalGetVisitor()
146
    {
147
        return new ValueObjectVisitor\UserGroupRefList();
148
    }
149
}
150