‪TYPO3CMS  10.4
PageTreeRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 class ‪PageTreeRepositoryTest extends FunctionalTestCase
25 {
27 
28  public function ‪setUp(): void
29  {
30  parent::setUp();
31  $this->importCSVDataSet('typo3/sysext/backend/Tests/Functional/Tree/Repository/Fixtures/PageTree.csv');
32  $this->setUpBackendUserFromFixture(1);
33  }
34 
36  {
37  yield 'Single entry point with depth 2' => [
38  'pageTree' => [
39  'uid' => 0,
40  'title' => 'Core',
41  ],
42  'depth' => 2,
43  'entryPointIds' => [
44  2,
45  ],
46  'expected' => [
47  'uid' => 0,
48  'title' => 'Core',
49  '_children' => [
50  [
51  'uid' => 2,
52  'title' => 'Main Area',
53  '_children' => [
54  [
55  'uid' => 20,
56  'title' => 'Main Area Sub 1',
57  '_children' => [],
58  ],
59  [
60  'uid' => 21,
61  'title' => 'Main Area Sub 2',
62  '_children' => [
63  [
64  'uid' => 30,
65  'title' => 'Sub Area 1',
66  '_children' => [],
67  ],
68  [
69  'uid' => 31,
70  'title' => 'Sub Area 2',
71  '_children' => [],
72  ],
73  ],
74  ],
75  ],
76  ],
77  ],
78  ],
79  ];
80 
81  yield 'Single entry point with depth 1' => [
82  'pageTree' => [
83  'uid' => 0,
84  'title' => 'Core',
85  ],
86  'depth' => 1,
87  'entryPointIds' => [
88  2,
89  ],
90  'expected' => [
91  'uid' => 0,
92  'title' => 'Core',
93  '_children' => [
94  [
95  'uid' => 2,
96  'title' => 'Main Area',
97  '_children' => [
98  [
99  'uid' => 20,
100  'title' => 'Main Area Sub 1',
101  '_children' => [],
102  ],
103  [
104  'uid' => 21,
105  'title' => 'Main Area Sub 2',
106  '_children' => [],
107  ],
108  ],
109  ],
110  ],
111  ],
112  ];
113 
114  yield 'Two entry points parallel to each other' => [
115  'pageTree' => [
116  'uid' => 0,
117  'title' => 'Core',
118  ],
119  'depth' => 2,
120  'entryPointIds' => [
121  2,
122  3,
123  ],
124  'expected' => [
125  'uid' => 0,
126  'title' => 'Core',
127  '_children' => [
128  [
129  'uid' => 2,
130  'title' => 'Main Area',
131  '_children' => [
132  [
133  'uid' => 20,
134  'title' => 'Main Area Sub 1',
135  '_children' => [],
136  ],
137  [
138  'uid' => 21,
139  'title' => 'Main Area Sub 2',
140  '_children' => [
141  [
142  'uid' => 30,
143  'title' => 'Sub Area 1',
144  '_children' => [],
145  ],
146  [
147  'uid' => 31,
148  'title' => 'Sub Area 2',
149  '_children' => [],
150  ],
151  ],
152  ],
153  ],
154  ],
155  [
156  'uid' => 3,
157  'title' => 'Home 2',
158  '_children' => [],
159  ],
160  ],
161  ],
162  ];
163 
164  yield 'Two entry points intersecting each other' => [
165  'pageTree' => [
166  'uid' => 0,
167  'title' => 'Core',
168  ],
169  'depth' => 2,
170  'entryPointIds' => [
171  2,
172  21,
173  ],
174  'expected' => [
175  'uid' => 0,
176  'title' => 'Core',
177  '_children' => [
178  [
179  'uid' => 2,
180  'title' => 'Main Area',
181  '_children' => [
182  [
183  'uid' => 20,
184  'title' => 'Main Area Sub 1',
185  '_children' => [],
186  ],
187  [
188  'uid' => 21,
189  'title' => 'Main Area Sub 2',
190  '_children' => [
191  [
192  'uid' => 30,
193  'title' => 'Sub Area 1',
194  '_children' => [],
195  ],
196  [
197  'uid' => 31,
198  'title' => 'Sub Area 2',
199  '_children' => [],
200  ],
201  ],
202  ],
203  ],
204  ],
205  [
206  'uid' => 21,
207  'title' => 'Main Area Sub 2',
208  '_children' => [
209  [
210  'uid' => 30,
211  'title' => 'Sub Area 1',
212  '_children' => [],
213  ],
214  [
215  'uid' => 31,
216  'title' => 'Sub Area 2',
217  '_children' => [],
218  ],
219  ],
220  ],
221  ],
222  ],
223  ];
224  }
225 
230  public function ‪getTreeLevelsReturnsGroupedAndSortedPageTreeArray(array $pageTree, int $depth, array $entryPointIds, array $expected): void
231  {
232  $pageTreeRepository = new ‪PageTreeRepository();
233  $actual = $pageTreeRepository->getTreeLevels($pageTree, $depth, $entryPointIds);
234  $actual = $this->‪sortTreeArray([$actual]);
235  $keepProperties = array_flip(['uid', 'title', '_children']);
236  $actual = $this->‪normalizeTreeArray($actual, $keepProperties);
237  self::assertEquals($expected, $actual[0]);
238  }
239 }
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\Fixtures\Tree\NormalizeTreeTrait
Definition: NormalizeTreeTrait.php:21
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\PageTreeRepositoryTest\getTreeLevelsReturnsGroupedAndSortedPageTreeArrayDataProvider
‪getTreeLevelsReturnsGroupedAndSortedPageTreeArrayDataProvider()
Definition: PageTreeRepositoryTest.php:34
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\PageTreeRepositoryTest\setUp
‪setUp()
Definition: PageTreeRepositoryTest.php:27
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\PageTreeRepositoryTest
Definition: PageTreeRepositoryTest.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\Fixtures\Tree\NormalizeTreeTrait\normalizeTreeArray
‪array normalizeTreeArray(array $tree, array $keepProperties)
Definition: NormalizeTreeTrait.php:49
‪TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository
Definition: PageTreeRepository.php:41
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\Fixtures\Tree\NormalizeTreeTrait\sortTreeArray
‪sortTreeArray(array $tree)
Definition: NormalizeTreeTrait.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\PageTreeRepositoryTest\getTreeLevelsReturnsGroupedAndSortedPageTreeArray
‪getTreeLevelsReturnsGroupedAndSortedPageTreeArray(array $pageTree, int $depth, array $entryPointIds, array $expected)
Definition: PageTreeRepositoryTest.php:229