Completed
Push — EZP-28290 ( bebb28 )
by André
24:22
created

ContentHandlerTest   F

Complexity

Total Complexity 50

Size/Duplication

Total Lines 1548
Duplicated Lines 5.43 %

Coupling/Cohesion

Components 1
Dependencies 15

Importance

Changes 0
Metric Value
dl 84
loc 1548
rs 2.2022
c 0
b 0
f 0
wmc 50
lcom 1
cbo 15

40 Methods

Rating   Name   Duplication   Size   Complexity  
A testCtor() 21 21 1
B testCreate() 0 94 1
A testPublishFirstVersion() 0 68 1
A testPublish() 0 72 1
B testCreateDraftFromVersion() 0 87 1
B testLoad() 0 42 1
A testLoadContentInfoByRemoteId() 21 21 1
A testLoadErrorNotFound() 14 14 1
A getContentFixtureForDraft() 0 15 1
B testUpdateContent() 0 97 1
B testUpdateMetadata() 0 34 1
A testUpdateMetadataUpdatesPathIdentificationString() 0 63 1
B testLoadRelations() 0 29 1
B testLoadReverseRelations() 0 28 1
B testAddRelation() 0 43 1
A testRemoveRelation() 0 10 1
A getRelationFixture() 0 9 1
B getCreateStructFixture() 0 28 1
B testLoadDraftsForUser() 0 30 1
A testListVersions() 0 19 1
A testRemoveRawContent() 0 12 1
A testDeleteContentWithLocations() 0 21 1
A testDeleteContentWithoutLocations() 0 15 1
A testDeleteVersion() 0 59 1
A testCopySingleVersion() 0 60 1
B testCopyAllVersions() 0 151 1
A testCopyThrowsNotFoundExceptionContentNotFound() 0 15 1
A testCopyThrowsNotFoundExceptionVersionNotFound() 12 12 1
A testSetStatus() 16 16 1
A getContentHandler() 0 17 2
A getPartlyMockedHandler() 0 18 1
A getTreeHandlerMock() 0 8 2
A getContentTypeHandlerMock() 0 8 2
A getFieldHandlerMock() 0 8 2
A getMapperMock() 0 8 2
A getLocationGatewayMock() 0 8 2
A getTypeGatewayMock() 0 8 2
A getGatewayMock() 0 8 2
A getSlugConverterMock() 0 8 2
A getUrlAliasGatewayMock() 0 8 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ContentHandlerTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContentHandlerTest, and based on these observations, apply Extract Interface, too.

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))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
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::loadContentInfoByRemoteId
524
     */
525 View Code Duplication
    public function testLoadContentInfoByRemoteId()
526
    {
527
        $contentInfoData = array(new ContentInfo());
528
        $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...
529
            ->method('loadContentInfoByRemoteId')
530
            ->with(
531
                $this->equalTo('15b256dbea2ae72418ff5facc999e8f9')
532
            )->will(
533
                $this->returnValue(array(42))
534
            );
535
536
        $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...
537
            ->method('extractContentInfoFromRow')
538
            ->with($this->equalTo(array(42)))
539
            ->will($this->returnValue($contentInfoData));
540
541
        $this->assertSame(
542
            $contentInfoData,
543
            $this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9')
544
        );
545
    }
546
547
    /**
548
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load
549
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
550
     */
551 View Code Duplication
    public function testLoadErrorNotFound()
552
    {
553
        $handler = $this->getContentHandler();
554
555
        $gatewayMock = $this->getGatewayMock();
556
557
        $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...
558
            ->method('load')
559
            ->will(
560
                $this->returnValue(array())
561
            );
562
563
        $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...
564
    }
565
566
    /**
567
     * Returns a Content for {@link testCreateDraftFromVersion()}.
568
     *
569
     * @return \eZ\Publish\SPI\Persistence\Content
570
     */
571
    protected function getContentFixtureForDraft()
572
    {
573
        $content = new Content();
574
        $content->versionInfo = new VersionInfo();
575
        $content->versionInfo->versionNo = 2;
576
577
        $content->versionInfo->contentInfo = new ContentInfo();
578
579
        $field = new Field();
580
        $field->versionNo = 2;
581
582
        $content->fields = array($field);
583
584
        return $content;
585
    }
586
587
    /**
588
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent
589
     */
590
    public function testUpdateContent()
591
    {
592
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
593
594
        $gatewayMock = $this->getGatewayMock();
595
        $fieldHandlerMock = $this->getFieldHandlerMock();
596
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
597
        $contentTypeMock = $this->createMock(Type::class);
598
        $contentStub = new Content(
599
            array(
600
                'versionInfo' => new VersionInfo(
601
                    array(
602
                        'contentInfo' => new ContentInfo(
603
                            array(
604
                                'contentTypeId' => 4242,
605
                            )
606
                        ),
607
                    )
608
                ),
609
            )
610
        );
611
612
        $contentTypeHandlerMock->expects($this->once())
613
            ->method('load')
614
            ->with($contentStub->versionInfo->contentInfo->contentTypeId)
615
            ->will($this->returnValue($contentTypeMock));
616
617
        $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...
618
            ->method('updateContent')
619
            ->with(14, $this->isInstanceOf(MetadataUpdateStruct::class));
620
        $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...
621
            ->method('updateVersion')
622
            ->with(14, 4, $this->isInstanceOf(UpdateStruct::class));
623
624
        $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...
625
            ->method('updateFields')
626
            ->with(
627
                $this->isInstanceOf(Content::class),
628
                $this->isInstanceOf(UpdateStruct::class),
629
                $this->isInstanceOf(Type::class)
630
            );
631
632
        $handler->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

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

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

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

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

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

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

Loading history...
642
            ->method('loadContentInfo')
643
            ->with(14);
644
645
        $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...
646
            14, // ContentId
647
            4, // VersionNo
648
            new UpdateStruct(
649
                array(
650
                    'creatorId' => 14,
651
                    'modificationDate' => time(),
652
                    'initialLanguageId' => 2,
653
                    'fields' => array(
654
                        new Field(
655
                            array(
656
                                'id' => 23,
657
                                'fieldDefinitionId' => 42,
658
                                'type' => 'some-type',
659
                                'value' => new FieldValue(),
660
                            )
661
                        ),
662
                        new Field(
663
                            array(
664
                                'id' => 23,
665
                                'fieldDefinitionId' => 43,
666
                                'type' => 'some-type',
667
                                'value' => new FieldValue(),
668
                            )
669
                        ),
670
                    ),
671
                )
672
            )
673
        );
674
675
        $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...
676
            14, // ContentId
677
            new MetadataUpdateStruct(
678
                array(
679
                    'ownerId' => 14,
680
                    'name' => 'Some name',
681
                    'modificationDate' => time(),
682
                    'alwaysAvailable' => true,
683
                )
684
            )
685
        );
686
    }
687
688
    /**
689
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
690
     */
691
    public function testUpdateMetadata()
692
    {
693
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
694
695
        $gatewayMock = $this->getGatewayMock();
696
        $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...
697
        $updateStruct = new MetadataUpdateStruct(
698
            array(
699
                'ownerId' => 14,
700
                'name' => 'Some name',
701
                'modificationDate' => time(),
702
                'alwaysAvailable' => true,
703
            )
704
        );
705
706
        $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...
707
            ->method('updateContent')
708
            ->with(14, $updateStruct);
709
710
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
711
            ->method('loadContentInfo')
712
            ->with(14)
713
            ->will(
714
                $this->returnValue(
715
                    $this->createMock(ContentInfo::class)
716
                )
717
            );
718
719
        $resultContentInfo = $handler->updateMetadata(
720
            14, // ContentId
721
            $updateStruct
722
        );
723
        self::assertInstanceOf(ContentInfo::class, $resultContentInfo);
724
    }
725
726
    /**
727
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata
728
     */
729
    public function testUpdateMetadataUpdatesPathIdentificationString()
730
    {
731
        $handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo'));
732
        $locationGatewayMock = $this->getLocationGatewayMock();
733
        $slugConverterMock = $this->getSlugConverterMock();
734
        $urlAliasGatewayMock = $this->getUrlAliasGatewayMock();
735
        $gatewayMock = $this->getGatewayMock();
736
        $updateStruct = new MetadataUpdateStruct(array('mainLanguageId' => 2));
737
738
        $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...
739
            ->method('updateContent')
740
            ->with(14, $updateStruct);
741
742
        $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...
743
            ->method('loadLocationDataByContent')
744
            ->with(14)
745
            ->will(
746
                $this->returnValue(
747
                    array(
748
                        array(
749
                            'node_id' => 100,
750
                            'parent_node_id' => 200,
751
                        ),
752
                    )
753
                )
754
            );
755
756
        $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...
757
            ->method('loadLocationEntries')
758
            ->with(100, false, 2)
759
            ->will(
760
                $this->returnValue(
761
                    array(
762
                        array(
763
                            'text' => 'slug',
764
                        ),
765
                    )
766
                )
767
            );
768
769
        $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...
770
            ->method('convert')
771
            ->with('slug', 'node_100', 'urlalias_compat')
772
            ->will($this->returnValue('transformed_slug'));
773
774
        $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...
775
            ->method('updatePathIdentificationString')
776
            ->with(100, 200, 'transformed_slug');
777
778
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
779
            ->method('loadContentInfo')
780
            ->with(14)
781
            ->will(
782
                $this->returnValue(
783
                    $this->createMock(ContentInfo::class)
784
                )
785
            );
786
787
        $handler->updateMetadata(
788
            14, // ContentId
789
            $updateStruct
790
        );
791
    }
792
793
    /**
794
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations
795
     */
796
    public function testLoadRelations()
797
    {
798
        $handler = $this->getContentHandler();
799
800
        $gatewayMock = $this->getGatewayMock();
801
        $mapperMock = $this->getMapperMock();
802
803
        $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...
804
            ->method('loadRelations')
805
            ->with(
806
                $this->equalTo(23),
807
                $this->equalTo(null),
808
                $this->equalTo(null)
809
            )->will(
810
                $this->returnValue(array(42))
811
            );
812
813
        $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...
814
            ->method('extractRelationsFromRows')
815
            ->with($this->equalTo(array(42)))
816
            ->will($this->returnValue($this->getRelationFixture()));
817
818
        $result = $handler->loadRelations(23);
819
820
        $this->assertEquals(
821
            $result,
822
            $this->getRelationFixture()
823
        );
824
    }
825
826
    /**
827
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations
828
     */
829
    public function testLoadReverseRelations()
830
    {
831
        $handler = $this->getContentHandler();
832
833
        $gatewayMock = $this->getGatewayMock();
834
        $mapperMock = $this->getMapperMock();
835
836
        $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...
837
            ->method('loadReverseRelations')
838
            ->with(
839
                $this->equalTo(23),
840
                $this->equalTo(null)
841
            )->will(
842
                $this->returnValue(array(42))
843
            );
844
845
        $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...
846
            ->method('extractRelationsFromRows')
847
            ->with($this->equalTo(array(42)))
848
            ->will($this->returnValue($this->getRelationFixture()));
849
850
        $result = $handler->loadReverseRelations(23);
851
852
        $this->assertEquals(
853
            $result,
854
            $this->getRelationFixture()
855
        );
856
    }
857
858
    public function testAddRelation()
859
    {
860
        // expected relation object after creation
861
        $expectedRelationObject = new Relation();
862
        $expectedRelationObject->id = 42; // mocked value, not a real one
863
        $expectedRelationObject->sourceContentId = 23;
864
        $expectedRelationObject->sourceContentVersionNo = 1;
865
        $expectedRelationObject->destinationContentId = 66;
866
        $expectedRelationObject->type = RelationValue::COMMON;
867
868
        // relation create struct
869
        $relationCreateStruct = new Relation\CreateStruct();
870
        $relationCreateStruct->destinationContentId = 66;
871
        $relationCreateStruct->sourceContentId = 23;
872
        $relationCreateStruct->sourceContentVersionNo = 1;
873
        $relationCreateStruct->type = RelationValue::COMMON;
874
875
        $handler = $this->getContentHandler();
876
877
        $gatewayMock = $this->getGatewayMock();
878
        $mapperMock = $this->getMapperMock();
879
880
        $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...
881
            ->method('createRelationFromCreateStruct')
882
            // @todo Connected with the todo above
883
            ->with($this->equalTo($relationCreateStruct))
884
            ->will($this->returnValue($expectedRelationObject));
885
886
        $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...
887
            ->method('insertRelation')
888
            ->with($this->equalTo($relationCreateStruct))
889
            ->will(
890
                // @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods
891
                $this->returnValue(42)
892
            );
893
894
        $result = $handler->addRelation($relationCreateStruct);
895
896
        $this->assertEquals(
897
            $result,
898
            $expectedRelationObject
899
        );
900
    }
901
902
    /**
903
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation
904
     */
905
    public function testRemoveRelation()
906
    {
907
        $gatewayMock = $this->getGatewayMock();
908
909
        $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...
910
            ->method('deleteRelation')
911
            ->with($this->equalTo(1, RelationValue::COMMON));
912
913
        $this->getContentHandler()->removeRelation(1, RelationValue::COMMON);
914
    }
915
916
    protected function getRelationFixture()
917
    {
918
        $relation = new Relation();
919
        $relation->sourceContentId = 23;
920
        $relation->sourceContentVersionNo = 1;
921
        $relation->destinationContentId = 69;
922
923
        return $relation;
924
    }
925
926
    /**
927
     * Returns a CreateStruct fixture.
928
     *
929
     * @return \eZ\Publish\SPI\Persistence\Content\CreateStruct
930
     */
931
    public function getCreateStructFixture()
932
    {
933
        $struct = new CreateStruct();
934
935
        $struct->typeId = 4242;
936
937
        $firstField = new Field();
938
        $firstField->type = 'some-type';
939
        $firstField->value = new FieldValue();
940
941
        $secondField = clone $firstField;
942
943
        $struct->fields = array(
944
            $firstField, $secondField,
945
        );
946
947
        $struct->locations = array(
948
            new LocationCreateStruct(
949
                array('parentId' => 42)
950
            ),
951
        );
952
953
        $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...
954
            'eng-GB' => 'This is a test name',
955
        );
956
957
        return $struct;
958
    }
959
960
    /**
961
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser
962
     */
963
    public function testLoadDraftsForUser()
964
    {
965
        $handler = $this->getContentHandler();
966
        $rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2));
967
968
        $gatewayMock = $this->getGatewayMock();
969
        $mapperMock = $this->getMapperMock();
970
971
        $gatewayMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Gateway>.

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

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

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

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

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

Loading history...
1039
            ->method('getAllLocationIds')
1040
            ->with($this->equalTo(23))
1041
            ->will($this->returnValue(array(42, 24)));
1042
        $treeHandlerMock->expects($this->exactly(2))
1043
            ->method('removeSubtree')
1044
            ->with(
1045
                $this->logicalOr(
1046
                    $this->equalTo(42),
1047
                    $this->equalTo(24)
1048
                )
1049
            );
1050
1051
        $handlerMock->deleteContent(23);
1052
    }
1053
1054
    /**
1055
     * Test for the deleteContent() method.
1056
     *
1057
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent
1058
     */
1059
    public function testDeleteContentWithoutLocations()
1060
    {
1061
        $handlerMock = $this->getPartlyMockedHandler(array('removeRawContent'));
1062
        $gatewayMock = $this->getGatewayMock();
1063
1064
        $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...
1065
            ->method('getAllLocationIds')
1066
            ->with($this->equalTo(23))
1067
            ->will($this->returnValue(array()));
1068
        $handlerMock->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
1069
            ->method('removeRawContent')
1070
            ->with($this->equalTo(23));
1071
1072
        $handlerMock->deleteContent(23);
1073
    }
1074
1075
    /**
1076
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion
1077
     */
1078
    public function testDeleteVersion()
1079
    {
1080
        $handler = $this->getContentHandler();
1081
1082
        $gatewayMock = $this->getGatewayMock();
1083
        $mapperMock = $this->getMapperMock();
1084
        $locationHandlerMock = $this->getLocationGatewayMock();
1085
        $fieldHandlerMock = $this->getFieldHandlerMock();
1086
1087
        // Load VersionInfo to delete fields
1088
        $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...
1089
            ->method('loadVersionInfo')
1090
            ->with($this->equalTo(225), $this->equalTo(2))
1091
            ->will($this->returnValue(array(42)));
1092
1093
        $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...
1094
            ->method('loadVersionedNameData')
1095
            ->with($this->equalTo(array(array('id' => 225, 'version' => 2))))
1096
            ->will($this->returnValue(array(22)));
1097
1098
        $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...
1099
            ->method('extractVersionInfoListFromRows')
1100
            ->with($this->equalTo(array(42)), $this->equalTo(array(22)))
1101
            ->will($this->returnValue(array(new VersionInfo())));
1102
1103
        $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...
1104
            ->method('deleteNodeAssignment')
1105
            ->with(
1106
                $this->equalTo(225),
1107
                $this->equalTo(2)
1108
            );
1109
1110
        $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...
1111
            ->method('deleteFields')
1112
            ->with(
1113
                $this->equalTo(225),
1114
                $this->isInstanceOf(VersionInfo::class)
1115
            );
1116
        $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...
1117
            ->method('deleteRelations')
1118
            ->with(
1119
                $this->equalTo(225),
1120
                $this->equalTo(2)
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('deleteVersions')
1124
            ->with(
1125
                $this->equalTo(225),
1126
                $this->equalTo(2)
1127
            );
1128
        $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...
1129
            ->method('deleteNames')
1130
            ->with(
1131
                $this->equalTo(225),
1132
                $this->equalTo(2)
1133
            );
1134
1135
        $handler->deleteVersion(225, 2);
1136
    }
1137
1138
    /**
1139
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1140
     */
1141
    public function testCopySingleVersion()
1142
    {
1143
        $handler = $this->getPartlyMockedHandler(array('load', 'internalCreate'));
1144
        $gatewayMock = $this->getGatewayMock();
1145
        $mapperMock = $this->getMapperMock();
1146
1147
        $handler->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
1148
            $this->once()
1149
        )->method(
1150
            'load'
1151
        )->with(
1152
            $this->equalTo(23),
1153
            $this->equalTo(32)
1154
        )->will(
1155
            $this->returnValue(new Content())
1156
        );
1157
1158
        $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...
1159
            $this->once()
1160
        )->method(
1161
            'createCreateStructFromContent'
1162
        )->with(
1163
            $this->isInstanceOf(Content::class)
1164
        )->will(
1165
            $this->returnValue(new CreateStruct())
1166
        );
1167
1168
        $handler->expects(
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
1169
            $this->once()
1170
        )->method(
1171
            'internalCreate'
1172
        )->with(
1173
            $this->isInstanceOf(CreateStruct::class),
1174
            $this->equalTo(32)
1175
        )->will(
1176
            $this->returnValue(
1177
                new Content(
1178
                    [
1179
                        'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]),
1180
                    ]
1181
                )
1182
            )
1183
        );
1184
1185
        $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...
1186
            ->method('copyRelations')
1187
            ->with(
1188
                $this->equalTo(23),
1189
                $this->equalTo(24),
1190
                $this->equalTo(32)
1191
            )
1192
            ->will($this->returnValue(null));
1193
1194
        $result = $handler->copy(23, 32);
1195
1196
        $this->assertInstanceOf(
1197
            Content::class,
1198
            $result
1199
        );
1200
    }
1201
1202
    /**
1203
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1204
     */
1205
    public function testCopyAllVersions()
1206
    {
1207
        $handler = $this->getPartlyMockedHandler(
1208
            array(
1209
                'loadContentInfo',
1210
                'load',
1211
                'internalCreate',
1212
                'listVersions',
1213
            )
1214
        );
1215
        $gatewayMock = $this->getGatewayMock();
1216
        $mapperMock = $this->getMapperMock();
1217
        $fieldHandlerMock = $this->getFieldHandlerMock();
1218
        $contentTypeHandlerMock = $this->getContentTypeHandlerMock();
1219
        $contentTypeMock = $this->createMock(Type::class);
1220
        $time = time();
1221
        $createStructStub = new CreateStruct(
1222
            array(
1223
                'modified' => $time,
1224
                'typeId' => 4242,
1225
            )
1226
        );
1227
1228
        $contentTypeHandlerMock->expects($this->once())
1229
            ->method('load')
1230
            ->with($createStructStub->typeId)
1231
            ->will($this->returnValue($contentTypeMock));
1232
1233
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

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

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

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

Loading history...
1239
            ->method('load')
1240
            ->with($this->equalTo(23), $this->equalTo(2))
1241
            ->will($this->returnValue(new Content()));
1242
1243
        $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...
1244
            ->method('createCreateStructFromContent')
1245
            ->with($this->isInstanceOf(Content::class))
1246
            ->will(
1247
                $this->returnValue($createStructStub)
1248
            );
1249
1250
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

Loading history...
1251
            ->method('internalCreate')
1252
            ->with(
1253
                $this->isInstanceOf(CreateStruct::class),
1254
                $this->equalTo(2)
1255
            )->will(
1256
                $this->returnValue(
1257
                    new Content(
1258
                        array(
1259
                            'versionInfo' => new VersionInfo(
1260
                                array(
1261
                                    'contentInfo' => new ContentInfo(array('id' => 24)),
1262
                                )
1263
                            ),
1264
                        )
1265
                    )
1266
                )
1267
            );
1268
1269
        $handler->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...Legacy\Content\Handler>.

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

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

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

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

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

Loading history...
1293
            ->method('load')
1294
            ->with($this->equalTo(23), $this->equalTo(1))
1295
            ->will(
1296
                $this->returnValue(
1297
                    new Content(
1298
                        array(
1299
                            'versionInfo' => $versionInfo,
1300
                            'fields' => array(),
1301
                        )
1302
                    )
1303
                )
1304
            );
1305
1306
        $versionInfo->creationDate = $time;
1307
        $versionInfo->modificationDate = $time;
1308
        $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...
1309
            ->method('insertVersion')
1310
            ->with(
1311
                $this->equalTo($versionInfo),
1312
                $this->isType('array')
1313
            )->will($this->returnValue(42));
1314
1315
        $versionInfo = clone $versionInfo;
1316
        $versionInfo->id = 42;
1317
        $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...
1318
            ->method('createNewFields')
1319
            ->with(
1320
                $this->equalTo(
1321
                    new Content(
1322
                        array(
1323
                            'versionInfo' => $versionInfo,
1324
                            'fields' => array(),
1325
                        )
1326
                    )
1327
                ),
1328
                $this->isInstanceOf(Type::class)
1329
            );
1330
1331
        $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...
1332
            ->method('setName')
1333
            ->with(
1334
                $this->equalTo(24),
1335
                $this->equalTo(1),
1336
                $this->equalTo('Test'),
1337
                $this->equalTo('eng-US')
1338
            );
1339
1340
        $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...
1341
            ->method('copyRelations')
1342
            ->with(
1343
                $this->equalTo(23),
1344
                $this->equalTo(24),
1345
                $this->equalTo(null)
1346
            )
1347
            ->will($this->returnValue(null));
1348
1349
        $result = $handler->copy(23);
1350
1351
        $this->assertInstanceOf(
1352
            Content::class,
1353
            $result
1354
        );
1355
    }
1356
1357
    /**
1358
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1359
     */
1360
    public function testCopyThrowsNotFoundExceptionContentNotFound()
1361
    {
1362
        $handler = $this->getContentHandler();
1363
1364
        $treeHandlerMock = $this->getTreeHandlerMock();
1365
        $treeHandlerMock
1366
            ->expects($this->once())
1367
            ->method('loadContentInfo')
1368
            ->with($this->equalTo(23))
1369
            ->will(
1370
                $this->throwException(new NotFoundException('ContentInfo', 23))
1371
            );
1372
1373
        $handler->copy(23);
1374
    }
1375
1376
    /**
1377
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy
1378
     * @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException
1379
     */
1380 View Code Duplication
    public function testCopyThrowsNotFoundExceptionVersionNotFound()
1381
    {
1382
        $handler = $this->getContentHandler();
1383
1384
        $gatewayMock = $this->getGatewayMock();
1385
        $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...
1386
            ->method('load')
1387
            ->with($this->equalTo(23, 32))
1388
            ->will($this->returnValue(array()));
1389
1390
        $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...
1391
    }
1392
1393
    /**
1394
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus
1395
     */
1396 View Code Duplication
    public function testSetStatus()
1397
    {
1398
        $handler = $this->getContentHandler();
1399
1400
        $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...
1401
        $gatewayMock = $this->getGatewayMock();
1402
1403
        $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...
1404
            ->method('setStatus')
1405
            ->with(23, 5, 2)
1406
            ->will($this->returnValue(true));
1407
1408
        $this->assertTrue(
1409
            $handler->setStatus(23, 2, 5)
1410
        );
1411
    }
1412
1413
    /**
1414
     * Returns the handler to test.
1415
     *
1416
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1417
     */
1418
    protected function getContentHandler()
1419
    {
1420
        if (!isset($this->contentHandler)) {
1421
            $this->contentHandler = new Handler(
1422
                $this->getGatewayMock(),
1423
                $this->getLocationGatewayMock(),
1424
                $this->getMapperMock(),
1425
                $this->getFieldHandlerMock(),
1426
                $this->getSlugConverterMock(),
1427
                $this->getUrlAliasGatewayMock(),
1428
                $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...
1429
                $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...
1430
            );
1431
        }
1432
1433
        return $this->contentHandler;
1434
    }
1435
1436
    /**
1437
     * Returns the handler to test with $methods mocked.
1438
     *
1439
     * @param string[] $methods
1440
     *
1441
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler
1442
     */
1443
    protected function getPartlyMockedHandler(array $methods)
1444
    {
1445
        return $this->getMockBuilder(Handler::class)
1446
            ->setMethods($methods)
1447
            ->setConstructorArgs(
1448
                array(
1449
                    $this->getGatewayMock(),
1450
                    $this->getLocationGatewayMock(),
1451
                    $this->getMapperMock(),
1452
                    $this->getFieldHandlerMock(),
1453
                    $this->getSlugConverterMock(),
1454
                    $this->getUrlAliasGatewayMock(),
1455
                    $this->getContentTypeHandlerMock(),
1456
                    $this->getTreeHandlerMock(),
1457
                )
1458
            )
1459
            ->getMock();
1460
    }
1461
1462
    /**
1463
     * Returns a TreeHandler mock.
1464
     *
1465
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
1466
     */
1467
    protected function getTreeHandlerMock()
1468
    {
1469
        if (!isset($this->treeHandlerMock)) {
1470
            $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...
1471
        }
1472
1473
        return $this->treeHandlerMock;
1474
    }
1475
1476
    /**
1477
     * Returns a ContentTypeHandler mock.
1478
     *
1479
     * @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler
1480
     */
1481
    protected function getContentTypeHandlerMock()
1482
    {
1483
        if (!isset($this->contentTypeHandlerMock)) {
1484
            $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...
1485
        }
1486
1487
        return $this->contentTypeHandlerMock;
1488
    }
1489
1490
    /**
1491
     * Returns a FieldHandler mock.
1492
     *
1493
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
1494
     */
1495
    protected function getFieldHandlerMock()
1496
    {
1497
        if (!isset($this->fieldHandlerMock)) {
1498
            $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...
1499
        }
1500
1501
        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 1501 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...
1502
    }
1503
1504
    /**
1505
     * Returns a Mapper mock.
1506
     *
1507
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper
1508
     */
1509
    protected function getMapperMock()
1510
    {
1511
        if (!isset($this->mapperMock)) {
1512
            $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...
1513
        }
1514
1515
        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 1515 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...
1516
    }
1517
1518
    /**
1519
     * Returns a Location Gateway mock.
1520
     *
1521
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
1522
     */
1523
    protected function getLocationGatewayMock()
1524
    {
1525
        if (!isset($this->locationGatewayMock)) {
1526
            $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...
1527
        }
1528
1529
        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 1529 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...
1530
    }
1531
1532
    /**
1533
     * Returns a Content Type gateway mock.
1534
     *
1535
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway
1536
     */
1537
    protected function getTypeGatewayMock()
1538
    {
1539
        if (!isset($this->typeGatewayMock)) {
1540
            $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...
1541
        }
1542
1543
        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 1543 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...
1544
    }
1545
1546
    /**
1547
     * Returns a mock object for the Content Gateway.
1548
     *
1549
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway
1550
     */
1551
    protected function getGatewayMock()
1552
    {
1553
        if (!isset($this->gatewayMock)) {
1554
            $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...
1555
        }
1556
1557
        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 1557 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...
1558
    }
1559
1560
    /**
1561
     * Returns a mock object for the UrlAlias Handler.
1562
     *
1563
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter
1564
     */
1565
    protected function getSlugConverterMock()
1566
    {
1567
        if (!isset($this->slugConverterMock)) {
1568
            $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...
1569
        }
1570
1571
        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 1571 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...
1572
    }
1573
1574
    /**
1575
     * Returns a mock object for the UrlAlias Gateway.
1576
     *
1577
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
1578
     */
1579
    protected function getUrlAliasGatewayMock()
1580
    {
1581
        if (!isset($this->urlAliasGatewayMock)) {
1582
            $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...
1583
        }
1584
1585
        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 1585 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...
1586
    }
1587
}
1588