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

VersionInfoTest::testVisit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 28
nc 1
nop 0
dl 0
loc 42
rs 8.8571
c 0
b 0
f 0
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\Repository\Values\Content;
16
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
17
use eZ\Publish\Core\REST\Server\Values\ResourceRouteReference;
18
19
class VersionInfoTest extends ValueObjectVisitorBaseTest
20
{
21
    /**
22
     * @var \DateTime
23
     */
24
    protected $creationDate;
25
26
    /**
27
     * @var \DateTime
28
     */
29
    protected $modificationDate;
30
31
    public function setUp()
32
    {
33
        $this->creationDate = new \DateTime('2012-05-19 12:23 Europe/Berlin');
34
        $this->modificationDate = new \DateTime('2012-08-31 23:42 Europe/Berlin');
35
    }
36
37
    /**
38
     * Test the VersionInfo visitor.
39
     *
40
     * @return string
41
     */
42
    public function testVisit()
43
    {
44
        $visitor = $this->getVisitor();
45
        $generator = $this->getGenerator();
46
47
        $generator->startDocument(null);
48
49
        $versionInfo = new Content\VersionInfo(
50
            array(
51
                'id' => 23,
52
                'versionNo' => 5,
53
                'status' => Content\VersionInfo::STATUS_PUBLISHED,
54
                'creationDate' => $this->creationDate,
55
                'creatorId' => 14,
56
                'modificationDate' => $this->modificationDate,
57
                'initialLanguageCode' => 'eng-US',
58
                'languageCodes' => array('eng-US', 'ger-DE'),
59
                'names' => array(
60
                    'eng-US' => 'Sindelfingen',
61
                    'eng-GB' => 'Bielefeld',
62
                ),
63
                'contentInfo' => new ContentInfo(array('id' => 42)),
64
            )
65
        );
66
67
        $this->setVisitValueObjectExpectations([
68
            new ResourceRouteReference('ezpublish_rest_loadUser', ['userId' => $versionInfo->creatorId]),
0 ignored issues
show
Documentation introduced by
'ezpublish_rest_loadUser' 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', ['contentId' => $versionInfo->contentInfo->id]),
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
        ]);
71
72
        $visitor->visit(
73
            $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...
74
            $generator,
75
            $versionInfo
76
        );
77
78
        $result = $generator->endDocument(null);
79
80
        $this->assertNotNull($result);
81
82
        return $result;
83
    }
84
85
    /**
86
     * @param string $result
87
     *
88
     * @depends testVisit
89
     */
90
    public function testResultContainsVersionInfoChildren($result)
91
    {
92
        $this->assertXMLTag(
93
            array(
94
                'tag' => 'VersionInfo',
95
                'children' => array(
96
                    'less_than' => 11,
97
                    'greater_than' => 9,
98
                ),
99
            ),
100
            $result,
101
            'Invalid <VersionInfo> element.',
102
            false
103
        );
104
    }
105
106
    /**
107
     * @param string $result
108
     *
109
     * @depends testVisit
110
     */
111
    public function testVersionInfoIdElement($result)
112
    {
113
        $this->assertXMLTag(
114
            array(
115
                'tag' => 'id',
116
                'content' => '23',
117
            ),
118
            $result,
119
            'Invalid <id> value.',
120
            false
121
        );
122
    }
123
124
    /**
125
     * @param string $result
126
     *
127
     * @depends testVisit
128
     */
129
    public function testVersionInfoVersionNoElement($result)
130
    {
131
        $this->assertXMLTag(
132
            array(
133
                'tag' => 'versionNo',
134
                'content' => '5',
135
            ),
136
            $result,
137
            'Invalid <versionNo> value.',
138
            false
139
        );
140
    }
141
142
    /**
143
     * @param string $result
144
     *
145
     * @depends testVisit
146
     */
147
    public function testVersionInfoStatusElement($result)
148
    {
149
        $this->assertXMLTag(
150
            array(
151
                'tag' => 'status',
152
                'content' => 'PUBLISHED',
153
            ),
154
            $result,
155
            'Invalid <status> value.',
156
            false
157
        );
158
    }
159
160
    /**
161
     * @param string $result
162
     *
163
     * @depends testVisit
164
     */
165 View Code Duplication
    public function testVersionInfoCreationDateElement($result)
166
    {
167
        $this->assertXMLTag(
168
            array(
169
                'tag' => 'creationDate',
170
                'content' => $this->creationDate->format('c'),
171
            ),
172
            $result,
173
            'Invalid <creationDate> value.',
174
            false
175
        );
176
    }
177
178
    /**
179
     * @param string $result
180
     *
181
     * @depends testVisit
182
     */
183 View Code Duplication
    public function testVersionInfoModificationDateElement($result)
184
    {
185
        $this->assertXMLTag(
186
            array(
187
                'tag' => 'modificationDate',
188
                'content' => $this->modificationDate->format('c'),
189
            ),
190
            $result,
191
            'Invalid <modificationDate> value.',
192
            false
193
        );
194
    }
195
196
    /**
197
     * @param string $result
198
     *
199
     * @depends testVisit
200
     */
201
    public function testVersionInfoInitialLanguageCodeElement($result)
202
    {
203
        $this->assertXMLTag(
204
            array(
205
                'tag' => 'initialLanguageCode',
206
                'content' => 'eng-US',
207
            ),
208
            $result,
209
            'Invalid <initialLanguageCode> value.',
210
            false
211
        );
212
    }
213
214
    /**
215
     * @param string $result
216
     *
217
     * @depends testVisit
218
     */
219
    public function testVersionInfoLanguageCodesElement($result)
220
    {
221
        $this->assertXMLTag(
222
            array(
223
                'tag' => 'languageCodes',
224
                'content' => 'eng-US,ger-DE',
225
            ),
226
            $result,
227
            'Invalid <languageCodes> value.',
228
            false
229
        );
230
    }
231
232
    /**
233
     * @param string $result
234
     *
235
     * @depends testVisit
236
     */
237
    public function testVersionInfoNamesElement($result)
238
    {
239
        $this->assertXMLTag(
240
            array(
241
                'tag' => 'names',
242
                'children' => array(
243
                    'less_than' => 3,
244
                    'greater_than' => 1,
245
                ),
246
            ),
247
            $result,
248
            'Invalid <names> value.',
249
            false
250
        );
251
    }
252
253
    /**
254
     * @param string $result
255
     *
256
     * @depends testVisit
257
     */
258
    public function testVersionInfoContentElement($result)
259
    {
260
        $this->assertXMLTag(
261
            array(
262
                'tag' => 'Content',
263
                'attributes' => array(
264
                    'media-type' => 'application/vnd.ez.api.ContentInfo+xml',
265
                ),
266
            ),
267
            $result,
268
            'Invalid <initialLanguageCode> value.',
269
            false
270
        );
271
    }
272
273
    /**
274
     * Get the VersionInfo visitor.
275
     *
276
     * @return \eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\VersionInfo
277
     */
278
    protected function internalGetVisitor()
279
    {
280
        return new ValueObjectVisitor\VersionInfo();
281
    }
282
}
283