Completed
Push — location_content_property ( b180d5 )
by André
16:28
created

ContentHandlerTest::testLoadContentList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 47
nc 1
nop 0
dl 0
loc 64
rs 9.3956
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\SPI\Persistence\Content;
13
use eZ\Publish\SPI\Persistence\Content\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(
120
            $this->getGatewayMock(),
121
            'contentGateway',
122
            $handler
123
        );
124
        $this->assertAttributeSame(
125
            $this->getMapperMock(),
126
            'mapper',
127
            $handler
128
        );
129
        $this->assertAttributeSame(
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
                        array(
169
                            'names' => array(),
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(array('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(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
256
                )
257
            );
258
259
        $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...
260
            ->method('load')
261
            ->with(
262
                $this->equalTo(23),
263
                $this->equalTo(1),
264
                $this->equalTo(null)
265
            )->will(
266
                $this->returnValue(array(42))
267
            );
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(array(array('id' => 23, 'version' => 1)))
273
            )->will(
274
                $this->returnValue(array(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(array(42)), $this->equalTo(array(22)))
280
            ->will($this->returnValue(array($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(array('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(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1))))
328
                )
329
            );
330
331
        $handler
332
            ->expects($this->at(1))
333
            ->method('setStatus')
334
            ->with(23, VersionInfo::STATUS_ARCHIVED, 1);
335
336
        $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...
337
            ->method('load')
338
            ->with(
339
                $this->equalTo(23),
340
                $this->equalTo(2),
341
                $this->equalTo(null)
342
            )
343
            ->will($this->returnValue(array(42)));
344
345
        $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...
346
            ->method('loadVersionedNameData')
347
            ->with(
348
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
349
            )->will(
350
                $this->returnValue(array(22))
351
            );
352
353
        $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...
354
            ->method('extractContentFromRows')
355
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
356
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
357
358
        $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...
359
            ->method('loadExternalFieldData')
360
            ->with($this->isInstanceOf(Content::class));
361
362
        $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...
363
            ->expects($this->once())
364
            ->method('updateContent')
365
            ->with(23, $metadataUpdateStruct, $this->isInstanceOf(VersionInfo::class));
366
367
        $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...
368
            ->expects($this->once())
369
            ->method('createLocationsFromNodeAssignments')
370
            ->with(23, 2);
371
372
        $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...
373
            ->expects($this->once())
374
            ->method('updateLocationsContentVersionNo')
375
            ->with(23, 2);
376
377
        $handler
378
            ->expects($this->at(2))
379
            ->method('setStatus')
380
            ->with(23, VersionInfo::STATUS_PUBLISHED, 2);
381
382
        $handler->publish(23, 2, $metadataUpdateStruct);
383
    }
384
385
    /**
386
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::createDraftFromVersion
387
     */
388
    public function testCreateDraftFromVersion()
389
    {
390
        $handler = $this->getPartlyMockedHandler(array('load'));
391
392
        $mapperMock = $this->getMapperMock();
393
        $gatewayMock = $this->getGatewayMock();
394
        $fieldHandlerMock = $this->getFieldHandlerMock();
395
396
        $handler->expects($this->once())
397
            ->method('load')
398
            ->with(23, 2)
399
            ->will($this->returnValue($this->getContentFixtureForDraft()));
400
401
        $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...
402
            ->method('createVersionInfoForContent')
403
            ->with(
404
                $this->isInstanceOf(Content::class),
405
                $this->equalTo(3),
406
                $this->equalTo(14)
407
            )->will(
408
                $this->returnValue(
409
                    new VersionInfo(
410
                        array(
411
                            'names' => array(),
412
                            'versionNo' => 3,
413
                        )
414
                    )
415
                )
416
            );
417
418
        $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...
419
            ->method('insertVersion')
420
            ->with(
421
                $this->isInstanceOf(VersionInfo::class),
422
                $this->getContentFixtureForDraft()->fields
423
            )->will($this->returnValue(42));
424
425
        $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...
426
            ->method('getLastVersionNumber')
427
            ->with($this->equalTo(23))
428
            ->will($this->returnValue(2));
429
430
        $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...
431
            ->method('createExistingFieldsInNewVersion')
432
            ->with($this->isInstanceOf(Content::class));
433
434
        $relationData = array(
435
            array(
436
                'ezcontentobject_link_contentclassattribute_id' => 0,
437
                'ezcontentobject_link_to_contentobject_id' => 42,
438
                'ezcontentobject_link_relation_type' => 1,
439
            ),
440
        );
441
442
        $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...
443
            ->method('loadRelations')
444
            ->with(
445
                $this->equalTo(23),
446
                $this->equalTo(2)
447
            )
448
            ->will($this->returnValue($relationData));
449
450
        $relationStruct = new RelationCreateStruct(
451
            array(
452
                'sourceContentId' => 23,
453
                'sourceContentVersionNo' => 3,
454
                'sourceFieldDefinitionId' => 0,
455
                'destinationContentId' => 42,
456
                'type' => 1,
457
            )
458
        );
459
460
        $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...
461
            ->method('insertRelation')
462
            ->with($this->equalTo($relationStruct));
463
464
        $result = $handler->createDraftFromVersion(23, 2, 14);
465
466
        $this->assertInstanceOf(
467
            Content::class,
468
            $result
469
        );
470
        $this->assertEquals(
471
            42,
472
            $result->versionInfo->id
473
        );
474
    }
475
476
    /**
477
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
478
     */
479
    public function testLoad()
480
    {
481
        $handler = $this->getContentHandler();
482
483
        $gatewayMock = $this->getGatewayMock();
484
        $mapperMock = $this->getMapperMock();
485
        $fieldHandlerMock = $this->getFieldHandlerMock();
486
487
        $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...
488
            ->method('load')
489
            ->with(
490
                $this->equalTo(23),
491
                $this->equalTo(2),
492
                $this->equalTo(array('eng-GB'))
493
            )->will(
494
                $this->returnValue(array(42))
495
            );
496
497
        $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...
498
            ->method('loadVersionedNameData')
499
            ->with(
500
                $this->equalTo(array(array('id' => 23, 'version' => 2)))
501
            )->will(
502
                $this->returnValue(array(22))
503
            );
504
505
        $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...
506
            ->method('extractContentFromRows')
507
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
508
            ->will($this->returnValue(array($this->getContentFixtureForDraft())));
509
510
        $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...
511
            ->method('loadExternalFieldData')
512
            ->with($this->isInstanceOf(Content::class));
513
514
        $result = $handler->load(23, 2, array('eng-GB'));
515
516
        $this->assertEquals(
517
            $result,
518
            $this->getContentFixtureForDraft()
519
        );
520
    }
521
522
    /**
523
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentList
524
     */
525
    public function testLoadContentList()
526
    {
527
        $handler = $this->getContentHandler();
528
529
        $gatewayMock = $this->getGatewayMock();
530
        $mapperMock = $this->getMapperMock();
531
        $fieldHandlerMock = $this->getFieldHandlerMock();
532
533
        $infoRows = [
534
            ['id' => 2, 'version' => 2, 'language_mask' => 2],
535
            ['id' => 3, 'version' => 1, 'language_mask' => 3],
536
        ];
537
        $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...
538
            ->method('loadContentInfoList')
539
            ->with($this->equalTo([2,3]))
540
            ->willReturn($infoRows);
541
542
        $infoList = [
543
            new ContentInfo(['id' => 2, 'currentVersionNo' => 2, 'alwaysAvailable' => false, 'mainLanguageCode' => 'eng-US']),
544
            new ContentInfo(['id' => 3, 'currentVersionNo' => 1, 'alwaysAvailable' => true, 'mainLanguageCode' => 'eng-US']),
545
        ];
546
        $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...
547
            ->method('extractContentInfoFromRows')
548
            ->with($this->equalTo($infoRows))
549
            ->willReturn($infoList);
550
551
        $idVersionTranslationPairs = [
552
            ['id' => 2, 'version' => 2, 'languages' => ['eng-GB']],
553
            ['id' => 3, 'version' => 1, 'languages' => ['eng-GB', 'eng-US']],
554
        ];
555
        $contentRows = [
556
            ['ezcontentobject_id' => 2, 'ezcontentobject_version_version' => 2],
557
            ['ezcontentobject_id' => 3, 'ezcontentobject_version_version' => 1],
558
        ];
559
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

Loading history...
560
            ->method('loadContentList')
561
            ->with($this->equalTo($idVersionTranslationPairs))
562
            ->willReturn($contentRows);
563
564
        $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...
565
            ->method('loadVersionedNameData')
566
            ->with($this->equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]]))
567
            ->willReturn([22]);
568
569
        $expected = [
570
            2 => $this->getContentFixtureForDraft(2, 2),
571
            3 => $this->getContentFixtureForDraft(3, 1)
572
        ];
573
        $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...
574
            ->method('extractContentFromRows')
575
            ->with($this->equalTo($contentRows), $this->equalTo([22]))
576
            ->willReturn($expected);
577
578
        $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...
579
            ->method('loadExternalFieldData')
580
            ->with($this->isInstanceOf(Content::class));
581
582
        $result = $handler->loadContentList([2, 3], ['eng-GB']);
583
584
        $this->assertEquals(
585
            $expected,
586
            $result
587
        );
588
    }
589
590
    /**
591
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId
592
     */
593 View Code Duplication
    public function testLoadContentInfoByRemoteId()
594
    {
595
        $contentInfoData = array(new ContentInfo());
596
        $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...
597
            ->method('loadContentInfoByRemoteId')
598
            ->with(
599
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
600
            )->will(
601
                $this->returnValue(array(42))
602
            );
603
604
        $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...
605
            ->method('extractContentInfoFromRow')
606
            ->with($this->equalTo(array(42)))
607
            ->will($this->returnValue($contentInfoData));
608
609
        $this->assertSame(
610
            $contentInfoData,
611
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
612
        );
613
    }
614
615
    /**
616
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
617
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
618
     */
619 View Code Duplication
    public function testLoadErrorNotFound()
620
    {
621
        $handler = $this->getContentHandler();
622
623
        $gatewayMock = $this->getGatewayMock();
624
625
        $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...
626
            ->method('load')
627
            ->will(
628
                $this->returnValue(array())
629
            );
630
631
        $result = $handler->load(23, 2, array('eng-GB'));
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

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

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

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

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

Loading history...
632
    }
633
634
    /**
635
     * Returns a Content for {@link testCreateDraftFromVersion()}.
636
     *
637
     * @param int $id Optional id
638
     * @param int $versionNo Optional version number
639
     *
640
     * @return \eZ\Publish\SPI\Persistence\Content
641
     */
642
    protected function getContentFixtureForDraft(int $id = 23, int $versionNo = 2)
643
    {
644
        $content = new Content();
645
        $content->versionInfo = new VersionInfo();
646
        $content->versionInfo->versionNo = $versionNo;
647
648
        $content->versionInfo->contentInfo = new ContentInfo(['id' => $id]);
649
650
        $field = new Field();
651
        $field->versionNo = $versionNo;
652
653
        $content->fields = [$field];
654
655
        return $content;
656
    }
657
658
    /**
659
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent
660
     */
661
    public function testUpdateContent()
662
    {
663
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
664
665
        $gatewayMock = $this->getGatewayMock();
666
        $fieldHandlerMock = $this->getFieldHandlerMock();
667
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
668
        $contentTypeMock = $this->createMock(Type::class);
669
        $contentStub = new Content(
670
            array(
671
                'versionInfo' => new VersionInfo(
672
                    array(
673
                        'contentInfo' => new ContentInfo(
674
                            array(
675
                                'contentTypeId' => 4242,
676
                            )
677
                        ),
678
                    )
679
                ),
680
            )
681
        );
682
683
        $contentTypeHandlerMock->expects($this->once())
684
            ->method('load')
685
            ->with($contentStub->versionInfo->contentInfo->contentTypeId)
686
            ->will($this->returnValue($contentTypeMock));
687
688
        $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...
689
            ->method('updateContent')
690
            ->with(14, $this->isInstanceOf(MetadataUpdateStruct::class));
691
        $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...
692
            ->method('updateVersion')
693
            ->with(14, 4, $this->isInstanceOf(UpdateStruct::class));
694
695
        $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...
696
            ->method('updateFields')
697
            ->with(
698
                $this->isInstanceOf(Content::class),
699
                $this->isInstanceOf(UpdateStruct::class),
700
                $this->isInstanceOf(Type::class)
701
            );
702
703
        $handler->expects($this->at(0))
704
            ->method('load')
705
            ->with(14, 4)
706
            ->will($this->returnValue($contentStub));
707
708
        $handler->expects($this->at(1))
709
            ->method('load')
710
            ->with(14, 4);
711
712
        $handler->expects($this->at(2))
713
            ->method('loadContentInfo')
714
            ->with(14);
715
716
        $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...
717
            14, // ContentId
718
            4, // VersionNo
719
            new UpdateStruct(
720
                array(
721
                    'creatorId' => 14,
722
                    'modificationDate' => time(),
723
                    'initialLanguageId' => 2,
724
                    'fields' => array(
725
                        new Field(
726
                            array(
727
                                'id' => 23,
728
                                'fieldDefinitionId' => 42,
729
                                'type' => 'some-type',
730
                                'value' => new FieldValue(),
731
                            )
732
                        ),
733
                        new Field(
734
                            array(
735
                                'id' => 23,
736
                                'fieldDefinitionId' => 43,
737
                                'type' => 'some-type',
738
                                'value' => new FieldValue(),
739
                            )
740
                        ),
741
                    ),
742
                )
743
            )
744
        );
745
746
        $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...
747
            14, // ContentId
748
            new MetadataUpdateStruct(
749
                array(
750
                    'ownerId' => 14,
751
                    'name' => 'Some name',
752
                    'modificationDate' => time(),
753
                    'alwaysAvailable' => true,
754
                )
755
            )
756
        );
757
    }
758
759
    /**
760
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
761
     */
762
    public function testUpdateMetadata()
763
    {
764
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
765
766
        $gatewayMock = $this->getGatewayMock();
767
        $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...
768
        $updateStruct = new MetadataUpdateStruct(
769
            array(
770
                'ownerId' => 14,
771
                'name' => 'Some name',
772
                'modificationDate' => time(),
773
                'alwaysAvailable' => true,
774
            )
775
        );
776
777
        $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...
778
            ->method('updateContent')
779
            ->with(14, $updateStruct);
780
781
        $handler->expects($this->once())
782
            ->method('loadContentInfo')
783
            ->with(14)
784
            ->will(
785
                $this->returnValue(
786
                    $this->createMock(ContentInfo::class)
787
                )
788
            );
789
790
        $resultContentInfo = $handler->updateMetadata(
791
            14, // ContentId
792
            $updateStruct
793
        );
794
        self::assertInstanceOf(ContentInfo::class, $resultContentInfo);
795
    }
796
797
    /**
798
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
799
     */
800
    public function testUpdateMetadataUpdatesPathIdentificationString()
801
    {
802
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
803
        $locationGatewayMock = $this->getLocationGatewayMock();
804
        $slugConverterMock = $this->getSlugConverterMock();
805
        $urlAliasGatewayMock = $this->getUrlAliasGatewayMock();
806
        $gatewayMock = $this->getGatewayMock();
807
        $updateStruct = new MetadataUpdateStruct(array('mainLanguageId' => 2));
808
809
        $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...
810
            ->method('updateContent')
811
            ->with(14, $updateStruct);
812
813
        $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...
814
            ->method('loadLocationDataByContent')
815
            ->with(14)
816
            ->will(
817
                $this->returnValue(
818
                    array(
819
                        array(
820
                            'node_id' => 100,
821
                            'parent_node_id' => 200,
822
                        ),
823
                    )
824
                )
825
            );
826
827
        $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...
828
            ->method('loadLocationEntries')
829
            ->with(100, false, 2)
830
            ->will(
831
                $this->returnValue(
832
                    array(
833
                        array(
834
                            'text' => 'slug',
835
                        ),
836
                    )
837
                )
838
            );
839
840
        $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...
841
            ->method('convert')
842
            ->with('slug', 'node_100', 'urlalias_compat')
843
            ->will($this->returnValue('transformed_slug'));
844
845
        $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...
846
            ->method('updatePathIdentificationString')
847
            ->with(100, 200, 'transformed_slug');
848
849
        $handler->expects($this->once())
850
            ->method('loadContentInfo')
851
            ->with(14)
852
            ->will(
853
                $this->returnValue(
854
                    $this->createMock(ContentInfo::class)
855
                )
856
            );
857
858
        $handler->updateMetadata(
859
            14, // ContentId
860
            $updateStruct
861
        );
862
    }
863
864
    /**
865
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations
866
     */
867
    public function testLoadRelations()
868
    {
869
        $handler = $this->getContentHandler();
870
871
        $gatewayMock = $this->getGatewayMock();
872
        $mapperMock = $this->getMapperMock();
873
874
        $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...
875
            ->method('loadRelations')
876
            ->with(
877
                $this->equalTo(23),
878
                $this->equalTo(null),
879
                $this->equalTo(null)
880
            )->will(
881
                $this->returnValue(array(42))
882
            );
883
884
        $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...
885
            ->method('extractRelationsFromRows')
886
            ->with($this->equalTo(array(42)))
887
            ->will($this->returnValue($this->getRelationFixture()));
888
889
        $result = $handler->loadRelations(23);
890
891
        $this->assertEquals(
892
            $result,
893
            $this->getRelationFixture()
894
        );
895
    }
896
897
    /**
898
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations
899
     */
900
    public function testLoadReverseRelations()
901
    {
902
        $handler = $this->getContentHandler();
903
904
        $gatewayMock = $this->getGatewayMock();
905
        $mapperMock = $this->getMapperMock();
906
907
        $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...
908
            ->method('loadReverseRelations')
909
            ->with(
910
                $this->equalTo(23),
911
                $this->equalTo(null)
912
            )->will(
913
                $this->returnValue(array(42))
914
            );
915
916
        $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...
917
            ->method('extractRelationsFromRows')
918
            ->with($this->equalTo(array(42)))
919
            ->will($this->returnValue($this->getRelationFixture()));
920
921
        $result = $handler->loadReverseRelations(23);
922
923
        $this->assertEquals(
924
            $result,
925
            $this->getRelationFixture()
926
        );
927
    }
928
929
    public function testAddRelation()
930
    {
931
        // expected relation object after creation
932
        $expectedRelationObject = new Relation();
933
        $expectedRelationObject->id = 42; // mocked value, not a real one
934
        $expectedRelationObject->sourceContentId = 23;
935
        $expectedRelationObject->sourceContentVersionNo = 1;
936
        $expectedRelationObject->destinationContentId = 66;
937
        $expectedRelationObject->type = RelationValue::COMMON;
938
939
        // relation create struct
940
        $relationCreateStruct = new Relation\CreateStruct();
941
        $relationCreateStruct->destinationContentId = 66;
942
        $relationCreateStruct->sourceContentId = 23;
943
        $relationCreateStruct->sourceContentVersionNo = 1;
944
        $relationCreateStruct->type = RelationValue::COMMON;
945
946
        $handler = $this->getContentHandler();
947
948
        $gatewayMock = $this->getGatewayMock();
949
        $mapperMock = $this->getMapperMock();
950
951
        $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...
952
            ->method('createRelationFromCreateStruct')
953
            // @todo Connected with the todo above
954
            ->with($this->equalTo($relationCreateStruct))
955
            ->will($this->returnValue($expectedRelationObject));
956
957
        $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...
958
            ->method('insertRelation')
959
            ->with($this->equalTo($relationCreateStruct))
960
            ->will(
961
                // @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods
962
                $this->returnValue(42)
963
            );
964
965
        $result = $handler->addRelation($relationCreateStruct);
966
967
        $this->assertEquals(
968
            $result,
969
            $expectedRelationObject
970
        );
971
    }
972
973
    /**
974
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation
975
     */
976
    public function testRemoveRelation()
977
    {
978
        $gatewayMock = $this->getGatewayMock();
979
980
        $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...
981
            ->method('deleteRelation')
982
            ->with($this->equalTo(1, RelationValue::COMMON));
983
984
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
985
    }
986
987
    protected function getRelationFixture()
988
    {
989
        $relation = new Relation();
990
        $relation->sourceContentId = 23;
991
        $relation->sourceContentVersionNo = 1;
992
        $relation->destinationContentId = 69;
993
994
        return $relation;
995
    }
996
997
    /**
998
     * Returns a CreateStruct fixture.
999
     *
1000
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
1001
     */
1002
    public function getCreateStructFixture()
1003
    {
1004
        $struct = new CreateStruct();
1005
1006
        $struct->typeId = 4242;
1007
1008
        $firstField = new Field();
1009
        $firstField->type = 'some-type';
1010
        $firstField->value = new FieldValue();
1011
1012
        $secondField = clone $firstField;
1013
1014
        $struct->fields = array(
1015
            $firstField, $secondField,
1016
        );
1017
1018
        $struct->locations = array(
1019
            new LocationCreateStruct(
1020
                array('parentId' => 42)
1021
            ),
1022
        );
1023
1024
        $struct->name = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('eng-GB' => 'This is a test name') of type array<string,string,{"eng-GB":"string"}> is incompatible with the declared type array<integer,string> of property $name.

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

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

Loading history...
1025
            'eng-GB' => 'This is a test name',
1026
        );
1027
1028
        return $struct;
1029
    }
1030
1031
    /**
1032
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
1033
     */
1034
    public function testLoadDraftsForUser()
1035
    {
1036
        $handler = $this->getContentHandler();
1037
        $rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2));
1038
1039
        $gatewayMock = $this->getGatewayMock();
1040
        $mapperMock = $this->getMapperMock();
1041
1042
        $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...
1043
            ->method('listVersionsForUser')
1044
            ->with($this->equalTo(23))
1045
            ->will($this->returnValue($rows));
1046
1047
        $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...
1048
            ->method('loadVersionedNameData')
1049
            ->with($this->equalTo(array(array('id' => 42, 'version' => 2))))
1050
            ->will($this->returnValue(array()));
1051
1052
        $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...
1053
            ->method('extractVersionInfoListFromRows')
1054
            ->with($this->equalTo($rows), $this->equalTo(array()))
1055
            ->will($this->returnValue(array(new VersionInfo())));
1056
1057
        $res = $handler->loadDraftsForUser(23);
1058
1059
        $this->assertEquals(
1060
            array(new VersionInfo()),
1061
            $res
1062
        );
1063
    }
1064
1065
    public function testListVersions()
1066
    {
1067
        $handler = $this->getContentHandler();
1068
1069
        $treeHandlerMock = $this->getTreeHandlerMock();
1070
1071
        $treeHandlerMock
1072
            ->expects($this->once())
1073
            ->method('listVersions')
1074
            ->with(23)
1075
            ->will($this->returnValue(array(new VersionInfo())));
1076
1077
        $versions = $handler->listVersions(23);
1078
1079
        $this->assertEquals(
1080
            array(new VersionInfo()),
1081
            $versions
1082
        );
1083
    }
1084
1085
    public function testRemoveRawContent()
1086
    {
1087
        $handler = $this->getContentHandler();
1088
        $treeHandlerMock = $this->getTreeHandlerMock();
1089
1090
        $treeHandlerMock
1091
            ->expects($this->once())
1092
            ->method('removeRawContent')
1093
            ->with(23);
1094
1095
        $handler->removeRawContent(23);
1096
    }
1097
1098
    /**
1099
     * Test for the deleteContent() method.
1100
     *
1101
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1102
     */
1103
    public function testDeleteContentWithLocations()
1104
    {
1105
        $handlerMock = $this->getPartlyMockedHandler(array('getAllLocationIds'));
1106
        $gatewayMock = $this->getGatewayMock();
1107
        $treeHandlerMock = $this->getTreeHandlerMock();
1108
1109
        $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...
1110
            ->method('getAllLocationIds')
1111
            ->with($this->equalTo(23))
1112
            ->will($this->returnValue(array(42, 24)));
1113
        $treeHandlerMock->expects($this->exactly(2))
1114
            ->method('removeSubtree')
1115
            ->with(
1116
                $this->logicalOr(
1117
                    $this->equalTo(42),
1118
                    $this->equalTo(24)
1119
                )
1120
            );
1121
1122
        $handlerMock->deleteContent(23);
1123
    }
1124
1125
    /**
1126
     * Test for the deleteContent() method.
1127
     *
1128
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1129
     */
1130
    public function testDeleteContentWithoutLocations()
1131
    {
1132
        $handlerMock = $this->getPartlyMockedHandler(array('removeRawContent'));
1133
        $gatewayMock = $this->getGatewayMock();
1134
1135
        $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...
1136
            ->method('getAllLocationIds')
1137
            ->with($this->equalTo(23))
1138
            ->will($this->returnValue(array()));
1139
        $handlerMock->expects($this->once())
1140
            ->method('removeRawContent')
1141
            ->with($this->equalTo(23));
1142
1143
        $handlerMock->deleteContent(23);
1144
    }
1145
1146
    /**
1147
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1148
     */
1149
    public function testDeleteVersion()
1150
    {
1151
        $handler = $this->getContentHandler();
1152
1153
        $gatewayMock = $this->getGatewayMock();
1154
        $mapperMock = $this->getMapperMock();
1155
        $locationHandlerMock = $this->getLocationGatewayMock();
1156
        $fieldHandlerMock = $this->getFieldHandlerMock();
1157
1158
        // Load VersionInfo to delete fields
1159
        $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...
1160
            ->method('loadVersionInfo')
1161
            ->with($this->equalTo(225), $this->equalTo(2))
1162
            ->will($this->returnValue(array(42)));
1163
1164
        $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...
1165
            ->method('loadVersionedNameData')
1166
            ->with($this->equalTo(array(array('id' => 225, 'version' => 2))))
1167
            ->will($this->returnValue(array(22)));
1168
1169
        $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...
1170
            ->method('extractVersionInfoListFromRows')
1171
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
1172
            ->will($this->returnValue(array(new VersionInfo())));
1173
1174
        $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...
1175
            ->method('deleteNodeAssignment')
1176
            ->with(
1177
                $this->equalTo(225),
1178
                $this->equalTo(2)
1179
            );
1180
1181
        $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...
1182
            ->method('deleteFields')
1183
            ->with(
1184
                $this->equalTo(225),
1185
                $this->isInstanceOf(VersionInfo::class)
1186
            );
1187
        $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...
1188
            ->method('deleteRelations')
1189
            ->with(
1190
                $this->equalTo(225),
1191
                $this->equalTo(2)
1192
            );
1193
        $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...
1194
            ->method('deleteVersions')
1195
            ->with(
1196
                $this->equalTo(225),
1197
                $this->equalTo(2)
1198
            );
1199
        $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...
1200
            ->method('deleteNames')
1201
            ->with(
1202
                $this->equalTo(225),
1203
                $this->equalTo(2)
1204
            );
1205
1206
        $handler->deleteVersion(225, 2);
1207
    }
1208
1209
    /**
1210
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1211
     */
1212
    public function testCopySingleVersion()
1213
    {
1214
        $handler = $this->getPartlyMockedHandler(array('load', 'internalCreate'));
1215
        $gatewayMock = $this->getGatewayMock();
1216
        $mapperMock = $this->getMapperMock();
1217
1218
        $handler->expects(
1219
            $this->once()
1220
        )->method(
1221
            'load'
1222
        )->with(
1223
            $this->equalTo(23),
1224
            $this->equalTo(32)
1225
        )->will(
1226
            $this->returnValue(new Content())
1227
        );
1228
1229
        $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...
1230
            $this->once()
1231
        )->method(
1232
            'createCreateStructFromContent'
1233
        )->with(
1234
            $this->isInstanceOf(Content::class)
1235
        )->will(
1236
            $this->returnValue(new CreateStruct())
1237
        );
1238
1239
        $handler->expects(
1240
            $this->once()
1241
        )->method(
1242
            'internalCreate'
1243
        )->with(
1244
            $this->isInstanceOf(CreateStruct::class),
1245
            $this->equalTo(32)
1246
        )->will(
1247
            $this->returnValue(
1248
                new Content(
1249
                    [
1250
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1251
                    ]
1252
                )
1253
            )
1254
        );
1255
1256
        $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...
1257
            ->method('copyRelations')
1258
            ->with(
1259
                $this->equalTo(23),
1260
                $this->equalTo(24),
1261
                $this->equalTo(32)
1262
            )
1263
            ->will($this->returnValue(null));
1264
1265
        $result = $handler->copy(23, 32);
1266
1267
        $this->assertInstanceOf(
1268
            Content::class,
1269
            $result
1270
        );
1271
    }
1272
1273
    /**
1274
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1275
     */
1276
    public function testCopyAllVersions()
1277
    {
1278
        $handler = $this->getPartlyMockedHandler(
1279
            array(
1280
                'loadContentInfo',
1281
                'load',
1282
                'internalCreate',
1283
                'listVersions',
1284
            )
1285
        );
1286
        $gatewayMock = $this->getGatewayMock();
1287
        $mapperMock = $this->getMapperMock();
1288
        $fieldHandlerMock = $this->getFieldHandlerMock();
1289
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1290
        $contentTypeMock = $this->createMock(Type::class);
1291
        $time = time();
1292
        $createStructStub = new CreateStruct(
1293
            array(
1294
                'modified' => $time,
1295
                'typeId' => 4242,
1296
            )
1297
        );
1298
1299
        $contentTypeHandlerMock->expects($this->once())
1300
            ->method('load')
1301
            ->with($createStructStub->typeId)
1302
            ->will($this->returnValue($contentTypeMock));
1303
1304
        $handler->expects($this->once())
1305
            ->method('loadContentInfo')
1306
            ->with($this->equalTo(23))
1307
            ->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2))));
1308
1309
        $handler->expects($this->at(1))
1310
            ->method('load')
1311
            ->with($this->equalTo(23), $this->equalTo(2))
1312
            ->will($this->returnValue(new Content()));
1313
1314
        $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...
1315
            ->method('createCreateStructFromContent')
1316
            ->with($this->isInstanceOf(Content::class))
1317
            ->will(
1318
                $this->returnValue($createStructStub)
1319
            );
1320
1321
        $handler->expects($this->once())
1322
            ->method('internalCreate')
1323
            ->with(
1324
                $this->isInstanceOf(CreateStruct::class),
1325
                $this->equalTo(2)
1326
            )->will(
1327
                $this->returnValue(
1328
                    new Content(
1329
                        array(
1330
                            'versionInfo' => new VersionInfo(
1331
                                array(
1332
                                    'contentInfo' => new ContentInfo(array('id' => 24)),
1333
                                )
1334
                            ),
1335
                        )
1336
                    )
1337
                )
1338
            );
1339
1340
        $handler->expects($this->once())
1341
            ->method('listVersions')
1342
            ->with($this->equalTo(23))
1343
            ->will(
1344
                $this->returnValue(
1345
                    array(
1346
                        new VersionInfo(array('versionNo' => 1)),
1347
                        new VersionInfo(array('versionNo' => 2)),
1348
                    )
1349
                )
1350
            );
1351
1352
        $versionInfo = new VersionInfo(
1353
            array(
1354
                'names' => array('eng-US' => 'Test'),
1355
                'contentInfo' => new ContentInfo(
1356
                    array(
1357
                        'id' => 24,
1358
                        'alwaysAvailable' => true,
1359
                    )
1360
                ),
1361
            )
1362
        );
1363
        $handler->expects($this->at(4))
1364
            ->method('load')
1365
            ->with($this->equalTo(23), $this->equalTo(1))
1366
            ->will(
1367
                $this->returnValue(
1368
                    new Content(
1369
                        array(
1370
                            'versionInfo' => $versionInfo,
1371
                            'fields' => array(),
1372
                        )
1373
                    )
1374
                )
1375
            );
1376
1377
        $versionInfo->creationDate = $time;
1378
        $versionInfo->modificationDate = $time;
1379
        $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...
1380
            ->method('insertVersion')
1381
            ->with(
1382
                $this->equalTo($versionInfo),
1383
                $this->isType('array')
1384
            )->will($this->returnValue(42));
1385
1386
        $versionInfo = clone $versionInfo;
1387
        $versionInfo->id = 42;
1388
        $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...
1389
            ->method('createNewFields')
1390
            ->with(
1391
                $this->equalTo(
1392
                    new Content(
1393
                        array(
1394
                            'versionInfo' => $versionInfo,
1395
                            'fields' => array(),
1396
                        )
1397
                    )
1398
                ),
1399
                $this->isInstanceOf(Type::class)
1400
            );
1401
1402
        $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...
1403
            ->method('setName')
1404
            ->with(
1405
                $this->equalTo(24),
1406
                $this->equalTo(1),
1407
                $this->equalTo('Test'),
1408
                $this->equalTo('eng-US')
1409
            );
1410
1411
        $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...
1412
            ->method('copyRelations')
1413
            ->with(
1414
                $this->equalTo(23),
1415
                $this->equalTo(24),
1416
                $this->equalTo(null)
1417
            )
1418
            ->will($this->returnValue(null));
1419
1420
        $result = $handler->copy(23);
1421
1422
        $this->assertInstanceOf(
1423
            Content::class,
1424
            $result
1425
        );
1426
    }
1427
1428
    /**
1429
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1430
     */
1431
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1432
    {
1433
        $handler = $this->getContentHandler();
1434
1435
        $treeHandlerMock = $this->getTreeHandlerMock();
1436
        $treeHandlerMock
1437
            ->expects($this->once())
1438
            ->method('loadContentInfo')
1439
            ->with($this->equalTo(23))
1440
            ->will(
1441
                $this->throwException(new NotFoundException('ContentInfo', 23))
1442
            );
1443
1444
        $handler->copy(23);
1445
    }
1446
1447
    /**
1448
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1449
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1450
     */
1451 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1452
    {
1453
        $handler = $this->getContentHandler();
1454
1455
        $gatewayMock = $this->getGatewayMock();
1456
        $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...
1457
            ->method('load')
1458
            ->with($this->equalTo(23, 32))
1459
            ->will($this->returnValue(array()));
1460
1461
        $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...
1462
    }
1463
1464
    /**
1465
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1466
     */
1467 View Code Duplication
    public function testSetStatus()
1468
    {
1469
        $handler = $this->getContentHandler();
1470
1471
        $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...
1472
        $gatewayMock = $this->getGatewayMock();
1473
1474
        $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...
1475
            ->method('setStatus')
1476
            ->with(23, 5, 2)
1477
            ->will($this->returnValue(true));
1478
1479
        $this->assertTrue(
1480
            $handler->setStatus(23, 2, 5)
1481
        );
1482
    }
1483
1484
    /**
1485
     * Returns the handler to test.
1486
     *
1487
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1488
     */
1489
    protected function getContentHandler()
1490
    {
1491
        if (!isset($this->contentHandler)) {
1492
            $this->contentHandler = new Handler(
1493
                $this->getGatewayMock(),
1494
                $this->getLocationGatewayMock(),
1495
                $this->getMapperMock(),
1496
                $this->getFieldHandlerMock(),
1497
                $this->getSlugConverterMock(),
1498
                $this->getUrlAliasGatewayMock(),
1499
                $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...
1500
                $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...
1501
            );
1502
        }
1503
1504
        return $this->contentHandler;
1505
    }
1506
1507
    /**
1508
     * Returns the handler to test with $methods mocked.
1509
     *
1510
     * @param string[] $methods
1511
     *
1512
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1513
     */
1514
    protected function getPartlyMockedHandler(array $methods)
1515
    {
1516
        return $this->getMockBuilder(Handler::class)
1517
            ->setMethods($methods)
1518
            ->setConstructorArgs(
1519
                array(
1520
                    $this->getGatewayMock(),
1521
                    $this->getLocationGatewayMock(),
1522
                    $this->getMapperMock(),
1523
                    $this->getFieldHandlerMock(),
1524
                    $this->getSlugConverterMock(),
1525
                    $this->getUrlAliasGatewayMock(),
1526
                    $this->getContentTypeHandlerMock(),
1527
                    $this->getTreeHandlerMock(),
1528
                )
1529
            )
1530
            ->getMock();
1531
    }
1532
1533
    /**
1534
     * Returns a TreeHandler mock.
1535
     *
1536
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1537
     */
1538
    protected function getTreeHandlerMock()
1539
    {
1540
        if (!isset($this->treeHandlerMock)) {
1541
            $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...
1542
        }
1543
1544
        return $this->treeHandlerMock;
1545
    }
1546
1547
    /**
1548
     * Returns a ContentTypeHandler mock.
1549
     *
1550
     * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1551
     */
1552
    protected function getContentTypeHandlerMock()
1553
    {
1554
        if (!isset($this->contentTypeHandlerMock)) {
1555
            $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...
1556
        }
1557
1558
        return $this->contentTypeHandlerMock;
1559
    }
1560
1561
    /**
1562
     * Returns a FieldHandler mock.
1563
     *
1564
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1565
     */
1566
    protected function getFieldHandlerMock()
1567
    {
1568
        if (!isset($this->fieldHandlerMock)) {
1569
            $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...
1570
        }
1571
1572
        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 1572 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...
1573
    }
1574
1575
    /**
1576
     * Returns a Mapper mock.
1577
     *
1578
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1579
     */
1580
    protected function getMapperMock()
1581
    {
1582
        if (!isset($this->mapperMock)) {
1583
            $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...
1584
        }
1585
1586
        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 1586 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...
1587
    }
1588
1589
    /**
1590
     * Returns a Location Gateway mock.
1591
     *
1592
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1593
     */
1594
    protected function getLocationGatewayMock()
1595
    {
1596
        if (!isset($this->locationGatewayMock)) {
1597
            $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...
1598
        }
1599
1600
        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 1600 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...
1601
    }
1602
1603
    /**
1604
     * Returns a Content Type gateway mock.
1605
     *
1606
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1607
     */
1608
    protected function getTypeGatewayMock()
1609
    {
1610
        if (!isset($this->typeGatewayMock)) {
1611
            $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...
1612
        }
1613
1614
        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 1614 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...
1615
    }
1616
1617
    /**
1618
     * Returns a mock object for the Content Gateway.
1619
     *
1620
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
1621
     */
1622
    protected function getGatewayMock()
1623
    {
1624
        if (!isset($this->gatewayMock)) {
1625
            $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...
1626
        }
1627
1628
        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 1628 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...
1629
    }
1630
1631
    /**
1632
     * Returns a mock object for the UrlAlias Handler.
1633
     *
1634
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1635
     */
1636
    protected function getSlugConverterMock()
1637
    {
1638
        if (!isset($this->slugConverterMock)) {
1639
            $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...
1640
        }
1641
1642
        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 1642 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...
1643
    }
1644
1645
    /**
1646
     * Returns a mock object for the UrlAlias Gateway.
1647
     *
1648
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1649
     */
1650
    protected function getUrlAliasGatewayMock()
1651
    {
1652
        if (!isset($this->urlAliasGatewayMock)) {
1653
            $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...
1654
        }
1655
1656
        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 1656 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...
1657
    }
1658
}
1659