[BUGFIX] Refactor record querying in deep nested structures in recycler
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Tests / Unit / Domain / Model / DeletedRecordsTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Recycler\Tests\Unit\Domain\Model;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Recycler\Domain\Model\DeletedRecords;
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class DeletedRecordsTest extends UnitTestCase
25 {
26 /**
27 * @test
28 */
29 public function recordsOfMultipleTablesAreSortedByPid()
30 {
31 $deletedRowsData = [
32 'pages' => [
33 ['uid' => 1, 'pid' => 1],
34 ['uid' => 2, 'pid' => 2],
35 ['uid' => 3, 'pid' => 4],
36 ['uid' => 4, 'pid' => 7],
37 ],
38 'sys_template' => [
39 ['uid' => 1, 'pid' => 9],
40 ['uid' => 2, 'pid' => 10],
41 ['uid' => 3, 'pid' => 1],
42 ],
43 'tt_content' => [
44 ['uid' => 1, 'pid' => 7],
45 ['uid' => 2, 'pid' => 1],
46 ]
47 ];
48
49 $expectedRows = [
50 'pages' => [
51 ['uid' => 1, 'pid' => 1],
52 ['uid' => 2, 'pid' => 2],
53 ['uid' => 4, 'pid' => 7],
54 ['uid' => 3, 'pid' => 4],
55 ],
56 'sys_template' => [
57 ['uid' => 3, 'pid' => 1],
58 ['uid' => 2, 'pid' => 10],
59 ['uid' => 1, 'pid' => 9],
60 ],
61 'tt_content' => [
62 ['uid' => 2, 'pid' => 1],
63 ['uid' => 1, 'pid' => 7],
64 ]
65 ];
66
67 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|DeletedRecords $subject */
68 $subject = $this->getAccessibleMock(DeletedRecords::class, ['dummy']);
69 $subject->_set('deletedRows', $deletedRowsData);
70 $subject->_call('sortDeletedRowsByPidList', [1, 2, 7, 4, 10, 9]);
71 static::assertEquals($expectedRows, $subject->getDeletedRows());
72 }
73 }