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

RestContentTest::testVisitWithoutEmbeddedVersion()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
nc 1
nop 0
dl 0
loc 40
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\Values\ResourceRouteReference;
15
use eZ\Publish\Core\REST\Server\Values\RestContent;
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 RestContentTest 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
        $restContent = $this->getBasicRestContent();
33
34
        $this->addRouteExpectation(
35
            'ezpublish_rest_loadContent',
36
            array('contentId' => $restContent->contentInfo->id),
37
            "/content/objects/{$restContent->contentInfo->id}"
38
        );
39
        $this->setVisitValueObjectExpectations([
40
            new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restContent->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...
41
            new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restContent->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...
42
            new ResourceRouteReference('ezpublish_rest_redirectCurrentVersion', ['contentId' => $restContent->contentInfo->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_redirectCurrentVersion' 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_loadSection', ['sectionId' => $restContent->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...
44
            new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')]),
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...
45
            new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restContent->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...
46
            new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContent->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...
47
            new ResourceRouteReference('ezpublish_rest_getObjectStatesForContent', ['contentId' => $restContent->contentInfo->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_getObjectStatesForContent' 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
        ]);
49
50
        $visitor->visit(
51
            $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...
52
            $generator,
53
            $restContent
54
        );
55
56
        $result = $generator->endDocument(null);
57
58
        $this->assertNotNull($result);
59
60
        $dom = new \DOMDocument();
61
        $dom->loadXml($result);
62
63
        return $dom;
64
    }
65
66
    protected function getBasicRestContent()
67
    {
68
        return new RestContent(
69
            new ContentInfo(
70
                array(
71
                    'id' => 'content23',
72
                    'name' => 'Sindelfingen',
73
                    'sectionId' => 'section23',
74
                    'currentVersionNo' => 5,
75
                    'published' => true,
76
                    'ownerId' => 'user23',
77
                    'modificationDate' => new \DateTime('2012-09-05 15:27 Europe/Berlin'),
78
                    'publishedDate' => null,
79
                    'alwaysAvailable' => true,
80
                    'remoteId' => 'abc123',
81
                    'mainLanguageCode' => 'eng-US',
82
                    'mainLocationId' => 'location23',
83
                    'contentTypeId' => 'contentType23',
84
                )
85
            ),
86
            new Values\Content\Location(
87
                array(
88
                    'pathString' => '/1/2/23',
89
                )
90
            ),
91
            null
92
        );
93
    }
94
95
    /**
96
     * @param \DOMDocument $dom
97
     *
98
     * @depends testVisitWithoutEmbeddedVersion
99
     */
100
    public function testContentHrefCorrect(\DOMDocument $dom)
101
    {
102
        $this->assertXPath($dom, '/Content[@href="/content/objects/content23"]');
103
    }
104
105
    /**
106
     * @param \DOMDocument $dom
107
     *
108
     * @depends testVisitWithoutEmbeddedVersion
109
     */
110
    public function testContentIdCorrect(\DOMDocument $dom)
111
    {
112
        $this->assertXPath($dom, '/Content[@id="content23"]');
113
    }
114
115
    /**
116
     * @param \DOMDocument $dom
117
     *
118
     * @depends testVisitWithoutEmbeddedVersion
119
     */
120
    public function testContentMediaTypeWithoutVersionCorrect(\DOMDocument $dom)
121
    {
122
        $this->assertXPath($dom, '/Content[@media-type="application/vnd.ez.api.ContentInfo+xml"]');
123
    }
124
125
    /**
126
     * @param \DOMDocument $dom
127
     *
128
     * @depends testVisitWithoutEmbeddedVersion
129
     */
130
    public function testContentRemoteIdCorrect(\DOMDocument $dom)
131
    {
132
        $this->assertXPath($dom, '/Content[@remoteId="abc123"]');
133
    }
134
135
    /**
136
     * @param \DOMDocument $dom
137
     *
138
     * @depends testVisitWithoutEmbeddedVersion
139
     */
140
    public function testContentTypeMediaTypeCorrect(\DOMDocument $dom)
141
    {
142
        $this->assertXPath($dom, '/Content/ContentType[@media-type="application/vnd.ez.api.ContentType+xml"]');
143
    }
144
145
    /**
146
     * @param \DOMDocument $dom
147
     *
148
     * @depends testVisitWithoutEmbeddedVersion
149
     */
150
    public function testNameCorrect(\DOMDocument $dom)
151
    {
152
        $this->assertXPath($dom, '/Content/Name[text()="Sindelfingen"]');
153
    }
154
155
    /**
156
     * @param \DOMDocument $dom
157
     *
158
     * @depends testVisitWithoutEmbeddedVersion
159
     */
160
    public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
161
    {
162
        $this->assertXPath($dom, '/Content/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
163
    }
164
165
    /**
166
     * @param \DOMDocument $dom
167
     *
168
     * @depends testVisitWithoutEmbeddedVersion
169
     */
170
    public function testCurrentVersionMediaTypeCorrect(\DOMDocument $dom)
171
    {
172
        $this->assertXPath($dom, '/Content/CurrentVersion[@media-type="application/vnd.ez.api.Version+xml"]');
173
    }
174
175
    /**
176
     * @param \DOMDocument $dom
177
     *
178
     * @depends testVisitWithoutEmbeddedVersion
179
     */
180
    public function testSectionMediaTypeCorrect(\DOMDocument $dom)
181
    {
182
        $this->assertXPath($dom, '/Content/Section[@media-type="application/vnd.ez.api.Section+xml"]');
183
    }
184
185
    /**
186
     * @param \DOMDocument $dom
187
     *
188
     * @depends testVisitWithoutEmbeddedVersion
189
     */
190
    public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
191
    {
192
        $this->assertXPath($dom, '/Content/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
193
    }
194
195
    /**
196
     * @param \DOMDocument $dom
197
     *
198
     * @depends testVisitWithoutEmbeddedVersion
199
     */
200
    public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
201
    {
202
        $this->assertXPath($dom, '/Content/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
203
    }
204
205
    /**
206
     * @param \DOMDocument $dom
207
     *
208
     * @depends testVisitWithoutEmbeddedVersion
209
     */
210
    public function testOwnerMediaTypeCorrect(\DOMDocument $dom)
211
    {
212
        $this->assertXPath($dom, '/Content/Owner[@media-type="application/vnd.ez.api.User+xml"]');
213
    }
214
215
    /**
216
     * @param \DOMDocument $dom
217
     *
218
     * @depends testVisitWithoutEmbeddedVersion
219
     */
220
    public function testLastModificationDateCorrect(\DOMDocument $dom)
221
    {
222
        $this->assertXPath($dom, '/Content/lastModificationDate[text()="2012-09-05T15:27:00+02:00"]');
223
    }
224
225
    /**
226
     * @param \DOMDocument $dom
227
     *
228
     * @depends testVisitWithoutEmbeddedVersion
229
     */
230
    public function testMainLanguageCodeCorrect(\DOMDocument $dom)
231
    {
232
        $this->assertXPath($dom, '/Content/mainLanguageCode[text()="eng-US"]');
233
    }
234
235
    /**
236
     * @param \DOMDocument $dom
237
     *
238
     * @depends testVisitWithoutEmbeddedVersion
239
     */
240
    public function testCurrentVersionNoCorrect(\DOMDocument $dom)
241
    {
242
        $this->assertXPath($dom, '/Content/currentVersionNo[text()="5"]');
243
    }
244
245
    /**
246
     * @param \DOMDocument $dom
247
     *
248
     * @depends testVisitWithoutEmbeddedVersion
249
     */
250
    public function testAlwaysAvailableCorrect(\DOMDocument $dom)
251
    {
252
        $this->assertXPath($dom, '/Content/alwaysAvailable[text()="true"]');
253
    }
254
255
    /**
256
     * @return \DOMDocument
257
     */
258
    public function testVisitWithEmbeddedVersion()
259
    {
260
        $visitor = $this->getVisitor();
261
        $generator = $this->getGenerator();
262
263
        $generator->startDocument(null);
264
265
        $restContent = $this->getBasicRestContent();
266
        $restContent->currentVersion = new Values\Content\Content(
267
            array(
268
                'versionInfo' => new Values\Content\VersionInfo(array('versionNo' => 5)),
269
                'internalFields' => array(),
270
            )
271
        );
272
        $restContent->relations = array();
273
        $restContent->contentType = $this->getMockForAbstractClass(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...tentType\\ContentType') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<eZ\Publish\API\Re...ontentType\ContentType> of property $contentType.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
274
            'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'
275
        );
276
277
        $this->addRouteExpectation(
278
            'ezpublish_rest_loadContent',
279
            array('contentId' => $restContent->contentInfo->id),
280
            "/content/objects/{$restContent->contentInfo->id}"
281
        );
282
        $this->setVisitValueObjectExpectations([
283
            new ResourceRouteReference('ezpublish_rest_loadContentType', ['contentTypeId' => $restContent->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...
284
            new ResourceRouteReference('ezpublish_rest_loadContentVersions', ['contentId' => $restContent->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...
285
            new ResourceRouteReference('ezpublish_rest_redirectCurrentVersion', ['contentId' => $restContent->contentInfo->id]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_redirectCurrentVersion' 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...
286
            $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\Version'),
287
            new ResourceRouteReference('ezpublish_rest_loadSection', ['sectionId' => $restContent->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...
288
            new ResourceRouteReference('ezpublish_rest_loadLocation', ['locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')]),
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...
289
            new ResourceRouteReference('ezpublish_rest_loadLocationsForContent', ['contentId' => $restContent->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...
290
            new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $restContent->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...
291
        ]);
292
293
        $visitor->visit(
294
            $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...
295
            $generator,
296
            $restContent
297
        );
298
299
        $result = $generator->endDocument(null);
300
301
        $this->assertNotNull($result);
302
303
        $dom = new \DOMDocument();
304
        $dom->loadXml($result);
305
306
        return $dom;
307
    }
308
309
    /**
310
     * @param \DOMDocument $dom
311
     *
312
     * @depends testVisitWithEmbeddedVersion
313
     */
314
    public function testContentMediaTypeWithVersionCorrect(\DOMDocument $dom)
315
    {
316
        $this->assertXPath($dom, '/Content[@media-type="application/vnd.ez.api.Content+xml"]');
317
    }
318
319
    /**
320
     * @param \DOMDocument $dom
321
     *
322
     * @depends testVisitWithEmbeddedVersion
323
     */
324
    public function testEmbeddedCurrentVersionMediaTypeCorrect(\DOMDocument $dom)
325
    {
326
        $this->assertXPath($dom, '/Content/CurrentVersion[@media-type="application/vnd.ez.api.Version+xml"]');
327
    }
328
329
    /**
330
     * Get the Content visitor.
331
     *
332
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestContent
333
     */
334
    protected function internalGetVisitor()
335
    {
336
        return new ValueObjectVisitor\RestContent();
337
    }
338
}
339