Completed
Push — master ( 65f512...fe0390 )
by Łukasz
26:26
created

testLoadContentInfoByRemoteId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Persistence\Legacy\Tests\Content;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\SPI\Persistence\Content;
13
use eZ\Publish\SPI\Persistence\Content\Type;
14
use eZ\Publish\SPI\Persistence\Content\ContentInfo;
15
use eZ\Publish\SPI\Persistence\Content\Field;
16
use eZ\Publish\SPI\Persistence\Content\FieldValue;
17
use eZ\Publish\SPI\Persistence\Content\VersionInfo;
18
use eZ\Publish\SPI\Persistence\Content\CreateStruct;
19
use eZ\Publish\SPI\Persistence\Content\UpdateStruct;
20
use eZ\Publish\SPI\Persistence\Content\Relation;
21
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct;
22
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct as LocationCreateStruct;
23
use eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Handler;
25
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue;
26
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
27
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
28
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
29
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter;
30
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
31
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway;
32
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
33
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper;
34
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler;
35
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
36
37
/**
38
 * Test case for Content Handler.
39
 */
40
class ContentHandlerTest extends TestCase
41
{
42
    /**
43
     * Content handler to test.
44
     *
45
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler
46
     */
47
    protected $contentHandler;
48
49
    /**
50
     * Gateway mock.
51
     *
52
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
53
     */
54
    protected $gatewayMock;
55
56
    /**
57
     * Location gateway mock.
58
     *
59
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
60
     */
61
    protected $locationGatewayMock;
62
63
    /**
64
     * Type gateway mock.
65
     *
66
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
67
     */
68
    protected $typeGatewayMock;
69
70
    /**
71
     * Mapper mock.
72
     *
73
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
74
     */
75
    protected $mapperMock;
76
77
    /**
78
     * Field handler mock.
79
     *
80
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
81
     */
82
    protected $fieldHandlerMock;
83
84
    /**
85
     * Location handler mock.
86
     *
87
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
88
     */
89
    protected $treeHandlerMock;
90
91
    /**
92
     * Slug converter mock.
93
     *
94
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
95
     */
96
    protected $slugConverterMock;
97
98
    /**
99
     * Location handler mock.
100
     *
101
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
102
     */
103
    protected $urlAliasGatewayMock;
104
105
    /**
106
     * ContentType handler mock.
107
     *
108
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
109
     */
110
    protected $contentTypeHandlerMock;
111
112
    /**
113
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::__construct
114
     */
115 View Code Duplication
    public function testCtor()
116
    {
117
        $handler = $this->getContentHandler();
118
119
        $this->assertAttributeSame(
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
        $idVersionTranslationPairs = [
534
            ['id' => 2, 'version' => 2, 'languages' => ['eng-GB']],
535
            ['id' => 3, 'version' => null, 'languages' => ['eng-GB', 'eng-US']],
536
        ];
537
        $contentRows = [
538
            ['ezcontentobject_id' => 2, 'ezcontentobject_version_version' => 2],
539
            ['ezcontentobject_id' => 3, 'ezcontentobject_version_version' => 1],
540
        ];
541
        $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...
542
            ->method('loadContentList')
543
            ->with($this->equalTo($idVersionTranslationPairs))
544
            ->willReturn($contentRows);
545
546
        $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...
547
            ->method('loadVersionedNameData')
548
            ->with($this->equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]]))
549
            ->willReturn([22]);
550
551
        $expected = [
552
            2 => $this->getContentFixtureForDraft(2, 2),
553
            3 => $this->getContentFixtureForDraft(3, 1),
554
        ];
555
        $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...
556
            ->method('extractContentFromRows')
557
            ->with($this->equalTo($contentRows), $this->equalTo([22]))
558
            ->willReturn($expected);
559
560
        $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...
561
            ->method('loadExternalFieldData')
562
            ->with($this->isInstanceOf(Content::class));
563
564
        $loadStructList = [
565
          new Content\LoadStruct(['id' => 2, 'versionNo' => 2, 'languages' => ['eng-GB']]),
566
          new Content\LoadStruct(['id' => 3, 'languages' => ['eng-GB', 'eng-US']]),
567
        ];
568
569
        $result = $handler->loadContentList($loadStructList);
570
571
        $this->assertEquals(
572
            $expected,
573
            $result
574
        );
575
    }
576
577
    /**
578
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId
579
     */
580 View Code Duplication
    public function testLoadContentInfoByRemoteId()
581
    {
582
        $contentInfoData = array(new ContentInfo());
583
        $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...
584
            ->method('loadContentInfoByRemoteId')
585
            ->with(
586
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
587
            )->will(
588
                $this->returnValue(array(42))
589
            );
590
591
        $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...
592
            ->method('extractContentInfoFromRow')
593
            ->with($this->equalTo(array(42)))
594
            ->will($this->returnValue($contentInfoData));
595
596
        $this->assertSame(
597
            $contentInfoData,
598
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
599
        );
600
    }
601
602
    /**
603
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
604
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
605
     */
606 View Code Duplication
    public function testLoadErrorNotFound()
607
    {
608
        $handler = $this->getContentHandler();
609
610
        $gatewayMock = $this->getGatewayMock();
611
612
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

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

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

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

Loading history...
968
            ->method('deleteRelation')
969
            ->with($this->equalTo(1, RelationValue::COMMON));
970
971
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
972
    }
973
974
    protected function getRelationFixture()
975
    {
976
        $relation = new Relation();
977
        $relation->sourceContentId = 23;
978
        $relation->sourceContentVersionNo = 1;
979
        $relation->destinationContentId = 69;
980
981
        return $relation;
982
    }
983
984
    /**
985
     * Returns a CreateStruct fixture.
986
     *
987
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
988
     */
989
    public function getCreateStructFixture()
990
    {
991
        $struct = new CreateStruct();
992
993
        $struct->typeId = 4242;
994
995
        $firstField = new Field();
996
        $firstField->type = 'some-type';
997
        $firstField->value = new FieldValue();
998
999
        $secondField = clone $firstField;
1000
1001
        $struct->fields = array(
1002
            $firstField, $secondField,
1003
        );
1004
1005
        $struct->locations = array(
1006
            new LocationCreateStruct(
1007
                array('parentId' => 42)
1008
            ),
1009
        );
1010
1011
        $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...
1012
            'eng-GB' => 'This is a test name',
1013
        );
1014
1015
        return $struct;
1016
    }
1017
1018
    /**
1019
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
1020
     */
1021
    public function testLoadDraftsForUser()
1022
    {
1023
        $handler = $this->getContentHandler();
1024
        $rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2));
1025
1026
        $gatewayMock = $this->getGatewayMock();
1027
        $mapperMock = $this->getMapperMock();
1028
1029
        $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...
1030
            ->method('listVersionsForUser')
1031
            ->with($this->equalTo(23))
1032
            ->will($this->returnValue($rows));
1033
1034
        $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...
1035
            ->method('loadVersionedNameData')
1036
            ->with($this->equalTo(array(array('id' => 42, 'version' => 2))))
1037
            ->will($this->returnValue(array()));
1038
1039
        $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...
1040
            ->method('extractVersionInfoListFromRows')
1041
            ->with($this->equalTo($rows), $this->equalTo(array()))
1042
            ->will($this->returnValue(array(new VersionInfo())));
1043
1044
        $res = $handler->loadDraftsForUser(23);
1045
1046
        $this->assertEquals(
1047
            array(new VersionInfo()),
1048
            $res
1049
        );
1050
    }
1051
1052
    public function testListVersions()
1053
    {
1054
        $handler = $this->getContentHandler();
1055
1056
        $treeHandlerMock = $this->getTreeHandlerMock();
1057
1058
        $treeHandlerMock
1059
            ->expects($this->once())
1060
            ->method('listVersions')
1061
            ->with(23)
1062
            ->will($this->returnValue(array(new VersionInfo())));
1063
1064
        $versions = $handler->listVersions(23);
1065
1066
        $this->assertEquals(
1067
            array(new VersionInfo()),
1068
            $versions
1069
        );
1070
    }
1071
1072
    public function testRemoveRawContent()
1073
    {
1074
        $handler = $this->getContentHandler();
1075
        $treeHandlerMock = $this->getTreeHandlerMock();
1076
1077
        $treeHandlerMock
1078
            ->expects($this->once())
1079
            ->method('removeRawContent')
1080
            ->with(23);
1081
1082
        $handler->removeRawContent(23);
1083
    }
1084
1085
    /**
1086
     * Test for the deleteContent() method.
1087
     *
1088
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1089
     */
1090
    public function testDeleteContentWithLocations()
1091
    {
1092
        $handlerMock = $this->getPartlyMockedHandler(array('getAllLocationIds'));
1093
        $gatewayMock = $this->getGatewayMock();
1094
        $treeHandlerMock = $this->getTreeHandlerMock();
1095
1096
        $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...
1097
            ->method('getAllLocationIds')
1098
            ->with($this->equalTo(23))
1099
            ->will($this->returnValue(array(42, 24)));
1100
        $treeHandlerMock->expects($this->exactly(2))
1101
            ->method('removeSubtree')
1102
            ->with(
1103
                $this->logicalOr(
1104
                    $this->equalTo(42),
1105
                    $this->equalTo(24)
1106
                )
1107
            );
1108
1109
        $handlerMock->deleteContent(23);
1110
    }
1111
1112
    /**
1113
     * Test for the deleteContent() method.
1114
     *
1115
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1116
     */
1117
    public function testDeleteContentWithoutLocations()
1118
    {
1119
        $handlerMock = $this->getPartlyMockedHandler(array('removeRawContent'));
1120
        $gatewayMock = $this->getGatewayMock();
1121
1122
        $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...
1123
            ->method('getAllLocationIds')
1124
            ->with($this->equalTo(23))
1125
            ->will($this->returnValue(array()));
1126
        $handlerMock->expects($this->once())
1127
            ->method('removeRawContent')
1128
            ->with($this->equalTo(23));
1129
1130
        $handlerMock->deleteContent(23);
1131
    }
1132
1133
    /**
1134
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1135
     */
1136
    public function testDeleteVersion()
1137
    {
1138
        $handler = $this->getContentHandler();
1139
1140
        $gatewayMock = $this->getGatewayMock();
1141
        $mapperMock = $this->getMapperMock();
1142
        $locationHandlerMock = $this->getLocationGatewayMock();
1143
        $fieldHandlerMock = $this->getFieldHandlerMock();
1144
1145
        // Load VersionInfo to delete fields
1146
        $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...
1147
            ->method('loadVersionInfo')
1148
            ->with($this->equalTo(225), $this->equalTo(2))
1149
            ->will($this->returnValue(array(42)));
1150
1151
        $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...
1152
            ->method('loadVersionedNameData')
1153
            ->with($this->equalTo(array(array('id' => 225, 'version' => 2))))
1154
            ->will($this->returnValue(array(22)));
1155
1156
        $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...
1157
            ->method('extractVersionInfoListFromRows')
1158
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
1159
            ->will($this->returnValue(array(new VersionInfo())));
1160
1161
        $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...
1162
            ->method('deleteNodeAssignment')
1163
            ->with(
1164
                $this->equalTo(225),
1165
                $this->equalTo(2)
1166
            );
1167
1168
        $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...
1169
            ->method('deleteFields')
1170
            ->with(
1171
                $this->equalTo(225),
1172
                $this->isInstanceOf(VersionInfo::class)
1173
            );
1174
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

Loading history...
1175
            ->method('deleteRelations')
1176
            ->with(
1177
                $this->equalTo(225),
1178
                $this->equalTo(2)
1179
            );
1180
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

Loading history...
1181
            ->method('deleteVersions')
1182
            ->with(
1183
                $this->equalTo(225),
1184
                $this->equalTo(2)
1185
            );
1186
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

Loading history...
1187
            ->method('deleteNames')
1188
            ->with(
1189
                $this->equalTo(225),
1190
                $this->equalTo(2)
1191
            );
1192
1193
        $handler->deleteVersion(225, 2);
1194
    }
1195
1196
    /**
1197
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1198
     */
1199
    public function testCopySingleVersion()
1200
    {
1201
        $handler = $this->getPartlyMockedHandler(array('load', 'internalCreate'));
1202
        $gatewayMock = $this->getGatewayMock();
1203
        $mapperMock = $this->getMapperMock();
1204
1205
        $handler->expects(
1206
            $this->once()
1207
        )->method(
1208
            'load'
1209
        )->with(
1210
            $this->equalTo(23),
1211
            $this->equalTo(32)
1212
        )->will(
1213
            $this->returnValue(new Content())
1214
        );
1215
1216
        $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...
1217
            $this->once()
1218
        )->method(
1219
            'createCreateStructFromContent'
1220
        )->with(
1221
            $this->isInstanceOf(Content::class)
1222
        )->will(
1223
            $this->returnValue(new CreateStruct())
1224
        );
1225
1226
        $handler->expects(
1227
            $this->once()
1228
        )->method(
1229
            'internalCreate'
1230
        )->with(
1231
            $this->isInstanceOf(CreateStruct::class),
1232
            $this->equalTo(32)
1233
        )->will(
1234
            $this->returnValue(
1235
                new Content(
1236
                    [
1237
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1238
                    ]
1239
                )
1240
            )
1241
        );
1242
1243
        $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...
1244
            ->method('copyRelations')
1245
            ->with(
1246
                $this->equalTo(23),
1247
                $this->equalTo(24),
1248
                $this->equalTo(32)
1249
            )
1250
            ->will($this->returnValue(null));
1251
1252
        $result = $handler->copy(23, 32);
1253
1254
        $this->assertInstanceOf(
1255
            Content::class,
1256
            $result
1257
        );
1258
    }
1259
1260
    /**
1261
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1262
     */
1263
    public function testCopyAllVersions()
1264
    {
1265
        $handler = $this->getPartlyMockedHandler(
1266
            array(
1267
                'loadContentInfo',
1268
                'load',
1269
                'internalCreate',
1270
                'listVersions',
1271
            )
1272
        );
1273
        $gatewayMock = $this->getGatewayMock();
1274
        $mapperMock = $this->getMapperMock();
1275
        $fieldHandlerMock = $this->getFieldHandlerMock();
1276
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1277
        $contentTypeMock = $this->createMock(Type::class);
1278
        $time = time();
1279
        $createStructStub = new CreateStruct(
1280
            array(
1281
                'modified' => $time,
1282
                'typeId' => 4242,
1283
            )
1284
        );
1285
1286
        $contentTypeHandlerMock->expects($this->once())
1287
            ->method('load')
1288
            ->with($createStructStub->typeId)
1289
            ->will($this->returnValue($contentTypeMock));
1290
1291
        $handler->expects($this->once())
1292
            ->method('loadContentInfo')
1293
            ->with($this->equalTo(23))
1294
            ->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2))));
1295
1296
        $handler->expects($this->at(1))
1297
            ->method('load')
1298
            ->with($this->equalTo(23), $this->equalTo(2))
1299
            ->will($this->returnValue(new Content()));
1300
1301
        $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...
1302
            ->method('createCreateStructFromContent')
1303
            ->with($this->isInstanceOf(Content::class))
1304
            ->will(
1305
                $this->returnValue($createStructStub)
1306
            );
1307
1308
        $handler->expects($this->once())
1309
            ->method('internalCreate')
1310
            ->with(
1311
                $this->isInstanceOf(CreateStruct::class),
1312
                $this->equalTo(2)
1313
            )->will(
1314
                $this->returnValue(
1315
                    new Content(
1316
                        array(
1317
                            'versionInfo' => new VersionInfo(
1318
                                array(
1319
                                    'contentInfo' => new ContentInfo(array('id' => 24)),
1320
                                )
1321
                            ),
1322
                        )
1323
                    )
1324
                )
1325
            );
1326
1327
        $handler->expects($this->once())
1328
            ->method('listVersions')
1329
            ->with($this->equalTo(23))
1330
            ->will(
1331
                $this->returnValue(
1332
                    array(
1333
                        new VersionInfo(array('versionNo' => 1)),
1334
                        new VersionInfo(array('versionNo' => 2)),
1335
                    )
1336
                )
1337
            );
1338
1339
        $versionInfo = new VersionInfo(
1340
            array(
1341
                'names' => array('eng-US' => 'Test'),
1342
                'contentInfo' => new ContentInfo(
1343
                    array(
1344
                        'id' => 24,
1345
                        'alwaysAvailable' => true,
1346
                    )
1347
                ),
1348
            )
1349
        );
1350
        $handler->expects($this->at(4))
1351
            ->method('load')
1352
            ->with($this->equalTo(23), $this->equalTo(1))
1353
            ->will(
1354
                $this->returnValue(
1355
                    new Content(
1356
                        array(
1357
                            'versionInfo' => $versionInfo,
1358
                            'fields' => array(),
1359
                        )
1360
                    )
1361
                )
1362
            );
1363
1364
        $versionInfo->creationDate = $time;
1365
        $versionInfo->modificationDate = $time;
1366
        $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...
1367
            ->method('insertVersion')
1368
            ->with(
1369
                $this->equalTo($versionInfo),
1370
                $this->isType('array')
1371
            )->will($this->returnValue(42));
1372
1373
        $versionInfo = clone $versionInfo;
1374
        $versionInfo->id = 42;
1375
        $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...
1376
            ->method('createNewFields')
1377
            ->with(
1378
                $this->equalTo(
1379
                    new Content(
1380
                        array(
1381
                            'versionInfo' => $versionInfo,
1382
                            'fields' => array(),
1383
                        )
1384
                    )
1385
                ),
1386
                $this->isInstanceOf(Type::class)
1387
            );
1388
1389
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

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