Completed
Push — ezp26352-skip_csrf_check_on_re... ( 19f37a...6abe82 )
by
unknown
79:54 queued 33:48
created

VersionInfoTest::testVersionInfoNamesElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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