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

RestUserGroupTest::testParentUserGroupHrefCorrect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
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\Values\ResourceRouteReference;
15
use eZ\Publish\Core\REST\Server\Values\RestUserGroup;
16
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
17
use eZ\Publish\Core\Repository\Values;
18
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
19
20
class RestUserGroupTest extends ValueObjectVisitorBaseTest
21
{
22
    /**
23
     * @return \DOMDocument
24
     */
25
    public function testVisitWithoutEmbeddedVersion()
26
    {
27
        $visitor = $this->getVisitor();
28
        $generator = $this->getGenerator();
29
30
        $generator->startDocument(null);
31
32
        $restUserGroup = $this->getBasicRestUserGroup();
33
34
        $userGroupPath = implode('/', $restUserGroup->mainLocation->path);
35
36
        $this->setVisitValueObjectExpectations([
37
            new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => $userGroupPath]),
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...
38
            new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restUserGroup->contentInfo->contentTypeId]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadContentType' 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...
39
            new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restUserGroup->contentInfo->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadContentVersions' 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...
40
            new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restUserGroup->contentInfo->sectionId]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadSection' 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...
41
            new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $userGroupPath]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadLocation' 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...
42
            new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restUserGroup->contentInfo->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadLocationsForContent' 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...
43
            new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restUserGroup->contentInfo->ownerId]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadUser' 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...
44
            $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\Version'),
45
            new ResourceRouteReference('ezpublish_rest_loadUserGroup', ['groupPath' => '1/2']),
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...
46
            new ResourceRouteReference('ezpublish_rest_loadSubUserGroups', ['groupPath' => $userGroupPath]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadSubUserGroups' 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...
47
            new ResourceRouteReference('ezpublish_rest_loadUsersFromGroup', ['groupPath' => $userGroupPath]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadUsersFromGroup' 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...
48
            new ResourceRouteReference('ezpublish_rest_loadRoleAssignmentsForUserGroup', ['groupPath' => $userGroupPath]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadRoleAssignmentsForUserGroup' 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...
49
        ]);
50
51
        $visitor->visit(
52
            $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...
53
            $generator,
54
            $restUserGroup
55
        );
56
57
        $result = $generator->endDocument(null);
58
59
        $this->assertNotNull($result);
60
61
        $dom = new \DOMDocument();
62
        $dom->loadXml($result);
63
64
        return $dom;
65
    }
66
67 View Code Duplication
    protected function getBasicRestUserGroup()
68
    {
69
        return new RestUserGroup(
70
            new Values\User\UserGroup(),
71
            $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'),
72
            new ContentInfo(
73
                array(
74
                    'id' => 'content23',
75
                    'name' => 'Sindelfingen',
76
                    'sectionId' => 'section23',
77
                    'currentVersionNo' => 5,
78
                    'published' => true,
79
                    'ownerId' => 'user23',
80
                    'modificationDate' => new \DateTime('2012-09-05 15:27 Europe/Berlin'),
81
                    'publishedDate' => new \DateTime('2012-09-05 15:27 Europe/Berlin'),
82
                    'alwaysAvailable' => true,
83
                    'remoteId' => 'abc123',
84
                    'mainLanguageCode' => 'eng-US',
85
                    'mainLocationId' => 'location23',
86
                    'contentTypeId' => 'contentType23',
87
                )
88
            ),
89
            new Values\Content\Location(
90
                array(
91
                    'pathString' => '/1/2/23',
92
                    'path' => array(1, 2, 23),
93
                )
94
            ),
95
            array()
96
        );
97
    }
98
99
    /**
100
     * @param \DOMDocument $dom
101
     *
102
     * @depends testVisitWithoutEmbeddedVersion
103
     */
104
    public function testUserGroupIdCorrect(\DOMDocument $dom)
105
    {
106
        $this->assertXPath($dom, '/UserGroup[@id="content23"]');
107
    }
108
109
    /**
110
     * @param \DOMDocument $dom
111
     *
112
     * @depends testVisitWithoutEmbeddedVersion
113
     */
114
    public function testUserGroupMediaTypeWithoutVersionCorrect(\DOMDocument $dom)
115
    {
116
        $this->assertXPath($dom, '/UserGroup[@media-type="application/vnd.ez.api.UserGroup+xml"]');
117
    }
118
119
    /**
120
     * @param \DOMDocument $dom
121
     *
122
     * @depends testVisitWithoutEmbeddedVersion
123
     */
124
    public function testUserGroupRemoteIdCorrect(\DOMDocument $dom)
125
    {
126
        $this->assertXPath($dom, '/UserGroup[@remoteId="abc123"]');
127
    }
128
129
    /**
130
     * @param \DOMDocument $dom
131
     *
132
     * @depends testVisitWithoutEmbeddedVersion
133
     */
134
    public function testUserGroupTypeMediaTypeCorrect(\DOMDocument $dom)
135
    {
136
        $this->assertXPath($dom, '/UserGroup/ContentType[@media-type="application/vnd.ez.api.ContentType+xml"]');
137
    }
138
139
    /**
140
     * @param \DOMDocument $dom
141
     *
142
     * @depends testVisitWithoutEmbeddedVersion
143
     */
144
    public function testNameCorrect(\DOMDocument $dom)
145
    {
146
        $this->assertXPath($dom, '/UserGroup/name[text()="Sindelfingen"]');
147
    }
148
149
    /**
150
     * @param \DOMDocument $dom
151
     *
152
     * @depends testVisitWithoutEmbeddedVersion
153
     */
154
    public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
155
    {
156
        $this->assertXPath($dom, '/UserGroup/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
157
    }
158
159
    /**
160
     * @param \DOMDocument $dom
161
     *
162
     * @depends testVisitWithoutEmbeddedVersion
163
     */
164
    public function testSectionMediaTypeCorrect(\DOMDocument $dom)
165
    {
166
        $this->assertXPath($dom, '/UserGroup/Section[@media-type="application/vnd.ez.api.Section+xml"]');
167
    }
168
169
    /**
170
     * @param \DOMDocument $dom
171
     *
172
     * @depends testVisitWithoutEmbeddedVersion
173
     */
174
    public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
175
    {
176
        $this->assertXPath($dom, '/UserGroup/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
177
    }
178
179
    /**
180
     * @param \DOMDocument $dom
181
     *
182
     * @depends testVisitWithoutEmbeddedVersion
183
     */
184
    public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
185
    {
186
        $this->assertXPath($dom, '/UserGroup/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
187
    }
188
189
    /**
190
     * @param \DOMDocument $dom
191
     *
192
     * @depends testVisitWithoutEmbeddedVersion
193
     */
194
    public function testOwnerMediaTypeCorrect(\DOMDocument $dom)
195
    {
196
        $this->assertXPath($dom, '/UserGroup/Owner[@media-type="application/vnd.ez.api.User+xml"]');
197
    }
198
199
    /**
200
     * @param \DOMDocument $dom
201
     *
202
     * @depends testVisitWithoutEmbeddedVersion
203
     */
204
    public function testLastModificationDateCorrect(\DOMDocument $dom)
205
    {
206
        $this->assertXPath($dom, '/UserGroup/lastModificationDate[text()="2012-09-05T15:27:00+02:00"]');
207
    }
208
209
    /**
210
     * @param \DOMDocument $dom
211
     *
212
     * @depends testVisitWithoutEmbeddedVersion
213
     */
214
    public function testMainLanguageCodeCorrect(\DOMDocument $dom)
215
    {
216
        $this->assertXPath($dom, '/UserGroup/mainLanguageCode[text()="eng-US"]');
217
    }
218
219
    /**
220
     * @param \DOMDocument $dom
221
     *
222
     * @depends testVisitWithoutEmbeddedVersion
223
     */
224
    public function testAlwaysAvailableCorrect(\DOMDocument $dom)
225
    {
226
        $this->assertXPath($dom, '/UserGroup/alwaysAvailable[text()="true"]');
227
    }
228
229
    /**
230
     * @param \DOMDocument $dom
231
     *
232
     * @depends testVisitWithoutEmbeddedVersion
233
     */
234
    public function testParentUserGroupMediaTypeCorrect(\DOMDocument $dom)
235
    {
236
        $this->assertXPath($dom, '/UserGroup/ParentUserGroup[@media-type="application/vnd.ez.api.UserGroup+xml"]');
237
    }
238
239
    /**
240
     * @param \DOMDocument $dom
241
     *
242
     * @depends testVisitWithoutEmbeddedVersion
243
     */
244
    public function testSubgroupsMediaTypeCorrect(\DOMDocument $dom)
245
    {
246
        $this->assertXPath($dom, '/UserGroup/Subgroups[@media-type="application/vnd.ez.api.UserGroupList+xml"]');
247
    }
248
249
    /**
250
     * @param \DOMDocument $dom
251
     *
252
     * @depends testVisitWithoutEmbeddedVersion
253
     */
254
    public function testUsersMediaTypeCorrect(\DOMDocument $dom)
255
    {
256
        $this->assertXPath($dom, '/UserGroup/Users[@media-type="application/vnd.ez.api.UserList+xml"]');
257
    }
258
259
    /**
260
     * @param \DOMDocument $dom
261
     *
262
     * @depends testVisitWithoutEmbeddedVersion
263
     */
264
    public function testRolesMediaTypeCorrect(\DOMDocument $dom)
265
    {
266
        $this->assertXPath($dom, '/UserGroup/Roles[@media-type="application/vnd.ez.api.RoleAssignmentList+xml"]');
267
    }
268
269
    /**
270
     * Get the UserGroup visitor.
271
     *
272
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestUserGroup
273
     */
274
    protected function internalGetVisitor()
275
    {
276
        return new ValueObjectVisitor\RestUserGroup();
277
    }
278
}
279