Completed
Push — solr_77 ( 488353...548dbd )
by
unknown
18:49
created

ContentHandlerTest::testCtor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
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\Type;
14
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
15
use eZ\Publish\SPI\Persistence\Content\Field;
16
use eZ\Publish\SPI\Persistence\Content\FieldValue;
17
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
19
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
20
use eZ\Publish\SPI\Persistence\Content\Relation;
21
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
22
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct as LocationCreateStruct;
23
use eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Handler;
25
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
26
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
27
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
28
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
29
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
30
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
31
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway;
32
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
33
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper;
34
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler;
35
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
36
37
/**
38
 * Test case for Content Handler.
39
 */
40
class ContentHandlerTest extends TestCase
41
{
42
    /**
43
     * Content handler to test.
44
     *
45
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler
46
     */
47
    protected $contentHandler;
48
49
    /**
50
     * Gateway mock.
51
     *
52
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
53
     */
54
    protected $gatewayMock;
55
56
    /**
57
     * Location gateway mock.
58
     *
59
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
60
     */
61
    protected $locationGatewayMock;
62
63
    /**
64
     * Type gateway mock.
65
     *
66
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
67
     */
68
    protected $typeGatewayMock;
69
70
    /**
71
     * Mapper mock.
72
     *
73
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
74
     */
75
    protected $mapperMock;
76
77
    /**
78
     * Field handler mock.
79
     *
80
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
81
     */
82
    protected $fieldHandlerMock;
83
84
    /**
85
     * Location handler mock.
86
     *
87
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
88
     */
89
    protected $treeHandlerMock;
90
91
    /**
92
     * Slug converter mock.
93
     *
94
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
95
     */
96
    protected $slugConverterMock;
97
98
    /**
99
     * Location handler mock.
100
     *
101
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
102
     */
103
    protected $urlAliasGatewayMock;
104
105
    /**
106
     * ContentType handler mock.
107
     *
108
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
109
     */
110
    protected $contentTypeHandlerMock;
111
112
    /**
113
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::__construct
114
     */
115 View Code Duplication
    public function testCtor()
116
    {
117
        $handler = $this->getContentHandler();
118
119
        $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...
120
            $this->getGatewayMock(),
121
            'contentGateway',
122
            $handler
123
        );
124
        $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...
125
            $this->getMapperMock(),
126
            'mapper',
127
            $handler
128
        );
129
        $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...
130
            $this->getFieldHandlerMock(),
131
            'fieldHandler',
132
            $handler
133
        );
134
        // @todo Assert missing properties
135
    }
136
137
    /**
138
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::create
139
     *
140
     * @todo Current method way to complex to test, refactor!
141
     */
142
    public function testCreate()
143
    {
144
        $handler = $this->getContentHandler();
145
146
        $mapperMock = $this->getMapperMock();
147
        $gatewayMock = $this->getGatewayMock();
148
        $fieldHandlerMock = $this->getFieldHandlerMock();
149
        $locationMock = $this->getLocationGatewayMock();
150
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
151
        $contentTypeMock = $this->createMock(Type::class);
152
        $createStruct = $this->getCreateStructFixture();
153
154
        $contentTypeHandlerMock->expects($this->once())
155
            ->method('load')
156
            ->with($createStruct->typeId)
157
            ->will($this->returnValue($contentTypeMock));
158
159
        $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...
160
            ->method('createVersionInfoFromCreateStruct')
161
            ->with(
162
                $this->isInstanceOf(
163
                    CreateStruct::class
164
                )
165
            )->will(
166
                $this->returnValue(
167
                    new VersionInfo(
168
                        [
169
                            'names' => [],
170
                            'contentInfo' => new ContentInfo(),
171
                        ]
172
                    )
173
                )
174
            );
175
176
        $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...
177
            ->method('insertContentObject')
178
            ->with(
179
                $this->isInstanceOf(CreateStruct::class)
180
            )->will($this->returnValue(23));
181
182
        $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...
183
            ->method('insertVersion')
184
            ->with(
185
                $this->isInstanceOf(VersionInfo::class),
186
                $this->isType('array')
187
            )->will($this->returnValue(1));
188
189
        $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...
190
            ->method('createNewFields')
191
            ->with(
192
                $this->isInstanceOf(Content::class),
193
                $this->isInstanceOf(Type::class)
194
            );
195
196
        $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...
197
            ->method('createNodeAssignment')
198
            ->with(
199
                $this->isInstanceOf(
200
                    LocationCreateStruct::class
201
                ),
202
                $this->equalTo(42),
203
                $this->equalTo(3) // Location\Gateway::NODE_ASSIGNMENT_OP_CODE_CREATE
204
            );
205
206
        $res = $handler->create($createStruct);
207
208
        // @todo Make subsequent tests
209
210
        $this->assertInstanceOf(
211
            Content::class,
212
            $res,
213
            'Content not created'
214
        );
215
        $this->assertEquals(
216
            23,
217
            $res->versionInfo->contentInfo->id,
218
            'Content ID not set correctly'
219
        );
220
        $this->assertInstanceOf(
221
            VersionInfo::class,
222
            $res->versionInfo,
223
            'Version infos not created'
224
        );
225
        $this->assertEquals(
226
            1,
227
            $res->versionInfo->id,
228
            'Version ID not set correctly'
229
        );
230
        $this->assertEquals(
231
            2,
232
            count($res->fields),
233
            'Fields not set correctly in version'
234
        );
235
    }
236
237
    /**
238
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish
239
     */
240
    public function testPublishFirstVersion()
241
    {
242
        $handler = $this->getPartlyMockedHandler(['loadVersionInfo', 'setStatus']);
243
244
        $gatewayMock = $this->getGatewayMock();
245
        $mapperMock = $this->getMapperMock();
246
        $locationMock = $this->getLocationGatewayMock();
247
        $fieldHandlerMock = $this->getFieldHandlerMock();
248
        $metadataUpdateStruct = new MetadataUpdateStruct();
249
250
        $handler->expects($this->at(0))
251
            ->method('loadVersionInfo')
252
            ->with(23, 1)
253
            ->will(
254
                $this->returnValue(
255
                    new VersionInfo(['contentInfo' => new ContentInfo(['currentVersionNo' => 1])])
256
                )
257
            );
258
259
        $contentRows = [['ezcontentobject_version_version' => 1]];
260
261
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

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

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

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

Loading history...
1396
            ->method('setName')
1397
            ->with(
1398
                $this->equalTo(24),
1399
                $this->equalTo(1),
1400
                $this->equalTo('Test'),
1401
                $this->equalTo('eng-US')
1402
            );
1403
1404
        $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...
1405
            ->method('copyRelations')
1406
            ->with(
1407
                $this->equalTo(23),
1408
                $this->equalTo(24),
1409
                $this->equalTo(null)
1410
            )
1411
            ->will($this->returnValue(null));
1412
1413
        $result = $handler->copy(23);
1414
1415
        $this->assertInstanceOf(
1416
            Content::class,
1417
            $result
1418
        );
1419
    }
1420
1421
    /**
1422
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1423
     */
1424
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1425
    {
1426
        $handler = $this->getContentHandler();
1427
1428
        $treeHandlerMock = $this->getTreeHandlerMock();
1429
        $treeHandlerMock
1430
            ->expects($this->once())
1431
            ->method('loadContentInfo')
1432
            ->with($this->equalTo(23))
1433
            ->will(
1434
                $this->throwException(new NotFoundException('ContentInfo', 23))
1435
            );
1436
1437
        $handler->copy(23);
1438
    }
1439
1440
    /**
1441
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1442
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1443
     */
1444 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1445
    {
1446
        $handler = $this->getContentHandler();
1447
1448
        $gatewayMock = $this->getGatewayMock();
1449
        $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...
1450
            ->method('load')
1451
            ->with($this->equalTo(23, 32))
1452
            ->will($this->returnValue([]));
1453
1454
        $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...
1455
    }
1456
1457
    /**
1458
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1459
     */
1460
    public function testSetStatus()
1461
    {
1462
        $handler = $this->getContentHandler();
1463
1464
        $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...
1465
        $gatewayMock = $this->getGatewayMock();
1466
1467
        $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...
1468
            ->method('setStatus')
1469
            ->with(23, 5, 2)
1470
            ->will($this->returnValue(true));
1471
1472
        $this->assertTrue(
1473
            $handler->setStatus(23, 2, 5)
1474
        );
1475
    }
1476
1477
    /**
1478
     * Returns the handler to test.
1479
     *
1480
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1481
     */
1482
    protected function getContentHandler()
1483
    {
1484
        if (!isset($this->contentHandler)) {
1485
            $this->contentHandler = new Handler(
1486
                $this->getGatewayMock(),
1487
                $this->getLocationGatewayMock(),
1488
                $this->getMapperMock(),
1489
                $this->getFieldHandlerMock(),
1490
                $this->getSlugConverterMock(),
1491
                $this->getUrlAliasGatewayMock(),
1492
                $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...
1493
                $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...
1494
            );
1495
        }
1496
1497
        return $this->contentHandler;
1498
    }
1499
1500
    /**
1501
     * Returns the handler to test with $methods mocked.
1502
     *
1503
     * @param string[] $methods
1504
     *
1505
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1506
     */
1507
    protected function getPartlyMockedHandler(array $methods)
1508
    {
1509
        return $this->getMockBuilder(Handler::class)
1510
            ->setMethods($methods)
1511
            ->setConstructorArgs(
1512
                [
1513
                    $this->getGatewayMock(),
1514
                    $this->getLocationGatewayMock(),
1515
                    $this->getMapperMock(),
1516
                    $this->getFieldHandlerMock(),
1517
                    $this->getSlugConverterMock(),
1518
                    $this->getUrlAliasGatewayMock(),
1519
                    $this->getContentTypeHandlerMock(),
1520
                    $this->getTreeHandlerMock(),
1521
                ]
1522
            )
1523
            ->getMock();
1524
    }
1525
1526
    /**
1527
     * Returns a TreeHandler mock.
1528
     *
1529
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1530
     */
1531
    protected function getTreeHandlerMock()
1532
    {
1533
        if (!isset($this->treeHandlerMock)) {
1534
            $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...
1535
        }
1536
1537
        return $this->treeHandlerMock;
1538
    }
1539
1540
    /**
1541
     * Returns a ContentTypeHandler mock.
1542
     *
1543
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1544
     */
1545
    protected function getContentTypeHandlerMock()
1546
    {
1547
        if (!isset($this->contentTypeHandlerMock)) {
1548
            $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...
1549
        }
1550
1551
        return $this->contentTypeHandlerMock;
1552
    }
1553
1554
    /**
1555
     * Returns a FieldHandler mock.
1556
     *
1557
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1558
     */
1559
    protected function getFieldHandlerMock()
1560
    {
1561
        if (!isset($this->fieldHandlerMock)) {
1562
            $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...
1563
        }
1564
1565
        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 1565 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...
1566
    }
1567
1568
    /**
1569
     * Returns a Mapper mock.
1570
     *
1571
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1572
     */
1573
    protected function getMapperMock()
1574
    {
1575
        if (!isset($this->mapperMock)) {
1576
            $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...
1577
        }
1578
1579
        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 1579 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...
1580
    }
1581
1582
    /**
1583
     * Returns a Location Gateway mock.
1584
     *
1585
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1586
     */
1587
    protected function getLocationGatewayMock()
1588
    {
1589
        if (!isset($this->locationGatewayMock)) {
1590
            $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...
1591
        }
1592
1593
        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 1593 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...
1594
    }
1595
1596
    /**
1597
     * Returns a Content Type gateway mock.
1598
     *
1599
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1600
     */
1601
    protected function getTypeGatewayMock()
1602
    {
1603
        if (!isset($this->typeGatewayMock)) {
1604
            $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...
1605
        }
1606
1607
        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 1607 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...
1608
    }
1609
1610
    /**
1611
     * Returns a mock object for the Content Gateway.
1612
     *
1613
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
1614
     */
1615
    protected function getGatewayMock()
1616
    {
1617
        if (!isset($this->gatewayMock)) {
1618
            $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...
1619
        }
1620
1621
        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 1621 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...
1622
    }
1623
1624
    /**
1625
     * Returns a mock object for the UrlAlias Handler.
1626
     *
1627
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1628
     */
1629
    protected function getSlugConverterMock()
1630
    {
1631
        if (!isset($this->slugConverterMock)) {
1632
            $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...
1633
        }
1634
1635
        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 1635 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...
1636
    }
1637
1638
    /**
1639
     * Returns a mock object for the UrlAlias Gateway.
1640
     *
1641
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1642
     */
1643
    protected function getUrlAliasGatewayMock()
1644
    {
1645
        if (!isset($this->urlAliasGatewayMock)) {
1646
            $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...
1647
        }
1648
1649
        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 1649 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...
1650
    }
1651
}
1652