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

ContentHandlerTest::testCopySingleVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 60
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 60
rs 9.5555
c 1
b 1
f 0
cc 1
eloc 43
nc 1
nop 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 contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest 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\Persistence\Legacy\Tests\Content;
12
13
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
14
use eZ\Publish\SPI\Persistence\Content;
15
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
16
use eZ\Publish\SPI\Persistence\Content\Field;
17
use eZ\Publish\SPI\Persistence\Content\FieldValue;
18
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
19
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
20
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
21
use eZ\Publish\SPI\Persistence\Content\Relation;
22
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
23
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct as LocationCreateStruct;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Handler;
25
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
26
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
27
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
28
29
/**
30
 * Test case for Content Handler.
31
 */
32
class ContentHandlerTest extends TestCase
33
{
34
    /**
35
     * Content handler to test.
36
     *
37
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler
38
     */
39
    protected $contentHandler;
40
41
    /**
42
     * Gateway mock.
43
     *
44
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
45
     */
46
    protected $gatewayMock;
47
48
    /**
49
     * Location gateway mock.
50
     *
51
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
52
     */
53
    protected $locationGatewayMock;
54
55
    /**
56
     * Type gateway mock.
57
     *
58
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
59
     */
60
    protected $typeGatewayMock;
61
62
    /**
63
     * Mapper mock.
64
     *
65
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
66
     */
67
    protected $mapperMock;
68
69
    /**
70
     * Field handler mock.
71
     *
72
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
73
     */
74
    protected $fieldHandlerMock;
75
76
    /**
77
     * Location handler mock.
78
     *
79
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
80
     */
81
    protected $treeHandlerMock;
82
83
    /**
84
     * Slug converter mock.
85
     *
86
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
87
     */
88
    protected $slugConverterMock;
89
90
    /**
91
     * Location handler mock.
92
     *
93
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
94
     */
95
    protected $urlAliasGatewayMock;
96
97
    /**
98
     * ContentType handler mock.
99
     *
100
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
101
     */
102
    protected $contentTypeHandlerMock;
103
104
    /**
105
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::__construct
106
     */
107 View Code Duplication
    public function testCtor()
108
    {
109
        $handler = $this->getContentHandler();
110
111
        $this->assertAttributeSame(
112
            $this->getGatewayMock(),
113
            'contentGateway',
114
            $handler
115
        );
116
        $this->assertAttributeSame(
117
            $this->getMapperMock(),
118
            'mapper',
119
            $handler
120
        );
121
        $this->assertAttributeSame(
122
            $this->getFieldHandlerMock(),
123
            'fieldHandler',
124
            $handler
125
        );
126
        // @todo Assert missing properties
127
    }
128
129
    /**
130
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::create
131
     *
132
     * @todo Current method way to complex to test, refactor!
133
     */
134
    public function testCreate()
135
    {
136
        $handler = $this->getContentHandler();
137
138
        $mapperMock = $this->getMapperMock();
139
        $gatewayMock = $this->getGatewayMock();
140
        $fieldHandlerMock = $this->getFieldHandlerMock();
141
        $locationMock = $this->getLocationGatewayMock();
142
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
143
        $contentTypeMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Type');
144
        $createStruct = $this->getCreateStructFixture();
145
146
        $contentTypeHandlerMock->expects($this->once())
147
            ->method('load')
148
            ->with($createStruct->typeId)
149
            ->will($this->returnValue($contentTypeMock));
150
151
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
152
            ->method('createVersionInfoFromCreateStruct')
153
            ->with(
154
                $this->isInstanceOf(
155
                    'eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'
156
                )
157
            )->will(
158
                $this->returnValue(
159
                    new VersionInfo(
160
                        array(
161
                            'names' => array(),
162
                            'contentInfo' => new ContentInfo(),
163
                        )
164
                    )
165
                )
166
            );
167
168
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
169
            ->method('insertContentObject')
170
            ->with(
171
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct')
172
            )->will($this->returnValue(23));
173
174
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
            ->method('insertVersion')
176
            ->with(
177
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'),
178
                $this->isType('array')
179
            )->will($this->returnValue(1));
180
181
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
            ->method('createNewFields')
183
            ->with(
184
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'),
185
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Type')
186
            );
187
188
        $locationMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
189
            ->method('createNodeAssignment')
190
            ->with(
191
                $this->isInstanceOf(
192
                    'eZ\\Publish\\SPI\\Persistence\\Content\\Location\\CreateStruct'
193
                ),
194
                $this->equalTo(42),
195
                $this->equalTo(3) // Location\Gateway::NODE_ASSIGNMENT_OP_CODE_CREATE
196
            );
197
198
        $res = $handler->create($createStruct);
199
200
        // @todo Make subsequent tests
201
202
        $this->assertInstanceOf(
203
            'eZ\\Publish\\SPI\\Persistence\\Content',
204
            $res,
205
            'Content not created'
206
        );
207
        $this->assertEquals(
208
            23,
209
            $res->versionInfo->contentInfo->id,
210
            'Content ID not set correctly'
211
        );
212
        $this->assertInstanceOf(
213
            '\\eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo',
214
            $res->versionInfo,
215
            'Version infos not created'
216
        );
217
        $this->assertEquals(
218
            1,
219
            $res->versionInfo->id,
220
            'Version ID not set correctly'
221
        );
222
        $this->assertEquals(
223
            2,
224
            count($res->fields),
225
            'Fields not set correctly in version'
226
        );
227
    }
228
229
    /**
230
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
231
     */
232
    public function testPublishFirstVersion()
233
    {
234
        $handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus'));
235
236
        $gatewayMock = $this->getGatewayMock();
237
        $mapperMock = $this->getMapperMock();
238
        $locationMock = $this->getLocationGatewayMock();
239
        $fieldHandlerMock = $this->getFieldHandlerMock();
240
        $metadataUpdateStruct = new MetadataUpdateStruct();
241
242
        $handler->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
243
            ->method('loadVersionInfo')
244
            ->with(23, 1)
245
            ->will(
246
                $this->returnValue(
247
                    new VersionInfo(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
248
                )
249
            );
250
251
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
252
            ->method('load')
253
            ->with(
254
                $this->equalTo(23),
255
                $this->equalTo(1),
256
                $this->equalTo(null)
257
            )->will(
258
                $this->returnValue(array(42))
259
            );
260
261
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
262
            ->method('loadVersionedNameData')
263
            ->with(
264
                $this->equalTo(array(array('id' => 23, 'version' => 1)))
265
            )->will(
266
                $this->returnValue(array(22))
267
            );
268
269
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
270
            ->method('extractContentFromRows')
271
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
272
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
273
274
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
275
            ->method('loadExternalFieldData')
276
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
277
278
        $gatewayMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
279
            ->expects($this->once())
280
            ->method('updateContent')
281
            ->with(23, $metadataUpdateStruct);
282
283
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
284
            ->expects($this->once())
285
            ->method('createLocationsFromNodeAssignments')
286
            ->with(23, 1);
287
288
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
            ->expects($this->once())
290
            ->method('updateLocationsContentVersionNo')
291
            ->with(23, 1);
292
293
        $handler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
294
            ->expects($this->once())
295
            ->method('setStatus')
296
            ->with(23, VersionInfo::STATUS_PUBLISHED, 1);
297
298
        $handler->publish(23, 1, $metadataUpdateStruct);
299
    }
300
301
    /**
302
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
303
     */
304
    public function testPublish()
305
    {
306
        $handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus'));
307
308
        $gatewayMock = $this->getGatewayMock();
309
        $mapperMock = $this->getMapperMock();
310
        $locationMock = $this->getLocationGatewayMock();
311
        $fieldHandlerMock = $this->getFieldHandlerMock();
312
        $metadataUpdateStruct = new MetadataUpdateStruct();
313
314
        $handler->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
315
            ->method('loadVersionInfo')
316
            ->with(23, 2)
317
            ->will(
318
                $this->returnValue(
319
                    new VersionInfo(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
320
                )
321
            );
322
323
        $handler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
324
            ->expects($this->at(1))
325
            ->method('setStatus')
326
            ->with(23, VersionInfo::STATUS_ARCHIVED, 1);
327
328
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
329
            ->method('load')
330
            ->with(
331
                $this->equalTo(23),
332
                $this->equalTo(2),
333
                $this->equalTo(null)
334
            )
335
            ->will($this->returnValue(array(42)));
336
337
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
338
            ->method('loadVersionedNameData')
339
            ->with(
340
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
341
            )->will(
342
                $this->returnValue(array(22))
343
            );
344
345
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
346
            ->method('extractContentFromRows')
347
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
348
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
349
350
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
351
            ->method('loadExternalFieldData')
352
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
353
354
        $gatewayMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
355
            ->expects($this->once())
356
            ->method('updateContent')
357
            ->with(23, $metadataUpdateStruct, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'));
358
359
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
360
            ->expects($this->once())
361
            ->method('createLocationsFromNodeAssignments')
362
            ->with(23, 2);
363
364
        $locationMock
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
365
            ->expects($this->once())
366
            ->method('updateLocationsContentVersionNo')
367
            ->with(23, 2);
368
369
        $handler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
370
            ->expects($this->at(2))
371
            ->method('setStatus')
372
            ->with(23, VersionInfo::STATUS_PUBLISHED, 2);
373
374
        $handler->publish(23, 2, $metadataUpdateStruct);
375
    }
376
377
    /**
378
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::createDraftFromVersion
379
     */
380
    public function testCreateDraftFromVersion()
381
    {
382
        $handler = $this->getPartlyMockedHandler(array('load'));
383
384
        $mapperMock = $this->getMapperMock();
385
        $gatewayMock = $this->getGatewayMock();
386
        $fieldHandlerMock = $this->getFieldHandlerMock();
387
388
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
389
            ->method('load')
390
            ->with(23, 2)
391
            ->will($this->returnValue($this->getContentFixtureForDraft()));
392
393
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
394
            ->method('createVersionInfoForContent')
395
            ->with(
396
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'),
397
                $this->equalTo(3),
398
                $this->equalTo(14)
399
            )->will(
400
                $this->returnValue(
401
                    new VersionInfo(
402
                        array(
403
                            'names' => array(),
404
                            'versionNo' => 3,
405
                        )
406
                    )
407
                )
408
            );
409
410
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
411
            ->method('insertVersion')
412
            ->with(
413
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo'),
414
                $this->getContentFixtureForDraft()->fields
415
            )->will($this->returnValue(42));
416
417
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
418
            ->method('getLastVersionNumber')
419
            ->with($this->equalTo(23))
420
            ->will($this->returnValue(2));
421
422
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
423
            ->method('createExistingFieldsInNewVersion')
424
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
425
426
        $relationData = array(
427
            array(
428
                'ezcontentobject_link_contentclassattribute_id' => 0,
429
                'ezcontentobject_link_to_contentobject_id' => 42,
430
                'ezcontentobject_link_relation_type' => 1,
431
            ),
432
        );
433
434
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
435
            ->method('loadRelations')
436
            ->with(
437
                $this->equalTo(23),
438
                $this->equalTo(2)
439
            )
440
            ->will($this->returnValue($relationData));
441
442
        $relationStruct = new RelationCreateStruct(
443
            array(
444
                'sourceContentId' => 23,
445
                'sourceContentVersionNo' => 3,
446
                'sourceFieldDefinitionId' => 0,
447
                'destinationContentId' => 42,
448
                'type' => 1,
449
            )
450
        );
451
452
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
453
            ->method('insertRelation')
454
            ->with($this->equalTo($relationStruct));
455
456
        $result = $handler->createDraftFromVersion(23, 2, 14);
457
458
        $this->assertInstanceOf(
459
            'eZ\\Publish\\SPI\\Persistence\\Content',
460
            $result
461
        );
462
        $this->assertEquals(
463
            42,
464
            $result->versionInfo->id
465
        );
466
    }
467
468
    /**
469
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
470
     */
471
    public function testLoad()
472
    {
473
        $handler = $this->getContentHandler();
474
475
        $gatewayMock = $this->getGatewayMock();
476
        $mapperMock = $this->getMapperMock();
477
        $fieldHandlerMock = $this->getFieldHandlerMock();
478
479
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
480
            ->method('load')
481
            ->with(
482
                $this->equalTo(23),
483
                $this->equalTo(2),
484
                $this->equalTo(array('eng-GB'))
485
            )->will(
486
                $this->returnValue(array(42))
487
            );
488
489
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
490
            ->method('loadVersionedNameData')
491
            ->with(
492
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
493
            )->will(
494
                $this->returnValue(array(22))
495
            );
496
497
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
498
            ->method('extractContentFromRows')
499
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
500
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
501
502
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
503
            ->method('loadExternalFieldData')
504
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'));
505
506
        $result = $handler->load(23, 2, array('eng-GB'));
507
508
        $this->assertEquals(
509
            $result,
510
            $this->getContentFixtureForDraft()
511
        );
512
    }
513
514
    /**
515
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId
516
     */
517 View Code Duplication
    public function testLoadContentInfoByRemoteId()
518
    {
519
        $contentInfoData = array(new ContentInfo());
520
        $this->getGatewayMock()->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
521
            ->method('loadContentInfoByRemoteId')
522
            ->with(
523
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
524
            )->will(
525
                $this->returnValue(array(42))
526
            );
527
528
        $this->getMapperMock()->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
529
            ->method('extractContentInfoFromRow')
530
            ->with($this->equalTo(array(42)))
531
            ->will($this->returnValue($contentInfoData));
532
533
        $this->assertSame(
534
            $contentInfoData,
535
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
536
        );
537
    }
538
539
    /**
540
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
541
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
542
     */
543 View Code Duplication
    public function testLoadErrorNotFound()
544
    {
545
        $handler = $this->getContentHandler();
546
547
        $gatewayMock = $this->getGatewayMock();
548
549
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
550
            ->method('load')
551
            ->will(
552
                $this->returnValue(array())
553
            );
554
555
        $result = $handler->load(23, 2, array('eng-GB'));
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
556
    }
557
558
    /**
559
     * Returns a Content for {@link testCreateDraftFromVersion()}.
560
     *
561
     * @return \eZ\Publish\SPI\Persistence\Content
562
     */
563
    protected function getContentFixtureForDraft()
564
    {
565
        $content = new Content();
566
        $content->versionInfo = new VersionInfo();
567
        $content->versionInfo->versionNo = 2;
568
569
        $content->versionInfo->contentInfo = new ContentInfo();
570
571
        $field = new Field();
572
        $field->versionNo = 2;
573
574
        $content->fields = array($field);
575
576
        return $content;
577
    }
578
579
    /**
580
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent
581
     */
582
    public function testUpdateContent()
583
    {
584
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
585
586
        $gatewayMock = $this->getGatewayMock();
587
        $fieldHandlerMock = $this->getFieldHandlerMock();
588
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
589
        $contentTypeMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Type');
590
        $contentStub = new Content(
591
            array(
592
                'versionInfo' => new VersionInfo(
593
                    array(
594
                        'contentInfo' => new ContentInfo(
595
                            array(
596
                                'contentTypeId' => 4242,
597
                            )
598
                        ),
599
                    )
600
                ),
601
            )
602
        );
603
604
        $contentTypeHandlerMock->expects($this->once())
605
            ->method('load')
606
            ->with($contentStub->versionInfo->contentInfo->contentTypeId)
607
            ->will($this->returnValue($contentTypeMock));
608
609
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
610
            ->method('updateContent')
611
            ->with(14, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct'));
612
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
613
            ->method('updateVersion')
614
            ->with(14, 4, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UpdateStruct'));
615
616
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
617
            ->method('updateFields')
618
            ->with(
619
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'),
620
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\UpdateStruct'),
621
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Type')
622
            );
623
624
        $handler->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
625
            ->method('load')
626
            ->with(14, 4)
627
            ->will($this->returnValue($contentStub));
628
629
        $handler->expects($this->at(1))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
630
            ->method('load')
631
            ->with(14, 4);
632
633
        $handler->expects($this->at(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
634
            ->method('loadContentInfo')
635
            ->with(14);
636
637
        $resultContent = $handler->updateContent(
0 ignored issues
show
Unused Code introduced by
$resultContent is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
638
            14, // ContentId
639
            4, // VersionNo
640
            new UpdateStruct(
641
                array(
642
                    'creatorId' => 14,
643
                    'modificationDate' => time(),
644
                    'initialLanguageId' => 2,
645
                    'fields' => array(
646
                        new Field(
647
                            array(
648
                                'id' => 23,
649
                                'fieldDefinitionId' => 42,
650
                                'type' => 'some-type',
651
                                'value' => new FieldValue(),
652
                            )
653
                        ),
654
                        new Field(
655
                            array(
656
                                'id' => 23,
657
                                'fieldDefinitionId' => 43,
658
                                'type' => 'some-type',
659
                                'value' => new FieldValue(),
660
                            )
661
                        ),
662
                    ),
663
                )
664
            )
665
        );
666
667
        $resultContentInfo = $handler->updateMetadata(
0 ignored issues
show
Unused Code introduced by
$resultContentInfo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
668
            14, // ContentId
669
            new MetadataUpdateStruct(
670
                array(
671
                    'ownerId' => 14,
672
                    'name' => 'Some name',
673
                    'modificationDate' => time(),
674
                    'alwaysAvailable' => true,
675
                )
676
            )
677
        );
678
    }
679
680
    /**
681
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
682
     */
683
    public function testUpdateMetadata()
684
    {
685
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
686
687
        $gatewayMock = $this->getGatewayMock();
688
        $fieldHandlerMock = $this->getFieldHandlerMock();
0 ignored issues
show
Unused Code introduced by
$fieldHandlerMock is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
689
        $updateStruct = new MetadataUpdateStruct(
690
            array(
691
                'ownerId' => 14,
692
                'name' => 'Some name',
693
                'modificationDate' => time(),
694
                'alwaysAvailable' => true,
695
            )
696
        );
697
698
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
699
            ->method('updateContent')
700
            ->with(14, $updateStruct);
701
702
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
703
            ->method('loadContentInfo')
704
            ->with(14)
705
            ->will(
706
                $this->returnValue(
707
                    $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')
708
                )
709
            );
710
711
        $resultContentInfo = $handler->updateMetadata(
712
            14, // ContentId
713
            $updateStruct
714
        );
715
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo', $resultContentInfo);
716
    }
717
718
    /**
719
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
720
     */
721
    public function testUpdateMetadataUpdatesPathIdentificationString()
722
    {
723
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
724
        $locationGatewayMock = $this->getLocationGatewayMock();
725
        $slugConverterMock = $this->getSlugConverterMock();
726
        $urlAliasGatewayMock = $this->getUrlAliasGatewayMock();
727
        $gatewayMock = $this->getGatewayMock();
728
        $updateStruct = new MetadataUpdateStruct(array('mainLanguageId' => 2));
729
730
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
731
            ->method('updateContent')
732
            ->with(14, $updateStruct);
733
734
        $locationGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
735
            ->method('loadLocationDataByContent')
736
            ->with(14)
737
            ->will(
738
                $this->returnValue(
739
                    array(
740
                        array(
741
                            'node_id' => 100,
742
                            'parent_node_id' => 200,
743
                        ),
744
                    )
745
                )
746
            );
747
748
        $urlAliasGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\UrlAlias\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
749
            ->method('loadLocationEntries')
750
            ->with(100, false, 2)
751
            ->will(
752
                $this->returnValue(
753
                    array(
754
                        array(
755
                            'text' => 'slug',
756
                        ),
757
                    )
758
                )
759
            );
760
761
        $slugConverterMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...UrlAlias\SlugConverter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
762
            ->method('convert')
763
            ->with('slug', 'node_100', 'urlalias_compat')
764
            ->will($this->returnValue('transformed_slug'));
765
766
        $locationGatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
767
            ->method('updatePathIdentificationString')
768
            ->with(100, 200, 'transformed_slug');
769
770
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
771
            ->method('loadContentInfo')
772
            ->with(14)
773
            ->will(
774
                $this->returnValue(
775
                    $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\ContentInfo')
776
                )
777
            );
778
779
        $handler->updateMetadata(
780
            14, // ContentId
781
            $updateStruct
782
        );
783
    }
784
785
    /**
786
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations
787
     */
788
    public function testLoadRelations()
789
    {
790
        $handler = $this->getContentHandler();
791
792
        $gatewayMock = $this->getGatewayMock();
793
        $mapperMock = $this->getMapperMock();
794
795
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
796
            ->method('loadRelations')
797
            ->with(
798
                $this->equalTo(23),
799
                $this->equalTo(null),
800
                $this->equalTo(null)
801
            )->will(
802
                $this->returnValue(array(42))
803
            );
804
805
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
806
            ->method('extractRelationsFromRows')
807
            ->with($this->equalTo(array(42)))
808
            ->will($this->returnValue($this->getRelationFixture()));
809
810
        $result = $handler->loadRelations(23);
811
812
        $this->assertEquals(
813
            $result,
814
            $this->getRelationFixture()
815
        );
816
    }
817
818
    /**
819
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations
820
     */
821 View Code Duplication
    public function testLoadReverseRelations()
822
    {
823
        $handler = $this->getContentHandler();
824
825
        $gatewayMock = $this->getGatewayMock();
826
        $mapperMock = $this->getMapperMock();
827
828
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
829
            ->method('loadReverseRelations')
830
            ->with(
831
                $this->equalTo(23),
832
                $this->equalTo(null)
833
            )->will(
834
                $this->returnValue(array(42))
835
            );
836
837
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
838
            ->method('extractRelationsFromRows')
839
            ->with($this->equalTo(array(42)))
840
            ->will($this->returnValue($this->getRelationFixture()));
841
842
        $result = $handler->loadReverseRelations(23);
843
844
        $this->assertEquals(
845
            $result,
846
            $this->getRelationFixture()
847
        );
848
    }
849
850
    public function testAddRelation()
851
    {
852
        // expected relation object after creation
853
        $expectedRelationObject = new Relation();
854
        $expectedRelationObject->id = 42; // mocked value, not a real one
855
        $expectedRelationObject->sourceContentId = 23;
856
        $expectedRelationObject->sourceContentVersionNo = 1;
857
        $expectedRelationObject->destinationContentId = 66;
858
        $expectedRelationObject->type = RelationValue::COMMON;
859
860
        // relation create struct
861
        $relationCreateStruct = new Relation\CreateStruct();
862
        $relationCreateStruct->destinationContentId = 66;
863
        $relationCreateStruct->sourceContentId = 23;
864
        $relationCreateStruct->sourceContentVersionNo = 1;
865
        $relationCreateStruct->type = RelationValue::COMMON;
866
867
        $handler = $this->getContentHandler();
868
869
        $gatewayMock = $this->getGatewayMock();
870
        $mapperMock = $this->getMapperMock();
871
872
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
873
            ->method('createRelationFromCreateStruct')
874
            // @todo Connected with the todo above
875
            ->with($this->equalTo($relationCreateStruct))
876
            ->will($this->returnValue($expectedRelationObject));
877
878
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
879
            ->method('insertRelation')
880
            ->with($this->equalTo($relationCreateStruct))
881
            ->will(
882
                // @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods
883
                $this->returnValue(42)
884
            );
885
886
        $result = $handler->addRelation($relationCreateStruct);
887
888
        $this->assertEquals(
889
            $result,
890
            $expectedRelationObject
891
        );
892
    }
893
894
    /**
895
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation
896
     */
897
    public function testRemoveRelation()
898
    {
899
        $gatewayMock = $this->getGatewayMock();
900
901
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
902
            ->method('deleteRelation')
903
            ->with($this->equalTo(1, RelationValue::COMMON));
904
905
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
906
    }
907
908
    protected function getRelationFixture()
909
    {
910
        $relation = new Relation();
911
        $relation->sourceContentId = 23;
912
        $relation->sourceContentVersionNo = 1;
913
        $relation->destinationContentId = 69;
914
915
        return $relation;
916
    }
917
918
    /**
919
     * Returns a CreateStruct fixture.
920
     *
921
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
922
     */
923
    public function getCreateStructFixture()
924
    {
925
        $struct = new CreateStruct();
926
927
        $struct->typeId = 4242;
928
929
        $firstField = new Field();
930
        $firstField->type = 'some-type';
931
        $firstField->value = new FieldValue();
932
933
        $secondField = clone $firstField;
934
935
        $struct->fields = array(
936
            $firstField, $secondField,
937
        );
938
939
        $struct->locations = array(
940
            new LocationCreateStruct(
941
                array('parentId' => 42)
942
            ),
943
        );
944
945
        $struct->name = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-GB' => 'This is a test name') of type array<string,string,{"eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $name.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
946
            'eng-GB' => 'This is a test name',
947
        );
948
949
        return $struct;
950
    }
951
952
    /**
953
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
954
     */
955
    public function testLoadDraftsForUser()
956
    {
957
        $handler = $this->getContentHandler();
958
        $rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2));
959
960
        $gatewayMock = $this->getGatewayMock();
961
        $mapperMock = $this->getMapperMock();
962
963
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
964
            ->method('listVersionsForUser')
965
            ->with($this->equalTo(23))
966
            ->will($this->returnValue($rows));
967
968
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
969
            ->method('loadVersionedNameData')
970
            ->with($this->equalTo(array(array('id' => 42, 'version' => 2))))
971
            ->will($this->returnValue(array()));
972
973
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
974
            ->method('extractVersionInfoListFromRows')
975
            ->with($this->equalTo($rows), $this->equalTo(array()))
976
            ->will($this->returnValue(array(new VersionInfo())));
977
978
        $res = $handler->loadDraftsForUser(23);
979
980
        $this->assertEquals(
981
            array(new VersionInfo()),
982
            $res
983
        );
984
    }
985
986
    public function testListVersions()
987
    {
988
        $handler = $this->getContentHandler();
989
990
        $treeHandlerMock = $this->getTreeHandlerMock();
991
992
        $treeHandlerMock
993
            ->expects($this->once())
994
            ->method('listVersions')
995
            ->with(23)
996
            ->will($this->returnValue(array(new VersionInfo())));
997
998
        $versions = $handler->listVersions(23);
999
1000
        $this->assertEquals(
1001
            array(new VersionInfo()),
1002
            $versions
1003
        );
1004
    }
1005
1006
    public function testRemoveRawContent()
1007
    {
1008
        $handler = $this->getContentHandler();
1009
        $treeHandlerMock = $this->getTreeHandlerMock();
1010
1011
        $treeHandlerMock
1012
            ->expects($this->once())
1013
            ->method('removeRawContent')
1014
            ->with(23);
1015
1016
        $handler->removeRawContent(23);
1017
    }
1018
1019
    /**
1020
     * Test for the deleteContent() method.
1021
     *
1022
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1023
     */
1024
    public function testDeleteContentWithLocations()
1025
    {
1026
        $handlerMock = $this->getPartlyMockedHandler(array('getAllLocationIds'));
1027
        $gatewayMock = $this->getGatewayMock();
1028
        $treeHandlerMock = $this->getTreeHandlerMock();
1029
1030
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1031
            ->method('getAllLocationIds')
1032
            ->with($this->equalTo(23))
1033
            ->will($this->returnValue(array(42, 24)));
1034
        $treeHandlerMock->expects($this->exactly(2))
1035
            ->method('removeSubtree')
1036
            ->with(
1037
                $this->logicalOr(
1038
                    $this->equalTo(42),
1039
                    $this->equalTo(24)
1040
                )
1041
            );
1042
1043
        $handlerMock->deleteContent(23);
1044
    }
1045
1046
    /**
1047
     * Test for the deleteContent() method.
1048
     *
1049
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1050
     */
1051
    public function testDeleteContentWithoutLocations()
1052
    {
1053
        $handlerMock = $this->getPartlyMockedHandler(array('removeRawContent'));
1054
        $gatewayMock = $this->getGatewayMock();
1055
1056
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1057
            ->method('getAllLocationIds')
1058
            ->with($this->equalTo(23))
1059
            ->will($this->returnValue(array()));
1060
        $handlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1061
            ->method('removeRawContent')
1062
            ->with($this->equalTo(23));
1063
1064
        $handlerMock->deleteContent(23);
1065
    }
1066
1067
    /**
1068
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1069
     */
1070
    public function testDeleteVersion()
1071
    {
1072
        $handler = $this->getContentHandler();
1073
1074
        $gatewayMock = $this->getGatewayMock();
1075
        $mapperMock = $this->getMapperMock();
1076
        $locationHandlerMock = $this->getLocationGatewayMock();
1077
        $fieldHandlerMock = $this->getFieldHandlerMock();
1078
1079
        // Load VersionInfo to delete fields
1080
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1081
            ->method('loadVersionInfo')
1082
            ->with($this->equalTo(225), $this->equalTo(2))
1083
            ->will($this->returnValue(array(42)));
1084
1085
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1086
            ->method('loadVersionedNameData')
1087
            ->with($this->equalTo(array(array('id' => 225, 'version' => 2))))
1088
            ->will($this->returnValue(array(22)));
1089
1090
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1091
            ->method('extractVersionInfoListFromRows')
1092
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
1093
            ->will($this->returnValue(array(new VersionInfo())));
1094
1095
        $locationHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1096
            ->method('deleteNodeAssignment')
1097
            ->with(
1098
                $this->equalTo(225),
1099
                $this->equalTo(2)
1100
            );
1101
1102
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1103
            ->method('deleteFields')
1104
            ->with(
1105
                $this->equalTo(225),
1106
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\VersionInfo')
1107
            );
1108
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1109
            ->method('deleteRelations')
1110
            ->with(
1111
                $this->equalTo(225),
1112
                $this->equalTo(2)
1113
            );
1114
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1115
            ->method('deleteVersions')
1116
            ->with(
1117
                $this->equalTo(225),
1118
                $this->equalTo(2)
1119
            );
1120
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1121
            ->method('deleteNames')
1122
            ->with(
1123
                $this->equalTo(225),
1124
                $this->equalTo(2)
1125
            );
1126
1127
        $handler->deleteVersion(225, 2);
1128
    }
1129
1130
    /**
1131
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1132
     */
1133
    public function testCopySingleVersion()
1134
    {
1135
        $handler = $this->getPartlyMockedHandler(array('load', 'internalCreate'));
1136
        $gatewayMock = $this->getGatewayMock();
1137
        $mapperMock = $this->getMapperMock();
1138
1139
        $handler->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1140
            $this->once()
1141
        )->method(
1142
            'load'
1143
        )->with(
1144
            $this->equalTo(23),
1145
            $this->equalTo(32)
1146
        )->will(
1147
            $this->returnValue(new Content())
1148
        );
1149
1150
        $mapperMock->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1151
            $this->once()
1152
        )->method(
1153
            'createCreateStructFromContent'
1154
        )->with(
1155
            $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content')
1156
        )->will(
1157
            $this->returnValue(new CreateStruct())
1158
        );
1159
1160
        $handler->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1161
            $this->once()
1162
        )->method(
1163
            'internalCreate'
1164
        )->with(
1165
            $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'),
1166
            $this->equalTo(32)
1167
        )->will(
1168
            $this->returnValue(
1169
                new Content(
1170
                    [
1171
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1172
                    ]
1173
                )
1174
            )
1175
        );
1176
1177
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1178
            ->method('copyRelations')
1179
            ->with(
1180
                $this->equalTo(23),
1181
                $this->equalTo(24),
1182
                $this->equalTo(32)
1183
            )
1184
            ->will($this->returnValue(null));
1185
1186
        $result = $handler->copy(23, 32);
1187
1188
        $this->assertInstanceOf(
1189
            'eZ\\Publish\\SPI\\Persistence\\Content',
1190
            $result
1191
        );
1192
    }
1193
1194
    /**
1195
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1196
     */
1197
    public function testCopyAllVersions()
1198
    {
1199
        $handler = $this->getPartlyMockedHandler(
1200
            array(
1201
                'loadContentInfo',
1202
                'load',
1203
                'internalCreate',
1204
                'listVersions',
1205
            )
1206
        );
1207
        $gatewayMock = $this->getGatewayMock();
1208
        $mapperMock = $this->getMapperMock();
1209
        $fieldHandlerMock = $this->getFieldHandlerMock();
1210
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1211
        $contentTypeMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Type');
1212
        $time = time();
1213
        $createStructStub = new CreateStruct(
1214
            array(
1215
                'modified' => $time,
1216
                'typeId' => 4242,
1217
            )
1218
        );
1219
1220
        $contentTypeHandlerMock->expects($this->once())
1221
            ->method('load')
1222
            ->with($createStructStub->typeId)
1223
            ->will($this->returnValue($contentTypeMock));
1224
1225
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1226
            ->method('loadContentInfo')
1227
            ->with($this->equalTo(23))
1228
            ->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2))));
1229
1230
        $handler->expects($this->at(1))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1231
            ->method('load')
1232
            ->with($this->equalTo(23), $this->equalTo(2))
1233
            ->will($this->returnValue(new Content()));
1234
1235
        $mapperMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...\Legacy\Content\Mapper>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1236
            ->method('createCreateStructFromContent')
1237
            ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content'))
1238
            ->will(
1239
                $this->returnValue($createStructStub)
1240
            );
1241
1242
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1243
            ->method('internalCreate')
1244
            ->with(
1245
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\CreateStruct'),
1246
                $this->equalTo(2)
1247
            )->will(
1248
                $this->returnValue(
1249
                    new Content(
1250
                        array(
1251
                            'versionInfo' => new VersionInfo(
1252
                                array(
1253
                                    'contentInfo' => new ContentInfo(array('id' => 24)),
1254
                                )
1255
                            ),
1256
                        )
1257
                    )
1258
                )
1259
            );
1260
1261
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1262
            ->method('listVersions')
1263
            ->with($this->equalTo(23))
1264
            ->will(
1265
                $this->returnValue(
1266
                    array(
1267
                        new VersionInfo(array('versionNo' => 1)),
1268
                        new VersionInfo(array('versionNo' => 2)),
1269
                    )
1270
                )
1271
            );
1272
1273
        $versionInfo = new VersionInfo(
1274
            array(
1275
                'names' => array('eng-US' => 'Test'),
1276
                'contentInfo' => new ContentInfo(
1277
                    array(
1278
                        'id' => 24,
1279
                        'alwaysAvailable' => true,
1280
                    )
1281
                ),
1282
            )
1283
        );
1284
        $handler->expects($this->at(4))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1285
            ->method('load')
1286
            ->with($this->equalTo(23), $this->equalTo(1))
1287
            ->will(
1288
                $this->returnValue(
1289
                    new Content(
1290
                        array(
1291
                            'versionInfo' => $versionInfo,
1292
                            'fields' => array(),
1293
                        )
1294
                    )
1295
                )
1296
            );
1297
1298
        $versionInfo->creationDate = $time;
1299
        $versionInfo->modificationDate = $time;
1300
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1301
            ->method('insertVersion')
1302
            ->with(
1303
                $this->equalTo($versionInfo),
1304
                $this->isType('array')
1305
            )->will($this->returnValue(42));
1306
1307
        $versionInfo = clone $versionInfo;
1308
        $versionInfo->id = 42;
1309
        $fieldHandlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...y\Content\FieldHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1310
            ->method('createNewFields')
1311
            ->with(
1312
                $this->equalTo(
1313
                    new Content(
1314
                        array(
1315
                            'versionInfo' => $versionInfo,
1316
                            'fields' => array(),
1317
                        )
1318
                    )
1319
                ),
1320
                $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Type')
1321
            );
1322
1323
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1324
            ->method('setName')
1325
            ->with(
1326
                $this->equalTo(24),
1327
                $this->equalTo(1),
1328
                $this->equalTo('Test'),
1329
                $this->equalTo('eng-US')
1330
            );
1331
1332
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1333
            ->method('copyRelations')
1334
            ->with(
1335
                $this->equalTo(23),
1336
                $this->equalTo(24),
1337
                $this->equalTo(null)
1338
            )
1339
            ->will($this->returnValue(null));
1340
1341
        $result = $handler->copy(23);
1342
1343
        $this->assertInstanceOf(
1344
            'eZ\\Publish\\SPI\\Persistence\\Content',
1345
            $result
1346
        );
1347
    }
1348
1349
    /**
1350
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1351
     */
1352
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1353
    {
1354
        $handler = $this->getContentHandler();
1355
1356
        $treeHandlerMock = $this->getTreeHandlerMock();
1357
        $treeHandlerMock
1358
            ->expects($this->once())
1359
            ->method('loadContentInfo')
1360
            ->with($this->equalTo(23))
1361
            ->will(
1362
                $this->throwException(new NotFoundException('ContentInfo', 23))
1363
            );
1364
1365
        $handler->copy(23);
1366
    }
1367
1368
    /**
1369
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1370
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1371
     */
1372 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1373
    {
1374
        $handler = $this->getContentHandler();
1375
1376
        $gatewayMock = $this->getGatewayMock();
1377
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1378
            ->method('load')
1379
            ->with($this->equalTo(23, 32))
1380
            ->will($this->returnValue(array()));
1381
1382
        $result = $handler->copy(23, 32);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1383
    }
1384
1385
    /**
1386
     * @covers eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1387
     */
1388 View Code Duplication
    public function testSetStatus()
1389
    {
1390
        $handler = $this->getContentHandler();
1391
1392
        $mapperMock = $this->getMapperMock();
0 ignored issues
show
Unused Code introduced by
$mapperMock is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1393
        $gatewayMock = $this->getGatewayMock();
1394
1395
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1396
            ->method('setStatus')
1397
            ->with(23, 5, 2)
1398
            ->will($this->returnValue(true));
1399
1400
        $this->assertTrue(
1401
            $handler->setStatus(23, 2, 5)
1402
        );
1403
    }
1404
1405
    /**
1406
     * Returns the handler to test.
1407
     *
1408
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1409
     */
1410
    protected function getContentHandler()
1411
    {
1412
        if (!isset($this->contentHandler)) {
1413
            $this->contentHandler = new Handler(
1414
                $this->getGatewayMock(),
1415
                $this->getLocationGatewayMock(),
1416
                $this->getMapperMock(),
1417
                $this->getFieldHandlerMock(),
1418
                $this->getSlugConverterMock(),
1419
                $this->getUrlAliasGatewayMock(),
1420
                $this->getContentTypeHandlerMock(),
0 ignored issues
show
Bug introduced by
It seems like $this->getContentTypeHandlerMock() targeting eZ\Publish\Core\Persiste...ontentTypeHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Persiste...\Handler::__construct() does only seem to accept object<eZ\Publish\SPI\Pe...e\Content\Type\Handler>, 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...
1421
                $this->getTreeHandlerMock()
0 ignored issues
show
Bug introduced by
It seems like $this->getTreeHandlerMock() targeting eZ\Publish\Core\Persiste...t::getTreeHandlerMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, eZ\Publish\Core\Persiste...\Handler::__construct() does only seem to accept object<eZ\Publish\Core\P...cy\Content\TreeHandler>, 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...
1422
            );
1423
        }
1424
1425
        return $this->contentHandler;
1426
    }
1427
1428
    /**
1429
     * Returns the handler to test with $methods mocked.
1430
     *
1431
     * @param string[] $methods
1432
     *
1433
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1434
     */
1435
    protected function getPartlyMockedHandler(array $methods)
1436
    {
1437
        $mock = $this->getMock(
1438
            '\\eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Handler',
1439
            $methods,
1440
            array(
1441
                $this->getGatewayMock(),
1442
                $this->getLocationGatewayMock(),
1443
                $this->getMapperMock(),
1444
                $this->getFieldHandlerMock(),
1445
                $this->getSlugConverterMock(),
1446
                $this->getUrlAliasGatewayMock(),
1447
                $this->getContentTypeHandlerMock(),
1448
                $this->getTreeHandlerMock(),
1449
            )
1450
        );
1451
1452
        return $mock;
1453
    }
1454
1455
    /**
1456
     * Returns a TreeHandler mock.
1457
     *
1458
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1459
     */
1460
    protected function getTreeHandlerMock()
1461
    {
1462
        if (!isset($this->treeHandlerMock)) {
1463
            $this->treeHandlerMock = $this->getMock(
1464
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\TreeHandler',
1465
                array(),
1466
                array(),
1467
                '',
1468
                false
1469
            );
1470
        }
1471
1472
        return $this->treeHandlerMock;
1473
    }
1474
1475
    /**
1476
     * Returns a ContentTypeHandler mock.
1477
     *
1478
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1479
     */
1480 View Code Duplication
    protected function getContentTypeHandlerMock()
1481
    {
1482
        if (!isset($this->contentTypeHandlerMock)) {
1483
            $this->contentTypeHandlerMock = $this->getMock(
1484
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Type\\Handler',
1485
                array(),
1486
                array(),
1487
                '',
1488
                false
1489
            );
1490
        }
1491
1492
        return $this->contentTypeHandlerMock;
1493
    }
1494
1495
    /**
1496
     * Returns a FieldHandler mock.
1497
     *
1498
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1499
     */
1500 View Code Duplication
    protected function getFieldHandlerMock()
1501
    {
1502
        if (!isset($this->fieldHandlerMock)) {
1503
            $this->fieldHandlerMock = $this->getMock(
1504
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\FieldHandler',
1505
                array(),
1506
                array(),
1507
                '',
1508
                false
1509
            );
1510
        }
1511
1512
        return $this->fieldHandlerMock;
1513
    }
1514
1515
    /**
1516
     * Returns a Mapper mock.
1517
     *
1518
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1519
     */
1520 View Code Duplication
    protected function getMapperMock()
1521
    {
1522
        if (!isset($this->mapperMock)) {
1523
            $this->mapperMock = $this->getMock(
1524
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Mapper',
1525
                array(),
1526
                array(),
1527
                '',
1528
                false
1529
            );
1530
        }
1531
1532
        return $this->mapperMock;
1533
    }
1534
1535
    /**
1536
     * Returns a Location Gateway mock.
1537
     *
1538
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1539
     */
1540
    protected function getLocationGatewayMock()
1541
    {
1542
        if (!isset($this->locationGatewayMock)) {
1543
            $this->locationGatewayMock = $this->getMock(
1544
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway'
1545
            );
1546
        }
1547
1548
        return $this->locationGatewayMock;
1549
    }
1550
1551
    /**
1552
     * Returns a Content Type gateway mock.
1553
     *
1554
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1555
     */
1556
    protected function getTypeGatewayMock()
1557
    {
1558
        if (!isset($this->typeGatewayMock)) {
1559
            $this->typeGatewayMock = $this->getMock(
1560
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Type\\Gateway'
1561
            );
1562
        }
1563
1564
        return $this->typeGatewayMock;
1565
    }
1566
1567
    /**
1568
     * Returns a mock object for the Content Gateway.
1569
     *
1570
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
1571
     */
1572
    protected function getGatewayMock()
1573
    {
1574
        if (!isset($this->gatewayMock)) {
1575
            $this->gatewayMock = $this->getMockForAbstractClass(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...acy\\Content\\Gateway') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...Legacy\Content\Gateway> of property $gatewayMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1576
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Gateway'
1577
            );
1578
        }
1579
1580
        return $this->gatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->gatewayMock; of type PHPUnit_Framework_MockOb...\Legacy\Content\Gateway adds the type PHPUnit_Framework_MockObject_MockObject to the return on line 1580 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...lerTest::getGatewayMock of type eZ\Publish\Core\Persistence\Legacy\Content\Gateway.
Loading history...
1581
    }
1582
1583
    /**
1584
     * Returns a mock object for the UrlAlias Handler.
1585
     *
1586
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1587
     */
1588
    protected function getSlugConverterMock()
1589
    {
1590
        if (!isset($this->slugConverterMock)) {
1591
            $this->slugConverterMock = $this->getMock(
1592
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\SlugConverter',
1593
                array(),
1594
                array(),
1595
                '',
1596
                false
1597
            );
1598
        }
1599
1600
        return $this->slugConverterMock;
1601
    }
1602
1603
    /**
1604
     * Returns a mock object for the UrlAlias Gateway.
1605
     *
1606
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1607
     */
1608
    protected function getUrlAliasGatewayMock()
1609
    {
1610
        if (!isset($this->urlAliasGatewayMock)) {
1611
            $this->urlAliasGatewayMock = $this->getMockForAbstractClass(
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...nt\\UrlAlias\\Gateway') of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\UrlAlias\Gateway> of property $urlAliasGatewayMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1612
                'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\UrlAlias\\Gateway'
1613
            );
1614
        }
1615
1616
        return $this->urlAliasGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->urlAliasGatewayMock; of type PHPUnit_Framework_MockOb...ontent\UrlAlias\Gateway adds the type PHPUnit_Framework_MockObject_MockObject to the return on line 1616 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...:getUrlAliasGatewayMock of type eZ\Publish\Core\Persiste...ontent\UrlAlias\Gateway.
Loading history...
1617
    }
1618
}
1619