Completed
Push — ezp30878_cant_add_image_with_p... ( e19ea7...263f1b )
by
unknown
20:16
created

testTrashSubtreeUpdatesMainLocation()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 89
rs 8.24
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Trash\TrashHandlerTest 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\Location;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
12
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler;
13
use eZ\Publish\SPI\Persistence\Content\Location\Trashed;
14
15
/**
16
 * Test case for TrashHandlerTest.
17
 */
18
class TrashHandlerTest extends TestCase
19
{
20
    /**
21
     * Mocked location handler instance.
22
     *
23
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler
24
     */
25
    protected $locationHandler;
26
27
    /**
28
     * Mocked location gateway instance.
29
     *
30
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
31
     */
32
    protected $locationGateway;
33
34
    /**
35
     * Mocked location mapper instance.
36
     *
37
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
38
     */
39
    protected $locationMapper;
40
41
    /**
42
     * Mocked content handler instance.
43
     *
44
     * @var \PHPUnit_Framework_MockObject_MockObject
45
     */
46
    protected $contentHandler;
47
48
    protected function getTrashHandler()
49
    {
50
        $dbHandler = $this->getDatabaseHandler();
0 ignored issues
show
Unused Code introduced by
$dbHandler 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...
51
52
        return new Handler(
53
            $this->locationHandler = $this->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Handler')
54
                ->disableOriginalConstructor()
55
                ->getMock(),
56
            $this->locationGateway = $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway'),
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
57
            $this->locationMapper = $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Mapper'),
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

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

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

Loading history...
58
            $this->contentHandler = $this->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Handler')
59
                ->disableOriginalConstructor()
60
                ->getMock()
61
        );
62
    }
63
64
    /**
65
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
66
     */
67
    public function testTrashSubtree()
68
    {
69
        $handler = $this->getTrashHandler();
70
71
        $this->locationGateway
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...
72
            ->expects($this->at(0))
73
            ->method('getSubtreeContent')
74
            ->with(20)
75
            ->will(
76
                $this->returnValue(
77
                    [
78
                        [
79
                            'contentobject_id' => 10,
80
                            'node_id' => 20,
81
                            'main_node_id' => 30,
82
                            'parent_node_id' => 40,
83
                        ],
84
                        [
85
                            'contentobject_id' => 11,
86
                            'node_id' => 21,
87
                            'main_node_id' => 31,
88
                            'parent_node_id' => 41,
89
                        ],
90
                    ]
91
                )
92
            );
93
94
        $this->locationGateway
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...
95
            ->expects($this->at(1))
96
            ->method('countLocationsByContentId')
97
            ->with(10)
98
            ->will($this->returnValue(1));
99
100
        $this->locationGateway
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...
101
            ->expects($this->at(2))
102
            ->method('trashLocation')
103
            ->with(20);
104
105
        $this->locationGateway
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...
106
            ->expects($this->at(3))
107
            ->method('countLocationsByContentId')
108
            ->with(11)
109
            ->will($this->returnValue(2));
110
111
        $this->locationGateway
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...
112
            ->expects($this->at(4))
113
            ->method('removeLocation')
114
            ->with(21);
115
116
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\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...
117
            ->expects($this->once())
118
            ->method('markSubtreeModified')
119
            ->with(40);
120
121
        $this->locationGateway
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...
122
            ->expects($this->at(5))
123
            ->method('loadTrashByLocation')
124
            ->with(20)
125
            ->will($this->returnValue($array = ['data…']));
126
127
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
128
            ->expects($this->once())
129
            ->method('createLocationFromRow')
130
            ->with($array, null, new Trashed())
131
            ->will($this->returnValue(new Trashed(['id' => 20])));
132
133
        $trashedObject = $handler->trashSubtree(20);
134
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Trashed', $trashedObject);
135
        self::assertSame(20, $trashedObject->id);
136
    }
137
138
    /**
139
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
140
     */
141
    public function testTrashSubtreeReturnsNull()
142
    {
143
        $handler = $this->getTrashHandler();
144
145
        $this->locationGateway
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...
146
            ->expects($this->at(0))
147
            ->method('getSubtreeContent')
148
            ->with(20)
149
            ->will(
150
                $this->returnValue(
151
                    [
152
                        [
153
                            'contentobject_id' => 10,
154
                            'node_id' => 20,
155
                            'main_node_id' => 30,
156
                            'parent_node_id' => 40,
157
                        ],
158
                        [
159
                            'contentobject_id' => 11,
160
                            'node_id' => 21,
161
                            'main_node_id' => 31,
162
                            'parent_node_id' => 41,
163
                        ],
164
                    ]
165
                )
166
            );
167
168
        $this->locationGateway
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...
169
            ->expects($this->at(1))
170
            ->method('countLocationsByContentId')
171
            ->with(10)
172
            ->will($this->returnValue(2));
173
174
        $this->locationGateway
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...
175
            ->expects($this->at(2))
176
            ->method('removeLocation')
177
            ->with(20);
178
179
        $this->locationGateway
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...
180
            ->expects($this->at(3))
181
            ->method('countLocationsByContentId')
182
            ->with(11)
183
            ->will($this->returnValue(1));
184
185
        $this->locationGateway
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...
186
            ->expects($this->at(4))
187
            ->method('trashLocation')
188
            ->with(21);
189
190
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\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...
191
            ->expects($this->once())
192
            ->method('markSubtreeModified')
193
            ->with(40);
194
195
        $returnValue = $handler->trashSubtree(20);
196
        self::assertNull($returnValue);
197
    }
198
199
    /**
200
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
201
     */
202
    public function testTrashSubtreeUpdatesMainLocation()
203
    {
204
        $handler = $this->getTrashHandler();
205
206
        $this->locationGateway
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...
207
            ->expects($this->at(0))
208
            ->method('getSubtreeContent')
209
            ->with(20)
210
            ->will(
211
                $this->returnValue(
212
                    [
213
                        [
214
                            'contentobject_id' => 10,
215
                            'node_id' => 20,
216
                            'main_node_id' => 30,
217
                            'parent_node_id' => 40,
218
                        ],
219
                        [
220
                            'contentobject_id' => 11,
221
                            'node_id' => 21,
222
                            'main_node_id' => 21,
223
                            'parent_node_id' => 41,
224
                        ],
225
                    ]
226
                )
227
            );
228
229
        $this->locationGateway
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...
230
            ->expects($this->at(1))
231
            ->method('countLocationsByContentId')
232
            ->with(10)
233
            ->will($this->returnValue(1));
234
235
        $this->locationGateway
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...
236
            ->expects($this->at(2))
237
            ->method('trashLocation')
238
            ->with(20);
239
240
        $this->locationGateway
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...
241
            ->expects($this->at(3))
242
            ->method('countLocationsByContentId')
243
            ->with(11)
244
            ->will($this->returnValue(2));
245
246
        $this->locationGateway
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...
247
            ->expects($this->at(4))
248
            ->method('removeLocation')
249
            ->with(21);
250
251
        $this->locationGateway
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...
252
            ->expects($this->at(5))
253
            ->method('getFallbackMainNodeData')
254
            ->with(11, 21)
255
            ->will(
256
                $this->returnValue(
257
                    [
258
                        'node_id' => 100,
259
                        'contentobject_version' => 101,
260
                        'parent_node_id' => 102,
261
                    ]
262
                )
263
            );
264
265
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\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...
266
            ->expects($this->once())
267
            ->method('changeMainLocation')
268
            ->with(11, 100, 101, 102);
269
270
        $this->locationHandler
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ntent\Location\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...
271
            ->expects($this->once())
272
            ->method('markSubtreeModified')
273
            ->with(40);
274
275
        $this->locationGateway
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...
276
            ->expects($this->at(6))
277
            ->method('loadTrashByLocation')
278
            ->with(20)
279
            ->will($this->returnValue($array = ['data…']));
280
281
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
282
            ->expects($this->once())
283
            ->method('createLocationFromRow')
284
            ->with($array, null, new Trashed())
285
            ->will($this->returnValue(new Trashed(['id' => 20])));
286
287
        $trashedObject = $handler->trashSubtree(20);
288
        self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Trashed', $trashedObject);
289
        self::assertSame(20, $trashedObject->id);
290
    }
291
292
    /**
293
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::recover
294
     */
295
    public function testRecover()
296
    {
297
        $handler = $this->getTrashHandler();
298
299
        $this->locationGateway
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...
300
            ->expects($this->at(0))
301
            ->method('untrashLocation')
302
            ->with(69, 23)
303
            ->will(
304
                $this->returnValue(
305
                    new Trashed(['id' => 70])
306
                )
307
            );
308
309
        self::assertSame(70, $handler->recover(69, 23));
310
    }
311
312
    /**
313
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::loadTrashItem
314
     */
315
    public function testLoadTrashItem()
316
    {
317
        $handler = $this->getTrashHandler();
318
319
        $this->locationGateway
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...
320
            ->expects($this->at(0))
321
            ->method('loadTrashByLocation')
322
            ->with(69)
323
            ->will($this->returnValue($array = ['data…']));
324
325
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
326
            ->expects($this->at(0))
327
            ->method('createLocationFromRow')
328
            ->with($array, null, new Trashed());
329
330
        $handler->loadTrashItem(69);
331
    }
332
333
    /**
334
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::emptyTrash
335
     */
336
    public function testEmptyTrash()
337
    {
338
        $handler = $this->getTrashHandler();
339
340
        $expectedTrashed = [
341
            [
342
                'node_id' => 69,
343
                'path_string' => '/1/2/69/',
344
                'contentobject_id' => 67,
345
            ],
346
            [
347
                'node_id' => 70,
348
                'path_string' => '/1/2/70/',
349
                'contentobject_id' => 68,
350
            ],
351
        ];
352
353
        // Index for locationGateway calls
354
        $i = 0;
355
        // Index for contentHandler calls
356
        $iContent = 0;
357
        // Index for locationMapper calls
358
        $iLocation = 0;
359
        $this->locationGateway
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...
360
            ->expects($this->at($i++))
361
            ->method('listTrashed')
362
            ->will(
363
                $this->returnValue($expectedTrashed)
364
            );
365
366
        foreach ($expectedTrashed as $trashedElement) {
367
            $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
368
                ->expects($this->at($iLocation++))
369
                ->method('createLocationFromRow')
370
                ->will(
371
                    $this->returnValue(
372
                        new Trashed(
373
                            [
374
                                'id' => $trashedElement['node_id'],
375
                                'contentId' => $trashedElement['contentobject_id'],
376
                                'pathString' => $trashedElement['path_string'],
377
                            ]
378
                        )
379
                    )
380
                );
381
            $this->locationGateway
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...
382
                ->expects($this->at($i++))
383
                ->method('removeElementFromTrash')
384
                ->with($trashedElement['node_id']);
385
386
            $this->locationGateway
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...
387
                ->expects($this->at($i++))
388
                ->method('countLocationsByContentId')
389
                ->with($trashedElement['contentobject_id'])
390
                ->will($this->returnValue(0));
391
392
            $this->contentHandler
393
                ->expects($this->at($iContent++))
394
                ->method('deleteContent')
395
                ->with($trashedElement['contentobject_id']);
396
        }
397
398
        $handler->emptyTrash();
399
    }
400
401
    /**
402
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
403
     */
404 View Code Duplication
    public function testDeleteTrashItemNoMoreLocations()
405
    {
406
        $handler = $this->getTrashHandler();
407
408
        $this->locationGateway
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...
409
            ->expects($this->once())
410
            ->method('loadTrashByLocation')
411
            ->with(69)
412
            ->will(
413
                $this->returnValue(
414
                    [
415
                        'node_id' => 69,
416
                        'contentobject_id' => 67,
417
                        'path_string' => '/1/2/69',
418
                    ]
419
                )
420
            );
421
422
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\Mapper>.

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

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

Loading history...
423
            ->expects($this->once())
424
            ->method('createLocationFromRow')
425
            ->will(
426
                $this->returnValue(
427
                    new Trashed(
428
                        [
429
                            'id' => 69,
430
                            'contentId' => 67,
431
                            'pathString' => '/1/2/69',
432
                        ]
433
                    )
434
                )
435
            );
436
437
        $this->locationGateway
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...
438
            ->expects($this->once())
439
            ->method('removeElementFromTrash')
440
            ->with(69);
441
442
        $this->locationGateway
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...
443
            ->expects($this->once())
444
            ->method('countLocationsByContentId')
445
            ->with(67)
446
            ->will($this->returnValue(0));
447
448
        $this->contentHandler
449
            ->expects($this->once())
450
            ->method('deleteContent')
451
            ->with(67);
452
453
        $handler->deleteTrashItem(69);
454
    }
455
456
    /**
457
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
458
     */
459 View Code Duplication
    public function testDeleteTrashItemStillHaveLocations()
460
    {
461
        $handler = $this->getTrashHandler();
462
463
        $this->locationGateway
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...
464
            ->expects($this->once())
465
            ->method('loadTrashByLocation')
466
            ->with(69)
467
            ->will(
468
                $this->returnValue(
469
                    [
470
                        'node_id' => 69,
471
                        'contentobject_id' => 67,
472
                        'path_string' => '/1/2/69',
473
                    ]
474
                )
475
            );
476
477
        $this->locationMapper
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<eZ\Publish\Core\P...ontent\Location\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...
478
            ->expects($this->once())
479
            ->method('createLocationFromRow')
480
            ->will(
481
                $this->returnValue(
482
                    new Trashed(
483
                        [
484
                            'id' => 69,
485
                            'contentId' => 67,
486
                            'pathString' => '/1/2/69',
487
                        ]
488
                    )
489
                )
490
            );
491
492
        $this->locationGateway
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...
493
            ->expects($this->once())
494
            ->method('removeElementFromTrash')
495
            ->with(69);
496
497
        $this->locationGateway
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...
498
            ->expects($this->once())
499
            ->method('countLocationsByContentId')
500
            ->with(67)
501
            ->will($this->returnValue(1));
502
503
        $this->contentHandler
504
            ->expects($this->never())
505
            ->method('deleteContent');
506
507
        $handler->deleteTrashItem(69);
508
    }
509
}
510