Completed
Push — master ( 0f847f...a708aa )
by
unknown
61:46 queued 39:27
created

testUpdateMetadataUpdatesPathIdentificationString()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 63
rs 8.8072
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * File 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
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\SPI\Persistence\Content;
13
use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
14
use eZ\Publish\SPI\Persistence\Content\Type;
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\TreeHandler;
25
use eZ\Publish\Core\Persistence\Legacy\Content\Handler;
26
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
27
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
28
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
29
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
30
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
31
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
32
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway;
33
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
34
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper;
35
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler;
36
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
37
38
/**
39
 * Test case for Content Handler.
40
 */
41
class ContentHandlerTest extends TestCase
42
{
43
    /**
44
     * Content handler to test.
45
     *
46
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler
47
     */
48
    protected $contentHandler;
49
50
    /**
51
     * Gateway mock.
52
     *
53
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
54
     */
55
    protected $gatewayMock;
56
57
    /**
58
     * Location gateway mock.
59
     *
60
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
61
     */
62
    protected $locationGatewayMock;
63
64
    /**
65
     * Type gateway mock.
66
     *
67
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
68
     */
69
    protected $typeGatewayMock;
70
71
    /**
72
     * Mapper mock.
73
     *
74
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
75
     */
76
    protected $mapperMock;
77
78
    /**
79
     * Field handler mock.
80
     *
81
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
82
     */
83
    protected $fieldHandlerMock;
84
85
    /**
86
     * Location handler mock.
87
     *
88
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
89
     */
90
    protected $treeHandlerMock;
91
92
    /**
93
     * Slug converter mock.
94
     *
95
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
96
     */
97
    protected $slugConverterMock;
98
99
    /**
100
     * Location handler mock.
101
     *
102
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
103
     */
104
    protected $urlAliasGatewayMock;
105
106
    /**
107
     * ContentType handler mock.
108
     *
109
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
110
     */
111
    protected $contentTypeHandlerMock;
112
113
    /**
114
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::__construct
115
     */
116 View Code Duplication
    public function testCtor()
117
    {
118
        $handler = $this->getContentHandler();
119
120
        $this->assertAttributeSame(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
            $this->getGatewayMock(),
122
            'contentGateway',
123
            $handler
124
        );
125
        $this->assertAttributeSame(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
126
            $this->getMapperMock(),
127
            'mapper',
128
            $handler
129
        );
130
        $this->assertAttributeSame(
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3338

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
131
            $this->getFieldHandlerMock(),
132
            'fieldHandler',
133
            $handler
134
        );
135
        // @todo Assert missing properties
136
    }
137
138
    /**
139
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::create
140
     *
141
     * @todo Current method way to complex to test, refactor!
142
     */
143
    public function testCreate()
144
    {
145
        $handler = $this->getContentHandler();
146
147
        $mapperMock = $this->getMapperMock();
148
        $gatewayMock = $this->getGatewayMock();
149
        $fieldHandlerMock = $this->getFieldHandlerMock();
150
        $locationMock = $this->getLocationGatewayMock();
151
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
152
        $contentTypeMock = $this->createMock(Type::class);
153
        $createStruct = $this->getCreateStructFixture();
154
155
        $contentTypeHandlerMock->expects($this->once())
156
            ->method('load')
157
            ->with($createStruct->typeId)
158
            ->will($this->returnValue($contentTypeMock));
159
160
        $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...
161
            ->method('createVersionInfoFromCreateStruct')
162
            ->with(
163
                $this->isInstanceOf(
164
                    CreateStruct::class
165
                )
166
            )->will(
167
                $this->returnValue(
168
                    new VersionInfo(
169
                        array(
170
                            'names' => array(),
171
                            'contentInfo' => new ContentInfo(),
172
                        )
173
                    )
174
                )
175
            );
176
177
        $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...
178
            ->method('insertContentObject')
179
            ->with(
180
                $this->isInstanceOf(CreateStruct::class)
181
            )->will($this->returnValue(23));
182
183
        $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...
184
            ->method('insertVersion')
185
            ->with(
186
                $this->isInstanceOf(VersionInfo::class),
187
                $this->isType('array')
188
            )->will($this->returnValue(1));
189
190
        $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...
191
            ->method('createNewFields')
192
            ->with(
193
                $this->isInstanceOf(Content::class),
194
                $this->isInstanceOf(Type::class)
195
            );
196
197
        $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...
198
            ->method('createNodeAssignment')
199
            ->with(
200
                $this->isInstanceOf(
201
                    LocationCreateStruct::class
202
                ),
203
                $this->equalTo(42),
204
                $this->equalTo(3) // Location\Gateway::NODE_ASSIGNMENT_OP_CODE_CREATE
205
            );
206
207
        $res = $handler->create($createStruct);
208
209
        // @todo Make subsequent tests
210
211
        $this->assertInstanceOf(
212
            Content::class,
213
            $res,
214
            'Content not created'
215
        );
216
        $this->assertEquals(
217
            23,
218
            $res->versionInfo->contentInfo->id,
219
            'Content ID not set correctly'
220
        );
221
        $this->assertInstanceOf(
222
            VersionInfo::class,
223
            $res->versionInfo,
224
            'Version infos not created'
225
        );
226
        $this->assertEquals(
227
            1,
228
            $res->versionInfo->id,
229
            'Version ID not set correctly'
230
        );
231
        $this->assertEquals(
232
            2,
233
            count($res->fields),
234
            'Fields not set correctly in version'
235
        );
236
    }
237
238
    /**
239
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
240
     */
241
    public function testPublishFirstVersion()
242
    {
243
        $handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus'));
244
245
        $gatewayMock = $this->getGatewayMock();
246
        $mapperMock = $this->getMapperMock();
247
        $locationMock = $this->getLocationGatewayMock();
248
        $fieldHandlerMock = $this->getFieldHandlerMock();
249
        $metadataUpdateStruct = new MetadataUpdateStruct();
250
251
        $handler->expects($this->at(0))
252
            ->method('loadVersionInfo')
253
            ->with(23, 1)
254
            ->will(
255
                $this->returnValue(
256
                    new VersionInfo(array('versionNo' => 1, 'contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
257
                )
258
            );
259
260
        $contentRows = [['ezcontentobject_version_version' => 1]];
261
262
        $gatewayMock->expects($this->exactly(3))
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...
263
            ->method('load')
264
            ->withConsecutive(
265
                [
266
                    $this->equalTo(23),
267
                    $this->equalTo(null),
268
                    $this->equalTo(null),
269
                ],
270
                [
271
                    $this->equalTo(23),
272
                    $this->equalTo(1),
273
                    $this->equalTo(null),
274
                ],
275
                [
276
                    $this->equalTo(23),
277
                    $this->equalTo(1),
278
                    $this->equalTo(null),
279
                ]
280
            )->willReturn($contentRows);
281
282
        $gatewayMock->expects($this->exactly(3))
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...
283
            ->method('loadVersionedNameData')
284
            ->with(
285
                $this->equalTo(array(array('id' => 23, 'version' => 1)))
286
            )->will(
287
                $this->returnValue(array(22))
288
            );
289
290
        $mapperMock->expects($this->exactly(3))
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...
291
            ->method('extractContentFromRows')
292
            ->with($this->equalTo($contentRows), $this->equalTo(array(22)))
293
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
294
295
        $fieldHandlerMock->expects($this->exactly(3))
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...
296
            ->method('loadExternalFieldData')
297
            ->with($this->isInstanceOf(Content::class));
298
299
        $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...
300
            ->expects($this->once())
301
            ->method('updateContent')
302
            ->with(23, $metadataUpdateStruct);
303
304
        $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...
305
            ->expects($this->once())
306
            ->method('createLocationsFromNodeAssignments')
307
            ->with(23, 1);
308
309
        $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...
310
            ->expects($this->once())
311
            ->method('updateLocationsContentVersionNo')
312
            ->with(23, 1);
313
314
        $handler
315
            ->expects($this->once())
316
            ->method('setStatus')
317
            ->with(23, VersionInfo::STATUS_PUBLISHED, 1);
318
319
        $handler->publish(23, 1, $metadataUpdateStruct);
320
    }
321
322
    /**
323
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
324
     */
325
    public function testPublish()
326
    {
327
        $handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus'));
328
329
        $gatewayMock = $this->getGatewayMock();
330
        $mapperMock = $this->getMapperMock();
331
        $locationMock = $this->getLocationGatewayMock();
332
        $fieldHandlerMock = $this->getFieldHandlerMock();
333
        $metadataUpdateStruct = new MetadataUpdateStruct();
334
335
        $handler->expects($this->at(0))
336
            ->method('loadVersionInfo')
337
            ->with(23, 2)
338
            ->will(
339
                $this->returnValue(
340
                    new VersionInfo(array('versionNo' => 2, 'contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
341
                )
342
            );
343
344
        $handler
345
            ->expects($this->at(1))
346
            ->method('setStatus')
347
            ->with(23, VersionInfo::STATUS_ARCHIVED, 1);
348
349
        $contentRows = [['ezcontentobject_version_version' => 2]];
350
351
        $gatewayMock->expects($this->exactly(2))
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...
352
            ->method('load')
353
            ->withConsecutive(
354
                [
355
                    $this->equalTo(23),
356
                    $this->equalTo(null),
357
                    $this->equalTo(null),
358
                ],
359
                [
360
                    $this->equalTo(23),
361
                    $this->equalTo(2),
362
                    $this->equalTo(null),
363
                ]
364
            )->willReturn($contentRows);
365
366
        $gatewayMock->expects($this->exactly(2))
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...
367
            ->method('loadVersionedNameData')
368
            ->with(
369
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
370
            )->will(
371
                $this->returnValue(array(22))
372
            );
373
374
        $mapperMock->expects($this->exactly(2))
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...
375
            ->method('extractContentFromRows')
376
            ->with($this->equalTo($contentRows), $this->equalTo(array(22)))
377
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
378
379
        $fieldHandlerMock->expects($this->exactly(2))
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...
380
            ->method('loadExternalFieldData')
381
            ->with($this->isInstanceOf(Content::class));
382
383
        $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...
384
            ->expects($this->once())
385
            ->method('updateContent')
386
            ->with(23, $metadataUpdateStruct, $this->isInstanceOf(VersionInfo::class));
387
388
        $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...
389
            ->expects($this->once())
390
            ->method('createLocationsFromNodeAssignments')
391
            ->with(23, 2);
392
393
        $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...
394
            ->expects($this->once())
395
            ->method('updateLocationsContentVersionNo')
396
            ->with(23, 2);
397
398
        $handler
399
            ->expects($this->at(2))
400
            ->method('setStatus')
401
            ->with(23, VersionInfo::STATUS_PUBLISHED, 2);
402
403
        $handler->publish(23, 2, $metadataUpdateStruct);
404
    }
405
406
    /**
407
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::createDraftFromVersion
408
     */
409
    public function testCreateDraftFromVersion()
410
    {
411
        $handler = $this->getPartlyMockedHandler(array('load'));
412
413
        $mapperMock = $this->getMapperMock();
414
        $gatewayMock = $this->getGatewayMock();
415
        $fieldHandlerMock = $this->getFieldHandlerMock();
416
417
        $handler->expects($this->once())
418
            ->method('load')
419
            ->with(23, 2)
420
            ->will($this->returnValue($this->getContentFixtureForDraft()));
421
422
        $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...
423
            ->method('createVersionInfoForContent')
424
            ->with(
425
                $this->isInstanceOf(Content::class),
426
                $this->equalTo(3),
427
                $this->equalTo(14)
428
            )->will(
429
                $this->returnValue(
430
                    new VersionInfo(
431
                        array(
432
                            'names' => array(),
433
                            'versionNo' => 3,
434
                        )
435
                    )
436
                )
437
            );
438
439
        $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...
440
            ->method('insertVersion')
441
            ->with(
442
                $this->isInstanceOf(VersionInfo::class),
443
                $this->getContentFixtureForDraft()->fields
444
            )->will($this->returnValue(42));
445
446
        $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...
447
            ->method('getLastVersionNumber')
448
            ->with($this->equalTo(23))
449
            ->will($this->returnValue(2));
450
451
        $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...
452
            ->method('createExistingFieldsInNewVersion')
453
            ->with($this->isInstanceOf(Content::class));
454
455
        $relationData = array(
456
            array(
457
                'ezcontentobject_link_contentclassattribute_id' => 0,
458
                'ezcontentobject_link_to_contentobject_id' => 42,
459
                'ezcontentobject_link_relation_type' => 1,
460
            ),
461
        );
462
463
        $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...
464
            ->method('loadRelations')
465
            ->with(
466
                $this->equalTo(23),
467
                $this->equalTo(2)
468
            )
469
            ->will($this->returnValue($relationData));
470
471
        $relationStruct = new RelationCreateStruct(
472
            array(
473
                'sourceContentId' => 23,
474
                'sourceContentVersionNo' => 3,
475
                'sourceFieldDefinitionId' => 0,
476
                'destinationContentId' => 42,
477
                'type' => 1,
478
            )
479
        );
480
481
        $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...
482
            ->method('insertRelation')
483
            ->with($this->equalTo($relationStruct));
484
485
        $result = $handler->createDraftFromVersion(23, 2, 14);
486
487
        $this->assertInstanceOf(
488
            Content::class,
489
            $result
490
        );
491
        $this->assertEquals(
492
            42,
493
            $result->versionInfo->id
494
        );
495
    }
496
497
    /**
498
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
499
     */
500
    public function testLoad()
501
    {
502
        $handler = $this->getContentHandler();
503
504
        $gatewayMock = $this->getGatewayMock();
505
        $mapperMock = $this->getMapperMock();
506
        $fieldHandlerMock = $this->getFieldHandlerMock();
507
508
        $contentRows = [['ezcontentobject_version_version' => 2]];
509
510
        $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...
511
            ->method('load')
512
            ->with(
513
                $this->equalTo(23),
514
                $this->equalTo(2),
515
                $this->equalTo(array('eng-GB'))
516
            )->will(
517
                $this->returnValue($contentRows)
518
            );
519
520
        $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...
521
            ->method('loadVersionedNameData')
522
            ->with(
523
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
524
            )->will(
525
                $this->returnValue(array(22))
526
            );
527
528
        $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...
529
            ->method('extractContentFromRows')
530
            ->with($this->equalTo($contentRows), $this->equalTo(array(22)))
531
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
532
533
        $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...
534
            ->method('loadExternalFieldData')
535
            ->with($this->isInstanceOf(Content::class));
536
537
        $result = $handler->load(23, 2, array('eng-GB'));
538
539
        $this->assertEquals(
540
            $result,
541
            $this->getContentFixtureForDraft()
542
        );
543
    }
544
545
    /**
546
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentList
547
     */
548
    public function testLoadContentList()
549
    {
550
        $handler = $this->getContentHandler();
551
552
        $gatewayMock = $this->getGatewayMock();
553
        $mapperMock = $this->getMapperMock();
554
        $fieldHandlerMock = $this->getFieldHandlerMock();
555
        $contentRows = [
556
            ['ezcontentobject_id' => 2, 'ezcontentobject_version_version' => 2],
557
            ['ezcontentobject_id' => 3, 'ezcontentobject_version_version' => 1],
558
        ];
559
        $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...
560
            ->method('loadContentList')
561
            ->with([2, 3], ['eng-GB', 'eng-US'])
562
            ->willReturn($contentRows);
563
564
        $nameDataRows = [
565
            ['ezcontentobject_name_contentobject_id' => 2, 'ezcontentobject_name_content_version' => 2],
566
            ['ezcontentobject_name_contentobject_id' => 3, 'ezcontentobject_name_content_version' => 1],
567
        ];
568
569
        $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...
570
            ->method('loadVersionedNameData')
571
            ->with($this->equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]]))
572
            ->willReturn($nameDataRows);
573
574
        $expected = [
575
            2 => $this->getContentFixtureForDraft(2, 2),
576
            3 => $this->getContentFixtureForDraft(3, 1),
577
        ];
578
        $mapperMock->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\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...
579
            ->method('extractContentFromRows')
580
            ->with($this->equalTo([$contentRows[0]]), $this->equalTo([$nameDataRows[0]]))
581
            ->willReturn([$expected[2]]);
582
583
        $mapperMock->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\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...
584
            ->method('extractContentFromRows')
585
            ->with($this->equalTo([$contentRows[1]]), $this->equalTo([$nameDataRows[1]]))
586
            ->willReturn([$expected[3]]);
587
588
        $fieldHandlerMock->expects($this->exactly(2))
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...
589
            ->method('loadExternalFieldData')
590
            ->with($this->isInstanceOf(Content::class));
591
592
        $result = $handler->loadContentList([2, 3], ['eng-GB', 'eng-US']);
593
594
        $this->assertEquals(
595
            $expected,
596
            $result
597
        );
598
    }
599
600
    /**
601
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId
602
     */
603 View Code Duplication
    public function testLoadContentInfoByRemoteId()
604
    {
605
        $contentInfoData = array(new ContentInfo());
606
        $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...
607
            ->method('loadContentInfoByRemoteId')
608
            ->with(
609
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
610
            )->will(
611
                $this->returnValue(array(42))
612
            );
613
614
        $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...
615
            ->method('extractContentInfoFromRow')
616
            ->with($this->equalTo(array(42)))
617
            ->will($this->returnValue($contentInfoData));
618
619
        $this->assertSame(
620
            $contentInfoData,
621
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
622
        );
623
    }
624
625
    /**
626
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
627
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
628
     */
629 View Code Duplication
    public function testLoadErrorNotFound()
630
    {
631
        $handler = $this->getContentHandler();
632
633
        $gatewayMock = $this->getGatewayMock();
634
635
        $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...
636
            ->method('load')
637
            ->will(
638
                $this->returnValue(array())
639
            );
640
641
        $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...
642
    }
643
644
    /**
645
     * Returns a Content for {@link testCreateDraftFromVersion()}.
646
     *
647
     * @param int $id Optional id
648
     * @param int $versionNo Optional version number
649
     *
650
     * @return \eZ\Publish\SPI\Persistence\Content
651
     */
652
    protected function getContentFixtureForDraft(int $id = 23, int $versionNo = 2)
653
    {
654
        $content = new Content();
655
        $content->versionInfo = new VersionInfo();
656
        $content->versionInfo->versionNo = $versionNo;
657
658
        $content->versionInfo->contentInfo = new ContentInfo(['id' => $id]);
659
660
        $field = new Field();
661
        $field->versionNo = $versionNo;
662
663
        $content->fields = [$field];
664
665
        return $content;
666
    }
667
668
    /**
669
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent
670
     */
671
    public function testUpdateContent()
672
    {
673
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
674
675
        $gatewayMock = $this->getGatewayMock();
676
        $fieldHandlerMock = $this->getFieldHandlerMock();
677
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
678
        $contentTypeMock = $this->createMock(Type::class);
679
        $contentStub = new Content(
680
            array(
681
                'versionInfo' => new VersionInfo(
682
                    array(
683
                        'contentInfo' => new ContentInfo(
684
                            array(
685
                                'contentTypeId' => 4242,
686
                            )
687
                        ),
688
                    )
689
                ),
690
            )
691
        );
692
693
        $contentTypeHandlerMock->expects($this->once())
694
            ->method('load')
695
            ->with($contentStub->versionInfo->contentInfo->contentTypeId)
696
            ->will($this->returnValue($contentTypeMock));
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, $this->isInstanceOf(MetadataUpdateStruct::class));
701
        $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...
702
            ->method('updateVersion')
703
            ->with(14, 4, $this->isInstanceOf(UpdateStruct::class));
704
705
        $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...
706
            ->method('updateFields')
707
            ->with(
708
                $this->isInstanceOf(Content::class),
709
                $this->isInstanceOf(UpdateStruct::class),
710
                $this->isInstanceOf(Type::class)
711
            );
712
713
        $handler->expects($this->at(0))
714
            ->method('load')
715
            ->with(14, 4)
716
            ->will($this->returnValue($contentStub));
717
718
        $handler->expects($this->at(1))
719
            ->method('load')
720
            ->with(14, 4);
721
722
        $handler->expects($this->at(2))
723
            ->method('loadContentInfo')
724
            ->with(14);
725
726
        $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...
727
            14, // ContentId
728
            4, // VersionNo
729
            new UpdateStruct(
730
                array(
731
                    'creatorId' => 14,
732
                    'modificationDate' => time(),
733
                    'initialLanguageId' => 2,
734
                    'fields' => array(
735
                        new Field(
736
                            array(
737
                                'id' => 23,
738
                                'fieldDefinitionId' => 42,
739
                                'type' => 'some-type',
740
                                'value' => new FieldValue(),
741
                            )
742
                        ),
743
                        new Field(
744
                            array(
745
                                'id' => 23,
746
                                'fieldDefinitionId' => 43,
747
                                'type' => 'some-type',
748
                                'value' => new FieldValue(),
749
                            )
750
                        ),
751
                    ),
752
                )
753
            )
754
        );
755
756
        $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...
757
            14, // ContentId
758
            new MetadataUpdateStruct(
759
                array(
760
                    'ownerId' => 14,
761
                    'name' => 'Some name',
762
                    'modificationDate' => time(),
763
                    'alwaysAvailable' => true,
764
                )
765
            )
766
        );
767
    }
768
769
    /**
770
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
771
     */
772
    public function testUpdateMetadata()
773
    {
774
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
775
776
        $gatewayMock = $this->getGatewayMock();
777
        $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...
778
        $updateStruct = new MetadataUpdateStruct(
779
            array(
780
                'ownerId' => 14,
781
                'name' => 'Some name',
782
                'modificationDate' => time(),
783
                'alwaysAvailable' => true,
784
            )
785
        );
786
787
        $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...
788
            ->method('updateContent')
789
            ->with(14, $updateStruct);
790
791
        $handler->expects($this->once())
792
            ->method('loadContentInfo')
793
            ->with(14)
794
            ->will(
795
                $this->returnValue(
796
                    $this->createMock(ContentInfo::class)
797
                )
798
            );
799
800
        $resultContentInfo = $handler->updateMetadata(
801
            14, // ContentId
802
            $updateStruct
803
        );
804
        self::assertInstanceOf(ContentInfo::class, $resultContentInfo);
805
    }
806
807
    /**
808
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
809
     */
810
    public function testUpdateMetadataUpdatesPathIdentificationString()
811
    {
812
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
813
        $locationGatewayMock = $this->getLocationGatewayMock();
814
        $slugConverterMock = $this->getSlugConverterMock();
815
        $urlAliasGatewayMock = $this->getUrlAliasGatewayMock();
816
        $gatewayMock = $this->getGatewayMock();
817
        $updateStruct = new MetadataUpdateStruct(array('mainLanguageId' => 2));
818
819
        $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...
820
            ->method('updateContent')
821
            ->with(14, $updateStruct);
822
823
        $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...
824
            ->method('loadLocationDataByContent')
825
            ->with(14)
826
            ->will(
827
                $this->returnValue(
828
                    array(
829
                        array(
830
                            'node_id' => 100,
831
                            'parent_node_id' => 200,
832
                        ),
833
                    )
834
                )
835
            );
836
837
        $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...
838
            ->method('loadLocationEntries')
839
            ->with(100, false, 2)
840
            ->will(
841
                $this->returnValue(
842
                    array(
843
                        array(
844
                            'text' => 'slug',
845
                        ),
846
                    )
847
                )
848
            );
849
850
        $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...
851
            ->method('convert')
852
            ->with('slug', 'node_100', 'urlalias_compat')
853
            ->will($this->returnValue('transformed_slug'));
854
855
        $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...
856
            ->method('updatePathIdentificationString')
857
            ->with(100, 200, 'transformed_slug');
858
859
        $handler->expects($this->once())
860
            ->method('loadContentInfo')
861
            ->with(14)
862
            ->will(
863
                $this->returnValue(
864
                    $this->createMock(ContentInfo::class)
865
                )
866
            );
867
868
        $handler->updateMetadata(
869
            14, // ContentId
870
            $updateStruct
871
        );
872
    }
873
874
    /**
875
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations
876
     */
877
    public function testLoadRelations()
878
    {
879
        $handler = $this->getContentHandler();
880
881
        $gatewayMock = $this->getGatewayMock();
882
        $mapperMock = $this->getMapperMock();
883
884
        $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...
885
            ->method('loadRelations')
886
            ->with(
887
                $this->equalTo(23),
888
                $this->equalTo(null),
889
                $this->equalTo(null)
890
            )->will(
891
                $this->returnValue(array(42))
892
            );
893
894
        $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...
895
            ->method('extractRelationsFromRows')
896
            ->with($this->equalTo(array(42)))
897
            ->will($this->returnValue($this->getRelationFixture()));
898
899
        $result = $handler->loadRelations(23);
900
901
        $this->assertEquals(
902
            $result,
903
            $this->getRelationFixture()
904
        );
905
    }
906
907
    /**
908
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations
909
     */
910
    public function testLoadReverseRelations()
911
    {
912
        $handler = $this->getContentHandler();
913
914
        $gatewayMock = $this->getGatewayMock();
915
        $mapperMock = $this->getMapperMock();
916
917
        $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...
918
            ->method('loadReverseRelations')
919
            ->with(
920
                $this->equalTo(23),
921
                $this->equalTo(null)
922
            )->will(
923
                $this->returnValue(array(42))
924
            );
925
926
        $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...
927
            ->method('extractRelationsFromRows')
928
            ->with($this->equalTo(array(42)))
929
            ->will($this->returnValue($this->getRelationFixture()));
930
931
        $result = $handler->loadReverseRelations(23);
932
933
        $this->assertEquals(
934
            $result,
935
            $this->getRelationFixture()
936
        );
937
    }
938
939
    public function testAddRelation()
940
    {
941
        // expected relation object after creation
942
        $expectedRelationObject = new Relation();
943
        $expectedRelationObject->id = 42; // mocked value, not a real one
944
        $expectedRelationObject->sourceContentId = 23;
945
        $expectedRelationObject->sourceContentVersionNo = 1;
946
        $expectedRelationObject->destinationContentId = 66;
947
        $expectedRelationObject->type = RelationValue::COMMON;
948
949
        // relation create struct
950
        $relationCreateStruct = new Relation\CreateStruct();
951
        $relationCreateStruct->destinationContentId = 66;
952
        $relationCreateStruct->sourceContentId = 23;
953
        $relationCreateStruct->sourceContentVersionNo = 1;
954
        $relationCreateStruct->type = RelationValue::COMMON;
955
956
        $handler = $this->getContentHandler();
957
958
        $gatewayMock = $this->getGatewayMock();
959
        $mapperMock = $this->getMapperMock();
960
961
        $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...
962
            ->method('createRelationFromCreateStruct')
963
            // @todo Connected with the todo above
964
            ->with($this->equalTo($relationCreateStruct))
965
            ->will($this->returnValue($expectedRelationObject));
966
967
        $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...
968
            ->method('insertRelation')
969
            ->with($this->equalTo($relationCreateStruct))
970
            ->will(
971
                // @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods
972
                $this->returnValue(42)
973
            );
974
975
        $result = $handler->addRelation($relationCreateStruct);
976
977
        $this->assertEquals(
978
            $result,
979
            $expectedRelationObject
980
        );
981
    }
982
983
    /**
984
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation
985
     */
986
    public function testRemoveRelation()
987
    {
988
        $gatewayMock = $this->getGatewayMock();
989
990
        $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...
991
            ->method('deleteRelation')
992
            ->with($this->equalTo(1, RelationValue::COMMON));
993
994
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
995
    }
996
997
    protected function getRelationFixture()
998
    {
999
        $relation = new Relation();
1000
        $relation->sourceContentId = 23;
1001
        $relation->sourceContentVersionNo = 1;
1002
        $relation->destinationContentId = 69;
1003
1004
        return $relation;
1005
    }
1006
1007
    /**
1008
     * Returns a CreateStruct fixture.
1009
     *
1010
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
1011
     */
1012
    public function getCreateStructFixture()
1013
    {
1014
        $struct = new CreateStruct();
1015
1016
        $struct->typeId = 4242;
1017
1018
        $firstField = new Field();
1019
        $firstField->type = 'some-type';
1020
        $firstField->value = new FieldValue();
1021
1022
        $secondField = clone $firstField;
1023
1024
        $struct->fields = array(
1025
            $firstField, $secondField,
1026
        );
1027
1028
        $struct->locations = array(
1029
            new LocationCreateStruct(
1030
                array('parentId' => 42)
1031
            ),
1032
        );
1033
1034
        $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...
1035
            'eng-GB' => 'This is a test name',
1036
        );
1037
1038
        return $struct;
1039
    }
1040
1041
    /**
1042
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
1043
     */
1044
    public function testLoadDraftsForUser()
1045
    {
1046
        $handler = $this->getContentHandler();
1047
        $rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2));
1048
1049
        $gatewayMock = $this->getGatewayMock();
1050
        $mapperMock = $this->getMapperMock();
1051
1052
        $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...
1053
            ->method('listVersionsForUser')
1054
            ->with($this->equalTo(23))
1055
            ->will($this->returnValue($rows));
1056
1057
        $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...
1058
            ->method('loadVersionedNameData')
1059
            ->with($this->equalTo(array(array('id' => 42, 'version' => 2))))
1060
            ->will($this->returnValue(array()));
1061
1062
        $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...
1063
            ->method('extractVersionInfoListFromRows')
1064
            ->with($this->equalTo($rows), $this->equalTo(array()))
1065
            ->will($this->returnValue(array(new VersionInfo())));
1066
1067
        $res = $handler->loadDraftsForUser(23);
1068
1069
        $this->assertEquals(
1070
            array(new VersionInfo()),
1071
            $res
1072
        );
1073
    }
1074
1075
    public function testListVersions()
1076
    {
1077
        $handler = $this->getContentHandler();
1078
1079
        $treeHandlerMock = $this->getTreeHandlerMock();
1080
1081
        $treeHandlerMock
1082
            ->expects($this->once())
1083
            ->method('listVersions')
1084
            ->with(23)
1085
            ->will($this->returnValue(array(new VersionInfo())));
1086
1087
        $versions = $handler->listVersions(23);
1088
1089
        $this->assertEquals(
1090
            array(new VersionInfo()),
1091
            $versions
1092
        );
1093
    }
1094
1095
    public function testRemoveRawContent()
1096
    {
1097
        $handler = $this->getContentHandler();
1098
        $treeHandlerMock = $this->getTreeHandlerMock();
1099
1100
        $treeHandlerMock
1101
            ->expects($this->once())
1102
            ->method('removeRawContent')
1103
            ->with(23);
1104
1105
        $handler->removeRawContent(23);
1106
    }
1107
1108
    /**
1109
     * Test for the deleteContent() method.
1110
     *
1111
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1112
     */
1113
    public function testDeleteContentWithLocations()
1114
    {
1115
        $handlerMock = $this->getPartlyMockedHandler(array('getAllLocationIds'));
1116
        $gatewayMock = $this->getGatewayMock();
1117
        $treeHandlerMock = $this->getTreeHandlerMock();
1118
1119
        $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...
1120
            ->method('getAllLocationIds')
1121
            ->with($this->equalTo(23))
1122
            ->will($this->returnValue(array(42, 24)));
1123
        $treeHandlerMock->expects($this->exactly(2))
1124
            ->method('removeSubtree')
1125
            ->with(
1126
                $this->logicalOr(
1127
                    $this->equalTo(42),
1128
                    $this->equalTo(24)
1129
                )
1130
            );
1131
1132
        $handlerMock->deleteContent(23);
1133
    }
1134
1135
    /**
1136
     * Test for the deleteContent() method.
1137
     *
1138
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1139
     */
1140
    public function testDeleteContentWithoutLocations()
1141
    {
1142
        $handlerMock = $this->getPartlyMockedHandler(array('removeRawContent'));
1143
        $gatewayMock = $this->getGatewayMock();
1144
1145
        $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...
1146
            ->method('getAllLocationIds')
1147
            ->with($this->equalTo(23))
1148
            ->will($this->returnValue(array()));
1149
        $handlerMock->expects($this->once())
1150
            ->method('removeRawContent')
1151
            ->with($this->equalTo(23));
1152
1153
        $handlerMock->deleteContent(23);
1154
    }
1155
1156
    /**
1157
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1158
     */
1159
    public function testDeleteVersion()
1160
    {
1161
        $handler = $this->getContentHandler();
1162
1163
        $gatewayMock = $this->getGatewayMock();
1164
        $mapperMock = $this->getMapperMock();
1165
        $locationHandlerMock = $this->getLocationGatewayMock();
1166
        $fieldHandlerMock = $this->getFieldHandlerMock();
1167
1168
        // Load VersionInfo to delete fields
1169
        $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...
1170
            ->method('loadVersionInfo')
1171
            ->with($this->equalTo(225), $this->equalTo(2))
1172
            ->will($this->returnValue(array(42)));
1173
1174
        $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...
1175
            ->method('loadVersionedNameData')
1176
            ->with($this->equalTo(array(array('id' => 225, 'version' => 2))))
1177
            ->will($this->returnValue(array(22)));
1178
1179
        $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...
1180
            ->method('extractVersionInfoListFromRows')
1181
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
1182
            ->will($this->returnValue(array(new VersionInfo())));
1183
1184
        $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...
1185
            ->method('deleteNodeAssignment')
1186
            ->with(
1187
                $this->equalTo(225),
1188
                $this->equalTo(2)
1189
            );
1190
1191
        $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...
1192
            ->method('deleteFields')
1193
            ->with(
1194
                $this->equalTo(225),
1195
                $this->isInstanceOf(VersionInfo::class)
1196
            );
1197
        $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...
1198
            ->method('deleteRelations')
1199
            ->with(
1200
                $this->equalTo(225),
1201
                $this->equalTo(2)
1202
            );
1203
        $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...
1204
            ->method('deleteVersions')
1205
            ->with(
1206
                $this->equalTo(225),
1207
                $this->equalTo(2)
1208
            );
1209
        $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...
1210
            ->method('deleteNames')
1211
            ->with(
1212
                $this->equalTo(225),
1213
                $this->equalTo(2)
1214
            );
1215
1216
        $handler->deleteVersion(225, 2);
1217
    }
1218
1219
    /**
1220
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1221
     */
1222
    public function testCopySingleVersion()
1223
    {
1224
        $handler = $this->getPartlyMockedHandler(array('load', 'internalCreate'));
1225
        $gatewayMock = $this->getGatewayMock();
1226
        $mapperMock = $this->getMapperMock();
1227
1228
        $handler->expects(
1229
            $this->once()
1230
        )->method(
1231
            'load'
1232
        )->with(
1233
            $this->equalTo(23),
1234
            $this->equalTo(32)
1235
        )->will(
1236
            $this->returnValue(new Content())
1237
        );
1238
1239
        $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...
1240
            $this->once()
1241
        )->method(
1242
            'createCreateStructFromContent'
1243
        )->with(
1244
            $this->isInstanceOf(Content::class)
1245
        )->will(
1246
            $this->returnValue(new CreateStruct())
1247
        );
1248
1249
        $handler->expects(
1250
            $this->once()
1251
        )->method(
1252
            'internalCreate'
1253
        )->with(
1254
            $this->isInstanceOf(CreateStruct::class),
1255
            $this->equalTo(32)
1256
        )->will(
1257
            $this->returnValue(
1258
                new Content(
1259
                    [
1260
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1261
                    ]
1262
                )
1263
            )
1264
        );
1265
1266
        $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...
1267
            ->method('copyRelations')
1268
            ->with(
1269
                $this->equalTo(23),
1270
                $this->equalTo(24),
1271
                $this->equalTo(32)
1272
            )
1273
            ->will($this->returnValue(null));
1274
1275
        $result = $handler->copy(23, 32);
1276
1277
        $this->assertInstanceOf(
1278
            Content::class,
1279
            $result
1280
        );
1281
    }
1282
1283
    /**
1284
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1285
     */
1286
    public function testCopyAllVersions()
1287
    {
1288
        $handler = $this->getPartlyMockedHandler(
1289
            array(
1290
                'loadContentInfo',
1291
                'load',
1292
                'internalCreate',
1293
                'listVersions',
1294
            )
1295
        );
1296
        $gatewayMock = $this->getGatewayMock();
1297
        $mapperMock = $this->getMapperMock();
1298
        $fieldHandlerMock = $this->getFieldHandlerMock();
1299
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1300
        $contentTypeMock = $this->createMock(Type::class);
1301
        $time = time();
1302
        $createStructStub = new CreateStruct(
1303
            array(
1304
                'modified' => $time,
1305
                'typeId' => 4242,
1306
            )
1307
        );
1308
1309
        $contentTypeHandlerMock->expects($this->once())
1310
            ->method('load')
1311
            ->with($createStructStub->typeId)
1312
            ->will($this->returnValue($contentTypeMock));
1313
1314
        $handler->expects($this->once())
1315
            ->method('loadContentInfo')
1316
            ->with($this->equalTo(23))
1317
            ->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2))));
1318
1319
        $handler->expects($this->at(1))
1320
            ->method('load')
1321
            ->with($this->equalTo(23), $this->equalTo(2))
1322
            ->will($this->returnValue(new Content()));
1323
1324
        $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...
1325
            ->method('createCreateStructFromContent')
1326
            ->with($this->isInstanceOf(Content::class))
1327
            ->will(
1328
                $this->returnValue($createStructStub)
1329
            );
1330
1331
        $handler->expects($this->once())
1332
            ->method('internalCreate')
1333
            ->with(
1334
                $this->isInstanceOf(CreateStruct::class),
1335
                $this->equalTo(2)
1336
            )->will(
1337
                $this->returnValue(
1338
                    new Content(
1339
                        array(
1340
                            'versionInfo' => new VersionInfo(
1341
                                array(
1342
                                    'contentInfo' => new ContentInfo(array('id' => 24)),
1343
                                )
1344
                            ),
1345
                        )
1346
                    )
1347
                )
1348
            );
1349
1350
        $handler->expects($this->once())
1351
            ->method('listVersions')
1352
            ->with($this->equalTo(23))
1353
            ->will(
1354
                $this->returnValue(
1355
                    array(
1356
                        new VersionInfo(array('versionNo' => 1)),
1357
                        new VersionInfo(array('versionNo' => 2)),
1358
                    )
1359
                )
1360
            );
1361
1362
        $versionInfo = new VersionInfo(
1363
            array(
1364
                'names' => array('eng-US' => 'Test'),
1365
                'contentInfo' => new ContentInfo(
1366
                    array(
1367
                        'id' => 24,
1368
                        'alwaysAvailable' => true,
1369
                    )
1370
                ),
1371
            )
1372
        );
1373
        $handler->expects($this->at(4))
1374
            ->method('load')
1375
            ->with($this->equalTo(23), $this->equalTo(1))
1376
            ->will(
1377
                $this->returnValue(
1378
                    new Content(
1379
                        array(
1380
                            'versionInfo' => $versionInfo,
1381
                            'fields' => array(),
1382
                        )
1383
                    )
1384
                )
1385
            );
1386
1387
        $versionInfo->creationDate = $time;
1388
        $versionInfo->modificationDate = $time;
1389
        $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...
1390
            ->method('insertVersion')
1391
            ->with(
1392
                $this->equalTo($versionInfo),
1393
                $this->isType('array')
1394
            )->will($this->returnValue(42));
1395
1396
        $versionInfo = clone $versionInfo;
1397
        $versionInfo->id = 42;
1398
        $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...
1399
            ->method('createNewFields')
1400
            ->with(
1401
                $this->equalTo(
1402
                    new Content(
1403
                        array(
1404
                            'versionInfo' => $versionInfo,
1405
                            'fields' => array(),
1406
                        )
1407
                    )
1408
                ),
1409
                $this->isInstanceOf(Type::class)
1410
            );
1411
1412
        $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...
1413
            ->method('setName')
1414
            ->with(
1415
                $this->equalTo(24),
1416
                $this->equalTo(1),
1417
                $this->equalTo('Test'),
1418
                $this->equalTo('eng-US')
1419
            );
1420
1421
        $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...
1422
            ->method('copyRelations')
1423
            ->with(
1424
                $this->equalTo(23),
1425
                $this->equalTo(24),
1426
                $this->equalTo(null)
1427
            )
1428
            ->will($this->returnValue(null));
1429
1430
        $result = $handler->copy(23);
1431
1432
        $this->assertInstanceOf(
1433
            Content::class,
1434
            $result
1435
        );
1436
    }
1437
1438
    /**
1439
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1440
     */
1441
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1442
    {
1443
        $handler = $this->getContentHandler();
1444
1445
        $treeHandlerMock = $this->getTreeHandlerMock();
1446
        $treeHandlerMock
1447
            ->expects($this->once())
1448
            ->method('loadContentInfo')
1449
            ->with($this->equalTo(23))
1450
            ->will(
1451
                $this->throwException(new NotFoundException('ContentInfo', 23))
1452
            );
1453
1454
        $handler->copy(23);
1455
    }
1456
1457
    /**
1458
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1459
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1460
     */
1461 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1462
    {
1463
        $handler = $this->getContentHandler();
1464
1465
        $gatewayMock = $this->getGatewayMock();
1466
        $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...
1467
            ->method('load')
1468
            ->with($this->equalTo(23, 32))
1469
            ->will($this->returnValue(array()));
1470
1471
        $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...
1472
    }
1473
1474
    /**
1475
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1476
     */
1477 View Code Duplication
    public function testSetStatus()
1478
    {
1479
        $handler = $this->getContentHandler();
1480
1481
        $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...
1482
        $gatewayMock = $this->getGatewayMock();
1483
1484
        $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...
1485
            ->method('setStatus')
1486
            ->with(23, 5, 2)
1487
            ->will($this->returnValue(true));
1488
1489
        $this->assertTrue(
1490
            $handler->setStatus(23, 2, 5)
1491
        );
1492
    }
1493
1494
    /**
1495
     * Returns the handler to test.
1496
     *
1497
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1498
     */
1499
    protected function getContentHandler()
1500
    {
1501
        if (!isset($this->contentHandler)) {
1502
            $this->contentHandler = new Handler(
1503
                $this->getGatewayMock(),
1504
                $this->getLocationGatewayMock(),
1505
                $this->getMapperMock(),
1506
                $this->getFieldHandlerMock(),
1507
                $this->getSlugConverterMock(),
1508
                $this->getUrlAliasGatewayMock(),
1509
                $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...
1510
                $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...
1511
                $this->getLanguageHandlerMock()
1512
            );
1513
        }
1514
1515
        return $this->contentHandler;
1516
    }
1517
1518
    /**
1519
     * Returns the handler to test with $methods mocked.
1520
     *
1521
     * @param string[] $methods
1522
     *
1523
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1524
     */
1525
    protected function getPartlyMockedHandler(array $methods)
1526
    {
1527
        return $this->getMockBuilder(Handler::class)
1528
            ->setMethods($methods)
1529
            ->setConstructorArgs(
1530
                array(
1531
                    $this->getGatewayMock(),
1532
                    $this->getLocationGatewayMock(),
1533
                    $this->getMapperMock(),
1534
                    $this->getFieldHandlerMock(),
1535
                    $this->getSlugConverterMock(),
1536
                    $this->getUrlAliasGatewayMock(),
1537
                    $this->getContentTypeHandlerMock(),
1538
                    $this->getTreeHandlerMock(),
1539
                    $this->getLanguageHandlerMock(),
1540
                )
1541
            )
1542
            ->getMock();
1543
    }
1544
1545
    /**
1546
     * Returns a TreeHandler mock.
1547
     *
1548
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1549
     */
1550
    protected function getTreeHandlerMock()
1551
    {
1552
        if (!isset($this->treeHandlerMock)) {
1553
            $this->treeHandlerMock = $this->createMock(TreeHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ent\TreeHandler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...cy\Content\TreeHandler> of property $treeHandlerMock.

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...
1554
        }
1555
1556
        return $this->treeHandlerMock;
1557
    }
1558
1559
    /**
1560
     * Returns a ContentTypeHandler mock.
1561
     *
1562
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1563
     */
1564
    protected function getContentTypeHandlerMock()
1565
    {
1566
        if (!isset($this->contentTypeHandlerMock)) {
1567
            $this->contentTypeHandlerMock = $this->createMock(ContentTypeHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\Type\Handler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\Type\Handler> of property $contentTypeHandlerMock.

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...
1568
        }
1569
1570
        return $this->contentTypeHandlerMock;
1571
    }
1572
1573
    /**
1574
     * Returns a FieldHandler mock.
1575
     *
1576
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1577
     */
1578
    protected function getFieldHandlerMock()
1579
    {
1580
        if (!isset($this->fieldHandlerMock)) {
1581
            $this->fieldHandlerMock = $this->createMock(FieldHandler::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\FieldHandler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\FieldHandler> of property $fieldHandlerMock.

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...
1582
        }
1583
1584
        return $this->fieldHandlerMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->fieldHandlerMock; of type PHPUnit\Framework\MockOb...cy\Content\FieldHandler adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1584 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...st::getFieldHandlerMock of type eZ\Publish\Core\Persiste...cy\Content\FieldHandler.
Loading history...
1585
    }
1586
1587
    /**
1588
     * Returns a Mapper mock.
1589
     *
1590
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1591
     */
1592
    protected function getMapperMock()
1593
    {
1594
        if (!isset($this->mapperMock)) {
1595
            $this->mapperMock = $this->createMock(Mapper::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...\Content\Mapper::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...\Legacy\Content\Mapper> of property $mapperMock.

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...
1596
        }
1597
1598
        return $this->mapperMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->mapperMock; of type PHPUnit\Framework\MockOb...e\Legacy\Content\Mapper adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1598 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...dlerTest::getMapperMock of type eZ\Publish\Core\Persistence\Legacy\Content\Mapper.
Loading history...
1599
    }
1600
1601
    /**
1602
     * Returns a Location Gateway mock.
1603
     *
1604
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1605
     */
1606
    protected function getLocationGatewayMock()
1607
    {
1608
        if (!isset($this->locationGatewayMock)) {
1609
            $this->locationGatewayMock = $this->createMock(LocationGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ocation\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\Location\Gateway> of property $locationGatewayMock.

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...
1610
        }
1611
1612
        return $this->locationGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->locationGatewayMock; of type PHPUnit\Framework\MockOb...ontent\Location\Gateway adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1612 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...:getLocationGatewayMock of type eZ\Publish\Core\Persiste...ontent\Location\Gateway.
Loading history...
1613
    }
1614
1615
    /**
1616
     * Returns a Content Type gateway mock.
1617
     *
1618
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1619
     */
1620
    protected function getTypeGatewayMock()
1621
    {
1622
        if (!isset($this->typeGatewayMock)) {
1623
            $this->typeGatewayMock = $this->createMock(ContentTypeGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...nt\Type\Gateway::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...y\Content\Type\Gateway> of property $typeGatewayMock.

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...
1624
        }
1625
1626
        return $this->typeGatewayMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->typeGatewayMock; of type PHPUnit\Framework\MockOb...cy\Content\Type\Gateway adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1626 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...est::getTypeGatewayMock of type eZ\Publish\Core\Persiste...cy\Content\Type\Gateway.
Loading history...
1627
    }
1628
1629
    /**
1630
     * Returns a mock object for the Content Gateway.
1631
     *
1632
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
1633
     */
1634
    protected function getGatewayMock()
1635
    {
1636
        if (!isset($this->gatewayMock)) {
1637
            $this->gatewayMock = $this->getMockForAbstractClass(ContentGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...Content\Gateway::class) 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...
1638
        }
1639
1640
        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 1640 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...
1641
    }
1642
1643
    /**
1644
     * Returns a mock object for the UrlAlias Handler.
1645
     *
1646
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1647
     */
1648
    protected function getSlugConverterMock()
1649
    {
1650
        if (!isset($this->slugConverterMock)) {
1651
            $this->slugConverterMock = $this->createMock(SlugConverter::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...s\SlugConverter::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...UrlAlias\SlugConverter> of property $slugConverterMock.

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...
1652
        }
1653
1654
        return $this->slugConverterMock;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->slugConverterMock; of type PHPUnit\Framework\MockOb...\UrlAlias\SlugConverter adds the type PHPUnit\Framework\MockObject\MockObject to the return on line 1654 which is incompatible with the return type documented by eZ\Publish\Core\Persiste...t::getSlugConverterMock of type eZ\Publish\Core\Persiste...\UrlAlias\SlugConverter.
Loading history...
1655
    }
1656
1657
    /**
1658
     * Returns a mock object for the UrlAlias Gateway.
1659
     *
1660
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1661
     */
1662
    protected function getUrlAliasGatewayMock()
1663
    {
1664
        if (!isset($this->urlAliasGatewayMock)) {
1665
            $this->urlAliasGatewayMock = $this->getMockForAbstractClass(UrlAliasGateway::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForAbstrac...rlAlias\Gateway::class) 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...
1666
        }
1667
1668
        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 1668 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...
1669
    }
1670
1671
    /**
1672
     * @return \eZ\Publish\SPI\Persistence\Content\Language\Handler
1673
     */
1674
    protected function getLanguageHandlerMock()
1675
    {
1676
        if (!isset($this->languageHandlerMock)) {
1677
            $this->languageHandlerMock = $this->getMockForAbstractClass(LanguageHandler::class);
0 ignored issues
show
Bug introduced by
The property languageHandlerMock does not seem to exist. Did you mean handler?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1678
        }
1679
1680
        return $this->languageHandlerMock;
0 ignored issues
show
Bug introduced by
The property languageHandlerMock does not seem to exist. Did you mean handler?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1681
    }
1682
}
1683