Completed
Push — EZP-30006 ( ccc002...bed72d )
by André
20:27
created

testDeleteTrashItemNoMoreLocations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 58

Duplication

Lines 58
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 58
loc 58
rs 8.9163
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\API\Repository\Values\Content\Trash\TrashItemDeleteResult;
12
use eZ\Publish\API\Repository\Values\Content\Trash\TrashItemDeleteResultList;
13
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase;
14
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler;
15
use eZ\Publish\SPI\Persistence\Content\Location\Trashed;
16
use eZ\Publish\Core\Persistence\Legacy\Content as CoreContent;
17
18
/**
19
 * Test case for TrashHandlerTest.
20
 */
21
class TrashHandlerTest extends TestCase
22
{
23
    /**
24
     * Mocked location handler instance.
25
     *
26
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler
27
     */
28
    protected $locationHandler;
29
30
    /**
31
     * Mocked location gateway instance.
32
     *
33
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
34
     */
35
    protected $locationGateway;
36
37
    /**
38
     * Mocked location mapper instance.
39
     *
40
     * @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
41
     */
42
    protected $locationMapper;
43
44
    /**
45
     * Mocked content handler instance.
46
     *
47
     * @var \PHPUnit\Framework\MockObject\MockObject
48
     */
49
    protected $contentHandler;
50
51 View Code Duplication
    protected function getTrashHandler()
52
    {
53
        $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...
54
55
        return new Handler(
56
            $this->locationHandler = $this->createMock(CoreContent\Location\Handler::class),
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...ocation\Handler::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ntent\Location\Handler> of property $locationHandler.

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...
57
            $this->locationGateway = $this->createMock(CoreContent\Location\Gateway::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 $locationGateway.

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...
58
            $this->locationMapper = $this->createMock(CoreContent\Location\Mapper::class),
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...Location\Mapper::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\Core\P...ontent\Location\Mapper> of property $locationMapper.

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...
59
            $this->contentHandler = $this->createMock(CoreContent\Handler::class)
60
        );
61
    }
62
63
    /**
64
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
65
     */
66
    public function testTrashSubtree()
67
    {
68
        $handler = $this->getTrashHandler();
69
70
        $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...
71
            ->expects($this->at(0))
72
            ->method('getSubtreeContent')
73
            ->with(20)
74
            ->will(
75
                $this->returnValue(
76
                    array(
77
                        array(
78
                            'contentobject_id' => 10,
79
                            'node_id' => 20,
80
                            'main_node_id' => 30,
81
                            'parent_node_id' => 40,
82
                        ),
83
                        array(
84
                            'contentobject_id' => 11,
85
                            'node_id' => 21,
86
                            'main_node_id' => 31,
87
                            'parent_node_id' => 41,
88
                        ),
89
                    )
90
                )
91
            );
92
93
        $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...
94
            ->expects($this->at(1))
95
            ->method('countLocationsByContentId')
96
            ->with(10)
97
            ->will($this->returnValue(1));
98
99
        $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...
100
            ->expects($this->at(2))
101
            ->method('trashLocation')
102
            ->with(20);
103
104
        $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...
105
            ->expects($this->at(3))
106
            ->method('countLocationsByContentId')
107
            ->with(11)
108
            ->will($this->returnValue(2));
109
110
        $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...
111
            ->expects($this->at(4))
112
            ->method('removeLocation')
113
            ->with(21);
114
115
        $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...
116
            ->expects($this->once())
117
            ->method('markSubtreeModified')
118
            ->with(40);
119
120
        $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...
121
            ->expects($this->at(5))
122
            ->method('loadTrashByLocation')
123
            ->with(20)
124
            ->will($this->returnValue($array = array('data…')));
125
126
        $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...
127
            ->expects($this->once())
128
            ->method('createLocationFromRow')
129
            ->with($array, null, new Trashed())
130
            ->will($this->returnValue(new Trashed(array('id' => 20))));
131
132
        $trashedObject = $handler->trashSubtree(20);
133
        self::assertInstanceOf(Trashed::class, $trashedObject);
134
        self::assertSame(20, $trashedObject->id);
135
    }
136
137
    /**
138
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
139
     */
140
    public function testTrashSubtreeReturnsNull()
141
    {
142
        $handler = $this->getTrashHandler();
143
144
        $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...
145
            ->expects($this->at(0))
146
            ->method('getSubtreeContent')
147
            ->with(20)
148
            ->will(
149
                $this->returnValue(
150
                    array(
151
                        array(
152
                            'contentobject_id' => 10,
153
                            'node_id' => 20,
154
                            'main_node_id' => 30,
155
                            'parent_node_id' => 40,
156
                        ),
157
                        array(
158
                            'contentobject_id' => 11,
159
                            'node_id' => 21,
160
                            'main_node_id' => 31,
161
                            'parent_node_id' => 41,
162
                        ),
163
                    )
164
                )
165
            );
166
167
        $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...
168
            ->expects($this->at(1))
169
            ->method('countLocationsByContentId')
170
            ->with(10)
171
            ->will($this->returnValue(2));
172
173
        $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...
174
            ->expects($this->at(2))
175
            ->method('removeLocation')
176
            ->with(20);
177
178
        $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...
179
            ->expects($this->at(3))
180
            ->method('countLocationsByContentId')
181
            ->with(11)
182
            ->will($this->returnValue(1));
183
184
        $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...
185
            ->expects($this->at(4))
186
            ->method('trashLocation')
187
            ->with(21);
188
189
        $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...
190
            ->expects($this->once())
191
            ->method('markSubtreeModified')
192
            ->with(40);
193
194
        $returnValue = $handler->trashSubtree(20);
195
        self::assertNull($returnValue);
196
    }
197
198
    /**
199
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree
200
     */
201
    public function testTrashSubtreeUpdatesMainLocation()
202
    {
203
        $handler = $this->getTrashHandler();
204
205
        $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...
206
            ->expects($this->at(0))
207
            ->method('getSubtreeContent')
208
            ->with(20)
209
            ->will(
210
                $this->returnValue(
211
                    array(
212
                        array(
213
                            'contentobject_id' => 10,
214
                            'node_id' => 20,
215
                            'main_node_id' => 30,
216
                            'parent_node_id' => 40,
217
                        ),
218
                        array(
219
                            'contentobject_id' => 11,
220
                            'node_id' => 21,
221
                            'main_node_id' => 21,
222
                            'parent_node_id' => 41,
223
                        ),
224
                    )
225
                )
226
            );
227
228
        $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...
229
            ->expects($this->at(1))
230
            ->method('countLocationsByContentId')
231
            ->with(10)
232
            ->will($this->returnValue(1));
233
234
        $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...
235
            ->expects($this->at(2))
236
            ->method('trashLocation')
237
            ->with(20);
238
239
        $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...
240
            ->expects($this->at(3))
241
            ->method('countLocationsByContentId')
242
            ->with(11)
243
            ->will($this->returnValue(2));
244
245
        $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...
246
            ->expects($this->at(4))
247
            ->method('removeLocation')
248
            ->with(21);
249
250
        $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...
251
            ->expects($this->at(5))
252
            ->method('getFallbackMainNodeData')
253
            ->with(11, 21)
254
            ->will(
255
                $this->returnValue(
256
                    array(
257
                        'node_id' => 100,
258
                        'contentobject_version' => 101,
259
                        'parent_node_id' => 102,
260
                    )
261
                )
262
            );
263
264
        $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...
265
            ->expects($this->once())
266
            ->method('changeMainLocation')
267
            ->with(11, 100, 101, 102);
268
269
        $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...
270
            ->expects($this->once())
271
            ->method('markSubtreeModified')
272
            ->with(40);
273
274
        $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...
275
            ->expects($this->at(6))
276
            ->method('loadTrashByLocation')
277
            ->with(20)
278
            ->will($this->returnValue($array = array('data…')));
279
280
        $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...
281
            ->expects($this->once())
282
            ->method('createLocationFromRow')
283
            ->with($array, null, new Trashed())
284
            ->will($this->returnValue(new Trashed(array('id' => 20))));
285
286
        $trashedObject = $handler->trashSubtree(20);
287
        self::assertInstanceOf(Trashed::class, $trashedObject);
288
        self::assertSame(20, $trashedObject->id);
289
    }
290
291
    /**
292
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::recover
293
     */
294
    public function testRecover()
295
    {
296
        $handler = $this->getTrashHandler();
297
298
        $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...
299
            ->expects($this->at(0))
300
            ->method('untrashLocation')
301
            ->with(69, 23)
302
            ->will(
303
                $this->returnValue(
304
                    new Trashed(array('id' => 70))
305
                )
306
            );
307
308
        self::assertSame(70, $handler->recover(69, 23));
309
    }
310
311
    /**
312
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::loadTrashItem
313
     */
314
    public function testLoadTrashItem()
315
    {
316
        $handler = $this->getTrashHandler();
317
318
        $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...
319
            ->expects($this->at(0))
320
            ->method('loadTrashByLocation')
321
            ->with(69)
322
            ->will($this->returnValue($array = array('data…')));
323
324
        $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...
325
            ->expects($this->at(0))
326
            ->method('createLocationFromRow')
327
            ->with($array, null, new Trashed());
328
329
        $handler->loadTrashItem(69);
330
    }
331
332
    /**
333
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::emptyTrash
334
     */
335
    public function testEmptyTrash()
336
    {
337
        $handler = $this->getTrashHandler();
338
339
        $expectedTrashed = array(
340
            array(
341
                'node_id' => 69,
342
                'path_string' => '/1/2/69/',
343
                'contentobject_id' => 67,
344
            ),
345
            array(
346
                'node_id' => 70,
347
                'path_string' => '/1/2/70/',
348
                'contentobject_id' => 68,
349
            ),
350
        );
351
352
        // Index for locationGateway calls
353
        $i = 0;
354
        // Index for contentHandler calls
355
        $iContent = 0;
356
        // Index for locationMapper calls
357
        $iLocation = 0;
358
        $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...
359
            ->expects($this->at($i++))
360
            ->method('listTrashed')
361
            ->will(
362
                $this->returnValue($expectedTrashed)
363
            );
364
365
        $trashedItemIds = [];
366
        $trashedContentIds = [];
367
368
        foreach ($expectedTrashed as $trashedElement) {
369
            $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...
370
                ->expects($this->at($iLocation++))
371
                ->method('createLocationFromRow')
372
                ->will(
373
                    $this->returnValue(
374
                        new Trashed(
375
                            array(
376
                                'id' => $trashedElement['node_id'],
377
                                'contentId' => $trashedElement['contentobject_id'],
378
                                'pathString' => $trashedElement['path_string'],
379
                            )
380
                        )
381
                    )
382
                );
383
            $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...
384
                ->expects($this->at($i++))
385
                ->method('removeElementFromTrash')
386
                ->with($trashedElement['node_id']);
387
388
            $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...
389
                ->expects($this->at($i++))
390
                ->method('countLocationsByContentId')
391
                ->with($trashedElement['contentobject_id'])
392
                ->will($this->returnValue(0));
393
394
            $this->contentHandler
395
                ->expects($this->at($iContent++))
396
                ->method('deleteContent')
397
                ->with($trashedElement['contentobject_id']);
398
399
            $trashedItemIds[] = $trashedElement['node_id'];
400
            $trashedContentIds[] = $trashedElement['contentobject_id'];
401
        }
402
403
        $returnValue = $handler->emptyTrash();
404
405
        $this->assertInstanceOf(TrashItemDeleteResultList::class, $returnValue);
406
407
        foreach ($returnValue->items as $key => $trashItemDeleteResult) {
408
            $this->assertEquals($trashItemDeleteResult->trashItemId, $trashedItemIds[$key]);
409
            $this->assertEquals($trashItemDeleteResult->contentId, $trashedContentIds[$key]);
410
            $this->assertTrue($trashItemDeleteResult->contentRemoved);
411
        }
412
    }
413
414
    /**
415
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
416
     */
417 View Code Duplication
    public function testDeleteTrashItemNoMoreLocations()
418
    {
419
        $handler = $this->getTrashHandler();
420
421
        $trashItemId = 69;
422
        $contentId = 67;
423
        $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...
424
            ->expects($this->once())
425
            ->method('loadTrashByLocation')
426
            ->with($trashItemId)
427
            ->will(
428
                $this->returnValue(
429
                    array(
430
                        'node_id' => $trashItemId,
431
                        'contentobject_id' => $contentId,
432
                        'path_string' => '/1/2/69',
433
                    )
434
                )
435
            );
436
437
        $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...
438
            ->expects($this->once())
439
            ->method('createLocationFromRow')
440
            ->will(
441
                $this->returnValue(
442
                    new Trashed(
443
                        array(
444
                            'id' => $trashItemId,
445
                            'contentId' => $contentId,
446
                            'pathString' => '/1/2/69',
447
                        )
448
                    )
449
                )
450
            );
451
452
        $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...
453
            ->expects($this->once())
454
            ->method('removeElementFromTrash')
455
            ->with($trashItemId);
456
457
        $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...
458
            ->expects($this->once())
459
            ->method('countLocationsByContentId')
460
            ->with($contentId)
461
            ->will($this->returnValue(0));
462
463
        $this->contentHandler
464
            ->expects($this->once())
465
            ->method('deleteContent')
466
            ->with($contentId);
467
468
        $trashItemDeleteResult = $handler->deleteTrashItem($trashItemId);
469
470
        $this->assertInstanceOf(TrashItemDeleteResult::class, $trashItemDeleteResult);
471
        $this->assertEquals($trashItemId, $trashItemDeleteResult->trashItemId);
472
        $this->assertEquals($contentId, $trashItemDeleteResult->contentId);
473
        $this->assertTrue($trashItemDeleteResult->contentRemoved);
474
    }
475
476
    /**
477
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
478
     */
479 View Code Duplication
    public function testDeleteTrashItemStillHaveLocations()
480
    {
481
        $handler = $this->getTrashHandler();
482
483
        $trashItemId = 69;
484
        $contentId = 67;
485
        $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...
486
            ->expects($this->once())
487
            ->method('loadTrashByLocation')
488
            ->with($trashItemId)
489
            ->will(
490
                $this->returnValue(
491
                    array(
492
                        'node_id' => $trashItemId,
493
                        'contentobject_id' => $contentId,
494
                        'path_string' => '/1/2/69',
495
                    )
496
                )
497
            );
498
499
        $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...
500
            ->expects($this->once())
501
            ->method('createLocationFromRow')
502
            ->will(
503
                $this->returnValue(
504
                    new Trashed(
505
                        array(
506
                            'id' => $trashItemId,
507
                            'contentId' => $contentId,
508
                            'pathString' => '/1/2/69',
509
                        )
510
                    )
511
                )
512
            );
513
514
        $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...
515
            ->expects($this->once())
516
            ->method('removeElementFromTrash')
517
            ->with($trashItemId);
518
519
        $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...
520
            ->expects($this->once())
521
            ->method('countLocationsByContentId')
522
            ->with($contentId)
523
            ->will($this->returnValue(1));
524
525
        $this->contentHandler
526
            ->expects($this->never())
527
            ->method('deleteContent');
528
529
        $trashItemDeleteResult = $handler->deleteTrashItem($trashItemId);
530
531
        $this->assertInstanceOf(TrashItemDeleteResult::class, $trashItemDeleteResult);
532
        $this->assertEquals($trashItemId, $trashItemDeleteResult->trashItemId);
533
        $this->assertEquals($contentId, $trashItemDeleteResult->contentId);
534
        $this->assertFalse($trashItemDeleteResult->contentRemoved);
535
    }
536
}
537