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

RestLocationRootNodeTest::testVisit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 40
nc 1
nop 0
dl 0
loc 59
rs 9.597
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Server\Output\ValueObjectVisitor;
14
use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
15
use eZ\Publish\Core\REST\Server\Values\RestLocation;
16
use eZ\Publish\Core\Repository\Values\Content\Location;
17
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
18
19
class RestLocationRootNodeTest extends RestLocationTest
20
{
21
    /**
22
     * Test the Location 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
        $location = new RestLocation(
34
            new Location(
35
                array(
36
                    'id' => 1,
37
                    'priority' => 0,
38
                    'hidden' => false,
39
                    'invisible' => true,
40
                    'remoteId' => 'remote-id',
41
                    'parentLocationId' => null,
42
                    'pathString' => '/1',
43
                    'depth' => 3,
44
                    'sortField' => Location::SORT_FIELD_PATH,
45
                    'sortOrder' => Location::SORT_ORDER_ASC,
46
                    'contentInfo' => new ContentInfo(
47
                        array(
48
                            'id' => 42,
49
                            'contentTypeId' => 4,
50
                            'name' => 'A Node, long lost',
51
                        )
52
                    ),
53
                )
54
            ),
55
            // Dummy value for ChildCount
56
            0
57
        );
58
59
        $this->addRouteExpectation(
60
            'ezpublish_rest_loadLocation',
61
            array('locationPath' => '1'),
62
            '/content/locations/1'
63
        );
64
65
        $this->setVisitValueObjectExpectations([
66
            new ResourceRouteReference('ezpublish_rest_loadLocationChildren', array('locationPath' => '1')),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadLocationChildren' 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...
67
            new ResourceRouteReference('ezpublish_rest_loadContent', array('contentId' => $location->location->contentId)),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadContent' 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...
68
            new ResourceRouteReference('ezpublish_rest_listLocationURLAliases', array('locationPath' => '1')),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_listLocationURLAliases' 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...
69
            new ResourceRouteReference('ezpublish_rest_loadContent', array('contentId' => $location->location->contentId), 'ContentInfo'),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadContent' 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...
70
            $this->isInstanceOf('eZ\Publish\Core\REST\Server\Values\RestContent'),
71
        ]);
72
73
        $visitor->visit(
74
            $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...
75
            $generator,
76
            $location
77
        );
78
79
        $result = $generator->endDocument(null);
80
81
        $this->assertNotNull($result);
82
83
        return $result;
84
    }
85
86
    /**
87
     * Test if result contains id value element.
88
     *
89
     * @param string $result
90
     *
91
     * @depends testVisit
92
     */
93
    public function testResultContainsIdValueElement($result)
94
    {
95
        $this->assertXMLTag(
96
            array(
97
                'tag' => 'id',
98
                'content' => '1',
99
            ),
100
            $result,
101
            'Invalid or non-existing <Location> id value element.',
102
            false
103
        );
104
    }
105
106
    /**
107
     * Test if result contains ParentLocation element.
108
     *
109
     * @param string $result
110
     *
111
     * @depends testVisit
112
     */
113
    public function testResultContainsParentLocationElement($result)
114
    {
115
        $this->assertXMLTag(
116
            array(
117
                'tag' => 'ParentLocation',
118
            ),
119
            $result,
120
            'Invalid <ParentLocation> element.',
121
            false
122
        );
123
    }
124
125
    /**
126
     * Test if result contains ParentLocation element attributes.
127
     *
128
     * @param string $result
129
     *
130
     * @depends testVisit
131
     */
132
    public function testResultContainsParentLocationAttributes($result)
133
    {
134
        $this->assertXMLTag(
135
            array(
136
                'tag' => 'ParentLocation',
137
                'attributes' => array(),
138
            ),
139
            $result,
140
            'Invalid <ParentLocation> attributes.',
141
            false
142
        );
143
    }
144
145
    /**
146
     * Test if result contains Location element attributes.
147
     *
148
     * @param string $result
149
     *
150
     * @depends testVisit
151
     */
152
    public function testResultContainsLocationAttributes($result)
153
    {
154
        $this->assertXMLTag(
155
            array(
156
                'tag' => 'Location',
157
                'attributes' => array(
158
                    'media-type' => 'application/vnd.ez.api.Location+xml',
159
                    'href' => '/content/locations/1',
160
                ),
161
            ),
162
            $result,
163
            'Invalid <Location> attributes.',
164
            false
165
        );
166
    }
167
168
    /**
169
     * Test if result contains Children element attributes.
170
     *
171
     * @param string $result
172
     *
173
     * @depends testVisit
174
     */
175
    public function testResultContainsChildrenAttributes($result)
176
    {
177
        $this->assertXMLTag(
178
            array(
179
                'tag' => 'Children',
180
                'attributes' => array(
181
                    'media-type' => 'application/vnd.ez.api.LocationList+xml',
182
                ),
183
            ),
184
            $result,
185
            'Invalid <Children> attributes.',
186
            false
187
        );
188
    }
189
190
    /**
191
     * Test if result contains pathString value element.
192
     *
193
     * @param string $result
194
     *
195
     * @depends testVisit
196
     */
197
    public function testResultContainsPathStringValueElement($result)
198
    {
199
        $this->assertXMLTag(
200
            array(
201
                'tag' => 'pathString',
202
                'content' => '/1',
203
            ),
204
            $result,
205
            'Invalid or non-existing <Location> pathString value element.',
206
            false
207
        );
208
    }
209
210
    /**
211
     * Test if result contains Content element attributes.
212
     *
213
     * @param string $result
214
     *
215
     * @depends testVisit
216
     */
217
    public function testResultContainsUrlAliasesTagAttributes($result)
218
    {
219
        $this->assertXMLTag(
220
            array(
221
                'tag' => 'UrlAliases',
222
                'attributes' => array(
223
                    'media-type' => 'application/vnd.ez.api.UrlAliasRefList+xml',
224
                ),
225
            ),
226
            $result,
227
            'Invalid <UrlAliases> attributes.',
228
            false
229
        );
230
    }
231
232
    /**
233
     * Get the Location visitor.
234
     *
235
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestLocation
236
     */
237
    protected function internalGetVisitor()
238
    {
239
        return new ValueObjectVisitor\RestLocation();
240
    }
241
}
242