Completed
Push — ezp25366-copy_content_relation... ( 7d5327...4b97d3 )
by André
74:42 queued 12:30
created

testResultContainsContentInfoAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 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\Output\ValueObjectVisitor;
15
use eZ\Publish\Core\REST\Server\Values\RestTrashItem;
16
use eZ\Publish\Core\Repository\Values\Content\TrashItem;
17
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
18
19
class RestTrashItemTest extends ValueObjectVisitorBaseTest
20
{
21
    /**
22
     * Test the TrashItem visitor.
23
     *
24
     * @return string
25
     */
26
    public function testVisit()
27
    {
28
        $visitor = $this->getVisitor();
29
        $generator = $this->getGenerator();
30
31
        $generator->startDocument(null);
32
33
        $trashItem = new RestTrashItem(
34
            new TrashItem(
35
                array(
36
                    'id' => 42,
37
                    'priority' => 0,
38
                    'hidden' => false,
39
                    'invisible' => true,
40
                    'remoteId' => 'remote-id',
41
                    'parentLocationId' => 21,
42
                    'pathString' => '/1/2/21/42/',
43
                    'depth' => 3,
44
                    'contentInfo' => new ContentInfo(
45
                        array(
46
                            'id' => 84,
47
                             'contentTypeId' => 4,
48
                             'name' => 'A Node, long lost in the trash',
49
                        )
50
                    ),
51
                    'sortField' => TrashItem::SORT_FIELD_NAME,
52
                    'sortOrder' => TrashItem::SORT_ORDER_DESC,
53
                )
54
            ),
55
            // Dummy value for ChildCount
56
            0
57
        );
58
59
        $this->addRouteExpectation(
60
            'ezpublish_rest_loadTrashItem',
61
            array('trashItemId' => $trashItem->trashItem->id),
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
            "/content/trash/{$trashItem->trashItem->id}"
0 ignored issues
show
Documentation introduced by
The property $id is declared protected in eZ\Publish\API\Repository\Values\Content\Location. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
        );
64
        $this->addRouteExpectation(
65
            'ezpublish_rest_loadLocation',
66
            array('locationPath' => '1/2/21'),
67
            '/content/locations/1/2/21'
68
        );
69
70
        $this->addRouteExpectation(
71
            'ezpublish_rest_loadContent',
72
            array('contentId' => $trashItem->trashItem->contentInfo->id),
73
            "/content/objects/{$trashItem->trashItem->contentInfo->id}"
74
        );
75
76
        // Expected twice, second one here for ContentInfo
77
        $this->addRouteExpectation(
78
            'ezpublish_rest_loadContent',
79
            array('contentId' => $trashItem->trashItem->contentInfo->id),
80
            "/content/objects/{$trashItem->trashItem->contentInfo->id}"
81
        );
82
83
        $this->getVisitorMock()->expects($this->once())
84
            ->method('visitValueObject')
85
            ->with($this->isInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\RestContent'));
86
87
        $visitor->visit(
88
            $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...
89
            $generator,
90
            $trashItem
91
        );
92
93
        $result = $generator->endDocument(null);
94
95
        $this->assertNotNull($result);
96
97
        return $result;
98
    }
99
100
    /**
101
     * Test if result contains TrashItem element.
102
     *
103
     * @param string $result
104
     *
105
     * @depends testVisit
106
     */
107
    public function testResultContainsTrashItemElement($result)
108
    {
109
        $this->assertXMLTag(
110
            array(
111
                'tag' => 'TrashItem',
112
                'children' => array(
113
                    'count' => 12,
114
                ),
115
            ),
116
            $result,
117
            'Invalid <TrashItem> element.',
118
            false
119
        );
120
    }
121
122
    /**
123
     * Test if result contains TrashItem element attributes.
124
     *
125
     * @param string $result
126
     *
127
     * @depends testVisit
128
     */
129
    public function testResultContainsTrashItemAttributes($result)
130
    {
131
        $this->assertXMLTag(
132
            array(
133
                'tag' => 'TrashItem',
134
                'attributes' => array(
135
                    'media-type' => 'application/vnd.ez.api.TrashItem+xml',
136
                    'href' => '/content/trash/42',
137
                ),
138
            ),
139
            $result,
140
            'Invalid <TrashItem> attributes.',
141
            false
142
        );
143
    }
144
145
    /**
146
     * Test if result contains ContentInfo element.
147
     *
148
     * @param string $result
149
     *
150
     * @depends testVisit
151
     */
152
    public function testResultContainsContentInfoElement($result)
153
    {
154
        $this->assertXMLTag(
155
            array(
156
                'tag' => 'ContentInfo',
157
            ),
158
            $result,
159
            'Invalid <ContentInfo> element.',
160
            false
161
        );
162
    }
163
164
    /**
165
     * Test if result contains Location element attributes.
166
     *
167
     * @param string $result
168
     *
169
     * @depends testVisit
170
     */
171
    public function testResultContainsContentInfoAttributes($result)
172
    {
173
        $this->assertXMLTag(
174
            array(
175
                'tag' => 'ContentInfo',
176
                'attributes' => array(
177
                    'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
178
                    'href' => '/content/objects/84',
179
                ),
180
            ),
181
            $result,
182
            'Invalid <ContentInfo> attributes.',
183
            false
184
        );
185
    }
186
187
    /**
188
     * Test if result contains id value element.
189
     *
190
     * @param string $result
191
     *
192
     * @depends testVisit
193
     */
194
    public function testResultContainsIdValueElement($result)
195
    {
196
        $this->assertXMLTag(
197
            array(
198
                'tag' => 'id',
199
                'content' => '42',
200
            ),
201
            $result,
202
            'Invalid or non-existing <TrashItem> id value element.',
203
            false
204
        );
205
    }
206
207
    /**
208
     * Test if result contains priority value element.
209
     *
210
     * @param string $result
211
     *
212
     * @depends testVisit
213
     */
214
    public function testResultContainsPriorityValueElement($result)
215
    {
216
        $this->assertXMLTag(
217
            array(
218
                'tag' => 'priority',
219
                'content' => '0',
220
            ),
221
            $result,
222
            'Invalid or non-existing <TrashItem> priority value element.',
223
            false
224
        );
225
    }
226
227
    /**
228
     * Test if result contains hidden value element.
229
     *
230
     * @param string $result
231
     *
232
     * @depends testVisit
233
     */
234
    public function testResultContainsHiddenValueElement($result)
235
    {
236
        $this->assertXMLTag(
237
            array(
238
                'tag' => 'hidden',
239
                'content' => 'false',
240
            ),
241
            $result,
242
            'Invalid or non-existing <TrashItem> hidden value element.',
243
            false
244
        );
245
    }
246
247
    /**
248
     * Test if result contains invisible value element.
249
     *
250
     * @param string $result
251
     *
252
     * @depends testVisit
253
     */
254
    public function testResultContainsInvisibleValueElement($result)
255
    {
256
        $this->assertXMLTag(
257
            array(
258
                'tag' => 'invisible',
259
                'content' => 'true',
260
            ),
261
            $result,
262
            'Invalid or non-existing <TrashItem> invisible value element.',
263
            false
264
        );
265
    }
266
267
    /**
268
     * Test if result contains remoteId value element.
269
     *
270
     * @param string $result
271
     *
272
     * @depends testVisit
273
     */
274
    public function testResultContainsRemoteIdValueElement($result)
275
    {
276
        $this->assertXMLTag(
277
            array(
278
                'tag' => 'remoteId',
279
                'content' => 'remote-id',
280
            ),
281
            $result,
282
            'Invalid or non-existing <TrashItem> remoteId value element.',
283
            false
284
        );
285
    }
286
287
    /**
288
     * Test if result contains ParentLocation element.
289
     *
290
     * @param string $result
291
     *
292
     * @depends testVisit
293
     */
294
    public function testResultContainsParentLocationElement($result)
295
    {
296
        $this->assertXMLTag(
297
            array(
298
                'tag' => 'ParentLocation',
299
            ),
300
            $result,
301
            'Invalid <ParentLocation> element.',
302
            false
303
        );
304
    }
305
306
    /**
307
     * Test if result contains ParentLocation element attributes.
308
     *
309
     * @param string $result
310
     *
311
     * @depends testVisit
312
     */
313
    public function testResultContainsParentLocationAttributes($result)
314
    {
315
        $this->assertXMLTag(
316
            array(
317
                'tag' => 'ParentLocation',
318
                'attributes' => array(
319
                    'media-type' => 'application/vnd.ez.api.Location+xml',
320
                    'href' => '/content/locations/1/2/21',
321
                ),
322
            ),
323
            $result,
324
            'Invalid <ParentLocation> attributes.',
325
            false
326
        );
327
    }
328
329
    /**
330
     * Test if result contains pathString value element.
331
     *
332
     * @param string $result
333
     *
334
     * @depends testVisit
335
     */
336
    public function testResultContainsPathStringValueElement($result)
337
    {
338
        $this->assertXMLTag(
339
            array(
340
                'tag' => 'pathString',
341
                'content' => '/1/2/21/42/',
342
            ),
343
            $result,
344
            'Invalid or non-existing <TrashItem> pathString value element.',
345
            false
346
        );
347
    }
348
349
    /**
350
     * Test if result contains depth value element.
351
     *
352
     * @param string $result
353
     *
354
     * @depends testVisit
355
     */
356
    public function testResultContainsDepthValueElement($result)
357
    {
358
        $this->assertXMLTag(
359
            array(
360
                'tag' => 'depth',
361
                'content' => '3',
362
            ),
363
            $result,
364
            'Invalid or non-existing <TrashItem> depth value element.',
365
            false
366
        );
367
    }
368
369
    /**
370
     * Test if result contains childCount value element.
371
     *
372
     * @param string $result
373
     *
374
     * @depends testVisit
375
     */
376
    public function testResultContainsChildCountValueElement($result)
377
    {
378
        $this->assertXMLTag(
379
            array(
380
                'tag' => 'childCount',
381
                'content' => '0',
382
            ),
383
            $result,
384
            'Invalid or non-existing <TrashItem> childCount value element.',
385
            false
386
        );
387
    }
388
389
    /**
390
     * Test if result contains Content element.
391
     *
392
     * @param string $result
393
     *
394
     * @depends testVisit
395
     */
396
    public function testResultContainsContentElement($result)
397
    {
398
        $this->assertXMLTag(
399
            array(
400
                'tag' => 'Content',
401
            ),
402
            $result,
403
            'Invalid <Content> element.',
404
            false
405
        );
406
    }
407
408
    /**
409
     * Test if result contains Content element attributes.
410
     *
411
     * @param string $result
412
     *
413
     * @depends testVisit
414
     */
415
    public function testResultContainsContentAttributes($result)
416
    {
417
        $this->assertXMLTag(
418
            array(
419
                'tag' => 'Content',
420
                'attributes' => array(
421
                    'media-type' => 'application/vnd.ez.api.Content+xml',
422
                    'href' => '/content/objects/84',
423
                ),
424
            ),
425
            $result,
426
            'Invalid <Content> attributes.',
427
            false
428
        );
429
    }
430
431
    /**
432
     * Test if result contains sortField value element.
433
     *
434
     * @param string $result
435
     *
436
     * @depends testVisit
437
     */
438
    public function testResultContainsSortFieldValueElement($result)
439
    {
440
        $this->assertXMLTag(
441
            array(
442
                'tag' => 'sortField',
443
                'content' => 'NAME',
444
            ),
445
            $result,
446
            'Invalid or non-existing <TrashItem> sortField value element.',
447
            false
448
        );
449
    }
450
451
    /**
452
     * Test if result contains sortOrder value element.
453
     *
454
     * @param string $result
455
     *
456
     * @depends testVisit
457
     */
458
    public function testResultContainsSortOrderValueElement($result)
459
    {
460
        $this->assertXMLTag(
461
            array(
462
                'tag' => 'sortOrder',
463
                'content' => 'DESC',
464
            ),
465
            $result,
466
            'Invalid or non-existing <TrashItem> sortOrder value element.',
467
            false
468
        );
469
    }
470
471
    /**
472
     * Get the TrashItem visitor.
473
     *
474
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestTrashItem
475
     */
476
    protected function internalGetVisitor()
477
    {
478
        return new ValueObjectVisitor\RestTrashItem();
479
    }
480
}
481