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

RestContentTest   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 462
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 10

Importance

Changes 0
Metric Value
dl 0
loc 462
rs 10
c 0
b 0
f 0
wmc 30
lcom 2
cbo 10

30 Methods

Rating   Name   Duplication   Size   Complexity  
A testVisitWithoutEmbeddedVersion() 0 73 1
B getBasicRestContent() 0 28 1
A testContentHrefCorrect() 0 4 1
A testContentIdCorrect() 0 4 1
A testContentMediaTypeWithoutVersionCorrect() 0 4 1
A testContentRemoteIdCorrect() 0 4 1
A testContentTypeHrefCorrect() 0 4 1
A testContentTypeMediaTypeCorrect() 0 4 1
A testNameCorrect() 0 4 1
A testVersionsHrefCorrect() 0 4 1
A testVersionsMediaTypeCorrect() 0 4 1
A testCurrentVersionHrefCorrect() 0 4 1
A testCurrentVersionMediaTypeCorrect() 0 4 1
A testSectionHrefCorrect() 0 4 1
A testSectionMediaTypeCorrect() 0 4 1
A testMainLocationHrefCorrect() 0 4 1
A testMainLocationMediaTypeCorrect() 0 4 1
A testLocationsHrefCorrect() 0 4 1
A testLocationsMediaTypeCorrect() 0 4 1
A testOwnerHrefCorrect() 0 4 1
A testOwnerMediaTypeCorrect() 0 4 1
A testLastModificationDateCorrect() 0 4 1
A testMainLanguageCodeCorrect() 0 4 1
A testAlwaysAvailableCorrect() 0 4 1
B testVisitWithEmbeddedVersion() 0 80 1
A testContentMediaTypeWithVersionCorrect() 0 4 1
A testEmbeddedCurrentVersionHrefCorrect() 0 4 1
A testEmbeddedCurrentVersionMediaTypeCorrect() 0 4 1
A internalGetVisitor() 0 4 1
A testCurrentVersionNoCorrect() 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\REST\Server\Values\RestContent;
15
use eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
16
use eZ\Publish\Core\Repository\Values;
17
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
18
19
class RestContentTest extends ValueObjectVisitorBaseTest
20
{
21
    /**
22
     * @return \DOMDocument
23
     */
24
    public function testVisitWithoutEmbeddedVersion()
25
    {
26
        $visitor = $this->getVisitor();
27
        $generator = $this->getGenerator();
28
29
        $generator->startDocument(null);
30
31
        $restContent = $this->getBasicRestContent();
32
33
        $this->getVisitorMock()->expects($this->never())
34
            ->method('visitValueObject');
35
36
        $this->addRouteExpectation(
37
            'ezpublish_rest_loadContent',
38
            array('contentId' => $restContent->contentInfo->id),
39
            "/content/objects/{$restContent->contentInfo->id}"
40
        );
41
        $this->addRouteExpectation(
42
            'ezpublish_rest_loadContentType',
43
            array('contentTypeId' => $restContent->contentInfo->contentTypeId),
44
            "/content/types/{$restContent->contentInfo->contentTypeId}"
45
        );
46
        $this->addRouteExpectation(
47
            'ezpublish_rest_loadContentVersions',
48
            array('contentId' => $restContent->contentInfo->id),
49
            "/content/objects/{$restContent->contentInfo->id}/versions"
50
        );
51
        $this->addRouteExpectation(
52
            'ezpublish_rest_redirectCurrentVersion',
53
            array('contentId' => $restContent->contentInfo->id),
54
            "/content/objects/{$restContent->contentInfo->id}/currentversion"
55
        );
56
        $this->addRouteExpectation(
57
            'ezpublish_rest_loadSection',
58
            array('sectionId' => $restContent->contentInfo->sectionId),
59
            "/content/sections/{$restContent->contentInfo->sectionId}"
60
        );
61
        $this->addRouteExpectation(
62
            'ezpublish_rest_loadLocation',
63
            array('locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')),
64
            "/content/locations/{$locationPath}"
65
        );
66
        $this->addRouteExpectation(
67
            'ezpublish_rest_loadLocationsForContent',
68
            array('contentId' => $restContent->contentInfo->id),
69
            "/content/objects/{$restContent->contentInfo->id}/locations"
70
        );
71
        $this->addRouteExpectation(
72
            'ezpublish_rest_loadUser',
73
            array('userId' => $restContent->contentInfo->ownerId),
74
            "/user/users/{$restContent->contentInfo->ownerId}"
75
        );
76
        $this->addRouteExpectation(
77
            'ezpublish_rest_getObjectStatesForContent',
78
            array('contentId' => $restContent->contentInfo->id),
79
            "/content/objects/{$restContent->contentInfo->id}/objectstates"
80
        );
81
82
        $visitor->visit(
83
            $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...
84
            $generator,
85
            $restContent
86
        );
87
88
        $result = $generator->endDocument(null);
89
90
        $this->assertNotNull($result);
91
92
        $dom = new \DOMDocument();
93
        $dom->loadXml($result);
94
95
        return $dom;
96
    }
97
98
    protected function getBasicRestContent()
99
    {
100
        return new RestContent(
101
            new ContentInfo(
102
                array(
103
                    'id' => 'content23',
104
                    'name' => 'Sindelfingen',
105
                    'sectionId' => 'section23',
106
                    'currentVersionNo' => 5,
107
                    'published' => true,
108
                    'ownerId' => 'user23',
109
                    'modificationDate' => new \DateTime('2012-09-05 15:27 Europe/Berlin'),
110
                    'publishedDate' => null,
111
                    'alwaysAvailable' => true,
112
                    'remoteId' => 'abc123',
113
                    'mainLanguageCode' => 'eng-US',
114
                    'mainLocationId' => 'location23',
115
                    'contentTypeId' => 'contentType23',
116
                )
117
            ),
118
            new Values\Content\Location(
119
                array(
120
                    'pathString' => '/1/2/23',
121
                )
122
            ),
123
            null
124
        );
125
    }
126
127
    /**
128
     * @param \DOMDocument $dom
129
     *
130
     * @depends testVisitWithoutEmbeddedVersion
131
     */
132
    public function testContentHrefCorrect(\DOMDocument $dom)
133
    {
134
        $this->assertXPath($dom, '/Content[@href="/content/objects/content23"]');
135
    }
136
137
    /**
138
     * @param \DOMDocument $dom
139
     *
140
     * @depends testVisitWithoutEmbeddedVersion
141
     */
142
    public function testContentIdCorrect(\DOMDocument $dom)
143
    {
144
        $this->assertXPath($dom, '/Content[@id="content23"]');
145
    }
146
147
    /**
148
     * @param \DOMDocument $dom
149
     *
150
     * @depends testVisitWithoutEmbeddedVersion
151
     */
152
    public function testContentMediaTypeWithoutVersionCorrect(\DOMDocument $dom)
153
    {
154
        $this->assertXPath($dom, '/Content[@media-type="application/vnd.ez.api.ContentInfo+xml"]');
155
    }
156
157
    /**
158
     * @param \DOMDocument $dom
159
     *
160
     * @depends testVisitWithoutEmbeddedVersion
161
     */
162
    public function testContentRemoteIdCorrect(\DOMDocument $dom)
163
    {
164
        $this->assertXPath($dom, '/Content[@remoteId="abc123"]');
165
    }
166
167
    /**
168
     * @param \DOMDocument $dom
169
     *
170
     * @depends testVisitWithoutEmbeddedVersion
171
     */
172
    public function testContentTypeHrefCorrect(\DOMDocument $dom)
173
    {
174
        $this->assertXPath($dom, '/Content/ContentType[@href="/content/types/contentType23"]');
175
    }
176
177
    /**
178
     * @param \DOMDocument $dom
179
     *
180
     * @depends testVisitWithoutEmbeddedVersion
181
     */
182
    public function testContentTypeMediaTypeCorrect(\DOMDocument $dom)
183
    {
184
        $this->assertXPath($dom, '/Content/ContentType[@media-type="application/vnd.ez.api.ContentType+xml"]');
185
    }
186
187
    /**
188
     * @param \DOMDocument $dom
189
     *
190
     * @depends testVisitWithoutEmbeddedVersion
191
     */
192
    public function testNameCorrect(\DOMDocument $dom)
193
    {
194
        $this->assertXPath($dom, '/Content/Name[text()="Sindelfingen"]');
195
    }
196
197
    /**
198
     * @param \DOMDocument $dom
199
     *
200
     * @depends testVisitWithoutEmbeddedVersion
201
     */
202
    public function testVersionsHrefCorrect(\DOMDocument $dom)
203
    {
204
        $this->assertXPath($dom, '/Content/Versions[@href="/content/objects/content23/versions"]');
205
    }
206
207
    /**
208
     * @param \DOMDocument $dom
209
     *
210
     * @depends testVisitWithoutEmbeddedVersion
211
     */
212
    public function testVersionsMediaTypeCorrect(\DOMDocument $dom)
213
    {
214
        $this->assertXPath($dom, '/Content/Versions[@media-type="application/vnd.ez.api.VersionList+xml"]');
215
    }
216
217
    /**
218
     * @param \DOMDocument $dom
219
     *
220
     * @depends testVisitWithoutEmbeddedVersion
221
     */
222
    public function testCurrentVersionHrefCorrect(\DOMDocument $dom)
223
    {
224
        $this->assertXPath($dom, '/Content/CurrentVersion[@href="/content/objects/content23/currentversion"]');
225
    }
226
227
    /**
228
     * @param \DOMDocument $dom
229
     *
230
     * @depends testVisitWithoutEmbeddedVersion
231
     */
232
    public function testCurrentVersionMediaTypeCorrect(\DOMDocument $dom)
233
    {
234
        $this->assertXPath($dom, '/Content/CurrentVersion[@media-type="application/vnd.ez.api.Version+xml"]');
235
    }
236
237
    /**
238
     * @param \DOMDocument $dom
239
     *
240
     * @depends testVisitWithoutEmbeddedVersion
241
     */
242
    public function testSectionHrefCorrect(\DOMDocument $dom)
243
    {
244
        $this->assertXPath($dom, '/Content/Section[@href="/content/sections/section23"]');
245
    }
246
247
    /**
248
     * @param \DOMDocument $dom
249
     *
250
     * @depends testVisitWithoutEmbeddedVersion
251
     */
252
    public function testSectionMediaTypeCorrect(\DOMDocument $dom)
253
    {
254
        $this->assertXPath($dom, '/Content/Section[@media-type="application/vnd.ez.api.Section+xml"]');
255
    }
256
257
    /**
258
     * @param \DOMDocument $dom
259
     *
260
     * @depends testVisitWithoutEmbeddedVersion
261
     */
262
    public function testMainLocationHrefCorrect(\DOMDocument $dom)
263
    {
264
        $this->assertXPath($dom, '/Content/MainLocation[@href="/content/locations/1/2/23"]');
265
    }
266
267
    /**
268
     * @param \DOMDocument $dom
269
     *
270
     * @depends testVisitWithoutEmbeddedVersion
271
     */
272
    public function testMainLocationMediaTypeCorrect(\DOMDocument $dom)
273
    {
274
        $this->assertXPath($dom, '/Content/MainLocation[@media-type="application/vnd.ez.api.Location+xml"]');
275
    }
276
277
    /**
278
     * @param \DOMDocument $dom
279
     *
280
     * @depends testVisitWithoutEmbeddedVersion
281
     */
282
    public function testLocationsHrefCorrect(\DOMDocument $dom)
283
    {
284
        $this->assertXPath($dom, '/Content/Locations[@href="/content/objects/content23/locations"]');
285
    }
286
287
    /**
288
     * @param \DOMDocument $dom
289
     *
290
     * @depends testVisitWithoutEmbeddedVersion
291
     */
292
    public function testLocationsMediaTypeCorrect(\DOMDocument $dom)
293
    {
294
        $this->assertXPath($dom, '/Content/Locations[@media-type="application/vnd.ez.api.LocationList+xml"]');
295
    }
296
297
    /**
298
     * @param \DOMDocument $dom
299
     *
300
     * @depends testVisitWithoutEmbeddedVersion
301
     */
302
    public function testOwnerHrefCorrect(\DOMDocument $dom)
303
    {
304
        $this->assertXPath($dom, '/Content/Owner[@href="/user/users/user23"]');
305
    }
306
307
    /**
308
     * @param \DOMDocument $dom
309
     *
310
     * @depends testVisitWithoutEmbeddedVersion
311
     */
312
    public function testOwnerMediaTypeCorrect(\DOMDocument $dom)
313
    {
314
        $this->assertXPath($dom, '/Content/Owner[@media-type="application/vnd.ez.api.User+xml"]');
315
    }
316
317
    /**
318
     * @param \DOMDocument $dom
319
     *
320
     * @depends testVisitWithoutEmbeddedVersion
321
     */
322
    public function testLastModificationDateCorrect(\DOMDocument $dom)
323
    {
324
        $this->assertXPath($dom, '/Content/lastModificationDate[text()="2012-09-05T15:27:00+02:00"]');
325
    }
326
327
    /**
328
     * @param \DOMDocument $dom
329
     *
330
     * @depends testVisitWithoutEmbeddedVersion
331
     */
332
    public function testMainLanguageCodeCorrect(\DOMDocument $dom)
333
    {
334
        $this->assertXPath($dom, '/Content/mainLanguageCode[text()="eng-US"]');
335
    }
336
337
    /**
338
     * @param \DOMDocument $dom
339
     *
340
     * @depends testVisitWithoutEmbeddedVersion
341
     */
342
    public function testCurrentVersionNoCorrect(\DOMDocument $dom)
343
    {
344
        $this->assertXPath($dom, '/Content/currentVersionNo[text()="5"]');
345
    }
346
347
    /**
348
     * @param \DOMDocument $dom
349
     *
350
     * @depends testVisitWithoutEmbeddedVersion
351
     */
352
    public function testAlwaysAvailableCorrect(\DOMDocument $dom)
353
    {
354
        $this->assertXPath($dom, '/Content/alwaysAvailable[text()="true"]');
355
    }
356
357
    /**
358
     * @return \DOMDocument
359
     */
360
    public function testVisitWithEmbeddedVersion()
361
    {
362
        $visitor = $this->getVisitor();
363
        $generator = $this->getGenerator();
364
365
        $generator->startDocument(null);
366
367
        $restContent = $this->getBasicRestContent();
368
        $restContent->currentVersion = new Values\Content\Content(
369
            array(
370
                'versionInfo' => new Values\Content\VersionInfo(array('versionNo' => 5)),
371
                'internalFields' => array(),
372
            )
373
        );
374
        $restContent->relations = array();
375
        $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...
376
            'eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType'
377
        );
378
379
        $this->getVisitorMock()->expects($this->once())
380
            ->method('visitValueObject')
381
            ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\Version'));
382
383
        $this->addRouteExpectation(
384
            'ezpublish_rest_loadContent',
385
            array('contentId' => $restContent->contentInfo->id),
386
            "/content/objects/{$restContent->contentInfo->id}"
387
        );
388
        $this->addRouteExpectation(
389
            'ezpublish_rest_loadContentType',
390
            array('contentTypeId' => $restContent->contentInfo->contentTypeId),
391
            "/content/types/{$restContent->contentInfo->contentTypeId}"
392
        );
393
        $this->addRouteExpectation(
394
            'ezpublish_rest_loadContentVersions',
395
            array('contentId' => $restContent->contentInfo->id),
396
            "/content/objects/{$restContent->contentInfo->id}/versions"
397
        );
398
        $this->addRouteExpectation(
399
            'ezpublish_rest_redirectCurrentVersion',
400
            array('contentId' => $restContent->contentInfo->id),
401
            "/content/objects/{$restContent->contentInfo->id}/currentversion"
402
        );
403
404
        $this->addRouteExpectation(
405
            'ezpublish_rest_loadSection',
406
            array('sectionId' => $restContent->contentInfo->sectionId),
407
            "/content/sections/{$restContent->contentInfo->sectionId}"
408
        );
409
        $this->addRouteExpectation(
410
            'ezpublish_rest_loadLocation',
411
            array('locationPath' => $locationPath = trim($restContent->mainLocation->pathString, '/')),
412
            "/content/locations/{$locationPath}"
413
        );
414
        $this->addRouteExpectation(
415
            'ezpublish_rest_loadLocationsForContent',
416
            array('contentId' => $restContent->contentInfo->id),
417
            "/content/objects/{$restContent->contentInfo->id}/locations"
418
        );
419
        $this->addRouteExpectation(
420
            'ezpublish_rest_loadUser',
421
            array('userId' => $restContent->contentInfo->ownerId),
422
            "/user/users/{$restContent->contentInfo->ownerId}"
423
        );
424
425
        $visitor->visit(
426
            $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...
427
            $generator,
428
            $restContent
429
        );
430
431
        $result = $generator->endDocument(null);
432
433
        $this->assertNotNull($result);
434
435
        $dom = new \DOMDocument();
436
        $dom->loadXml($result);
437
438
        return $dom;
439
    }
440
441
    /**
442
     * @param \DOMDocument $dom
443
     *
444
     * @depends testVisitWithEmbeddedVersion
445
     */
446
    public function testContentMediaTypeWithVersionCorrect(\DOMDocument $dom)
447
    {
448
        $this->assertXPath($dom, '/Content[@media-type="application/vnd.ez.api.Content+xml"]');
449
    }
450
451
    /**
452
     * @param \DOMDocument $dom
453
     *
454
     * @depends testVisitWithEmbeddedVersion
455
     */
456
    public function testEmbeddedCurrentVersionHrefCorrect(\DOMDocument $dom)
457
    {
458
        $this->assertXPath($dom, '/Content/CurrentVersion[@href="/content/objects/content23/currentversion"]');
459
    }
460
461
    /**
462
     * @param \DOMDocument $dom
463
     *
464
     * @depends testVisitWithEmbeddedVersion
465
     */
466
    public function testEmbeddedCurrentVersionMediaTypeCorrect(\DOMDocument $dom)
467
    {
468
        $this->assertXPath($dom, '/Content/CurrentVersion[@media-type="application/vnd.ez.api.Version+xml"]');
469
    }
470
471
    /**
472
     * Get the Content visitor.
473
     *
474
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestContent
475
     */
476
    protected function internalGetVisitor()
477
    {
478
        return new ValueObjectVisitor\RestContent();
479
    }
480
}
481