Completed
Push — master ( 5fa9fe...31552d )
by André
46:14 queued 23:32
created

RestContentTest   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 473
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 10

Importance

Changes 0
Metric Value
dl 0
loc 473
rs 9.92
c 0
b 0
f 0
wmc 31
lcom 2
cbo 10

31 Methods

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