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