‪TYPO3CMS  11.5
TreeControllerTest.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 
28 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
29 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
30 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
31 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
32 
36 class ‪TreeControllerTest extends FunctionalTestCase
37 {
40 
41  protected const ‪LANGUAGE_PRESETS = [];
42 
43  protected ‪$coreExtensionsToLoad = ['workspaces'];
44 
48  private ‪$subject;
49 
54 
58  private ‪$context;
59 
65  protected ‪$backendUserFixture = 'EXT:core/Tests/Functional/Fixtures/be_users.xml';
66 
67  protected function ‪setUp(): void
68  {
69  parent::setUp();
70  //admin user for importing dataset
71  $this->backendUser = $this->setUpBackendUserFromFixture(1);
72  $this->‪setUpDatabase();
73 
74  //regular editor, non admin
75  $this->backendUser = $this->setUpBackendUser(9);
76  $this->context = GeneralUtility::makeInstance(Context::class);
77  $this->subject = $this->getAccessibleMock(TreeController::class, ['dummy']);
78  }
79 
80  protected function ‪tearDown(): void
81  {
82  unset($this->subject, $this->backendUser, $this->context);
83  parent::tearDown();
84  }
85 
86  protected function ‪setUpDatabase(): void
87  {
89  $scenarioFile = __DIR__ . '/Fixtures/PagesWithBEPermissions.yaml';
90  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
91  $writer = DataHandlerWriter::withBackendUser($this->backendUser);
92  $writer->invokeFactory($factory);
93  static::failIfArrayIsNotEmpty(
94  $writer->getErrors()
95  );
96  }
97 
101  public function ‪getAllEntryPointPageTrees(): void
102  {
103  $actual = $this->subject->_call('getAllEntryPointPageTrees');
104  $keepProperties = array_flip(['uid', 'title', '_children']);
105  $actual = $this->sortTreeArray($actual);
106  $actual = $this->normalizeTreeArray($actual, $keepProperties);
107 
108  $expected = [
109  [
110  'uid' => 0,
111  'title' => 'New TYPO3 site',
112  '_children' => [
113  [
114  'uid' => 1000,
115  'title' => 'ACME Inc',
116  '_children' => [
117  [
118  'uid' => 1100,
119  'title' => 'EN: Welcome',
120  '_children' => [
121  ],
122  ],
123  [
124  'uid' => 1200,
125  'title' => 'EN: Features',
126  '_children' => [
127  [
128  'uid' => 1210,
129  'title' => 'EN: Frontend Editing',
130  '_children' => [
131  ],
132  ],
133  [
134  'uid' => 1230,
135  'title' => 'EN: Managing content',
136  '_children' => [
137  ],
138  ],
139  ],
140  ],
141  [
142  'uid' => 1400,
143  'title' => 'EN: ACME in your Region',
144  '_children' => [
145  [
146  'uid' => 1410,
147  'title' => 'EN: Groups',
148  '_children' => [
149  ],
150  ],
151  ],
152  ],
153  [
154  'uid' => 1500,
155  'title' => 'Internal',
156  '_children' => [
157  [
158  'uid' => 1520,
159  'title' => 'Forecasts',
160  '_children' => [],
161  ],
162  [
163  'uid' => 1530,
164  'title' => 'Reports',
165  '_children' => [
166  ],
167  ],
168  ],
169  ],
170  [
171  'uid' => 1700,
172  'title' => 'Announcements & News',
173  '_children' => [
174  ],
175  ],
176  [
177  'uid' => 404,
178  'title' => 'Page not found',
179  '_children' => [
180  ],
181  ],
182  [
183  'uid' => 1930,
184  'title' => 'Our Blog',
185  '_children' => [
186  ],
187  ],
188  [
189  'uid' => 1990,
190  'title' => 'Storage',
191  '_children' => [
192  ],
193  ],
194  ],
195  ],
196  [
197  'uid' => 8110,
198  'title' => 'Europe',
199  '_children' => [
200  [
201  'uid' => 811000,
202  'title' => 'France',
203  '_children' => [],
204  ],
205  ],
206  ],
207  ],
208  ],
209  ];
210  self::assertEquals($expected, $actual);
211  }
212 
217  {
218  $this->backendUser->setWebMounts([0, 7000]);
219  $actual = $this->subject->_call('getAllEntryPointPageTrees');
220  $keepProperties = array_flip(['uid', 'title', '_children']);
221  $actual = $this->sortTreeArray($actual);
222  $actual = $this->normalizeTreeArray($actual, $keepProperties);
223 
224  $expected = [
225  [
226  'uid' => 0,
227  'title' => 'New TYPO3 site',
228  '_children' => [
229  [
230  'uid' => 1000,
231  'title' => 'ACME Inc',
232  '_children' => [
233  [
234  'uid' => 1100,
235  'title' => 'EN: Welcome',
236  '_children' => [
237  ],
238  ],
239  [
240  'uid' => 1200,
241  'title' => 'EN: Features',
242  '_children' => [
243  ],
244  ],
245  [
246  'uid' => 1400,
247  'title' => 'EN: ACME in your Region',
248  '_children' => [
249  ],
250  ],
251  [
252  'uid' => 1500,
253  'title' => 'Internal',
254  '_children' => [
255  ],
256  ],
257  [
258  'uid' => 1700,
259  'title' => 'Announcements & News',
260  '_children' => [
261  ],
262  ],
263  [
264  'uid' => 404,
265  'title' => 'Page not found',
266  '_children' => [
267  ],
268  ],
269  [
270  'uid' => 1930,
271  'title' => 'Our Blog',
272  '_children' => [
273  ],
274  ],
275  [
276  'uid' => 1990,
277  'title' => 'Storage',
278  '_children' => [
279  ],
280  ],
281  ],
282  ],
283  [
284  'uid' => 7000,
285  'title' => 'Common Collection',
286  '_children' => [
287  [
288  'uid' => 7100,
289  'title' => 'Announcements & News',
290  '_children' => [],
291  ],
292  ],
293  ],
294  ],
295  ],
296  [
297  'uid' => 7000,
298  'title' => 'Common Collection',
299  '_children' => [
300  [
301  'uid' => 7100,
302  'title' => 'Announcements & News',
303  '_children' => [
304  [
305  'uid' => 7110,
306  'title' => 'Markets',
307  '_children' => [],
308  ],
309  [
310  'uid' => 7120,
311  'title' => 'Products',
312  '_children' => [],
313  ],
314  [
315  'uid' => 7130,
316  'title' => 'Partners',
317  '_children' => [],
318  ],
319  ],
320  ],
321  ],
322  ],
323  ];
324  self::assertEquals($expected, $actual);
325  }
326 
330  public function ‪getAllEntryPointPageTreesWithSearch(): void
331  {
332  $actual = $this->subject->_call('getAllEntryPointPageTrees', 0, 'Groups');
333  $keepProperties = array_flip(['uid', 'title', '_children']);
334  $actual = $this->sortTreeArray($actual);
335  $actual = $this->normalizeTreeArray($actual, $keepProperties);
336 
337  $expected = [
338  [
339  'uid' => 0,
340  'title' => 'New TYPO3 site',
341  '_children' => [
342  [
343  'uid' => 1000,
344  'title' => 'ACME Inc',
345  '_children' => [
346  [
347  'uid' => 1400,
348  'title' => 'EN: ACME in your Region',
349  '_children' => [
350  [
351  'uid' => 1410,
352  'title' => 'EN: Groups',
353  '_children' => [
354  ],
355  ],
356  ],
357  ],
358  ],
359  ],
360  [
361  'uid' => 8110,
362  'title' => 'Europe',
363  '_children' => [
364  ],
365  ],
366  ],
367  ],
368  ];
369  self::assertEquals($expected, $actual);
370  }
371 
375  public function ‪getSubtreeForAccessiblePage(): void
376  {
377  $actual = $this->subject->_call('getAllEntryPointPageTrees', 1200);
378  $keepProperties = array_flip(['uid', 'title', '_children']);
379  $actual = $this->sortTreeArray($actual);
380  $actual = $this->normalizeTreeArray($actual, $keepProperties);
381 
382  $expected = [
383  [
384  'uid' => 1200,
385  'title' => 'EN: Features',
386  '_children' => [
387  [
388  'uid' => 1210,
389  'title' => 'EN: Frontend Editing',
390  '_children' => [
391  ],
392  ],
393  [
394  'uid' => 1230,
395  'title' => 'EN: Managing content',
396  '_children' => [
397  ],
398  ],
399  ],
400  ],
401  ];
402  self::assertEquals($expected, $actual);
403  }
404 
408  public function ‪getSubtreeForNonAccessiblePage(): void
409  {
410  $actual = $this->subject->_call('getAllEntryPointPageTrees', 1510);
411  $keepProperties = array_flip(['uid', 'title', '_children']);
412  $actual = $this->sortTreeArray($actual);
413  $actual = $this->normalizeTreeArray($actual, $keepProperties);
414 
415  $expected = [];
416  self::assertEquals($expected, $actual);
417  }
418 
422  public function ‪getSubtreeForPageOutsideMountPoint(): void
423  {
424  $actual = $this->subject->_call('getAllEntryPointPageTrees', 7000);
425  $keepProperties = array_flip(['uid', 'title', '_children']);
426  $actual = $this->sortTreeArray($actual);
427  $actual = $this->normalizeTreeArray($actual, $keepProperties);
428 
429  $expected = [];
430  self::assertEquals($expected, $actual);
431  }
432 
437  {
438  $this->backendUser->setWebmounts([1210, 1100]);
439  $actual = $this->subject->_call('getAllEntryPointPageTrees');
440  $keepProperties = array_flip(['uid', 'title', '_children']);
441  $actual = $this->sortTreeArray($actual);
442  $actual = $this->normalizeTreeArray($actual, $keepProperties);
443 
444  $expected = [
445  [
446  'uid' => 0,
447  'title' => 'New TYPO3 site',
448  '_children' => [
449  [
450  'uid' => 1210,
451  'title' => 'EN: Frontend Editing',
452  '_children' => [
453  ],
454  ],
455  [
456  'uid' => 1100,
457  'title' => 'EN: Welcome',
458  '_children' => [
459  ],
460  ],
461  ],
462  ],
463  ];
464  self::assertEquals($expected, $actual);
465  }
466 
470  public function ‪getAllEntryPointPageTreesInWorkspace(): void
471  {
472  $this->‪setWorkspace(1);
473  $actual = $this->subject->_call('getAllEntryPointPageTrees');
474  $keepProperties = array_flip(['uid', 'title', '_children']);
475  $actual = $this->sortTreeArray($actual);
476  $actual = $this->normalizeTreeArray($actual, $keepProperties);
477 
478  $expected = [
479  [
480  'uid' => 0,
481  'title' => 'New TYPO3 site',
482  '_children' => [
483  [
484  'uid' => 1000,
485  'title' => 'ACME Inc',
486  '_children' => [
487  [
488  'uid' => 1950,
489  'title' => 'EN: Goodbye',
490  '_children' => [
491  [
492  'uid' => 10015,
493  'title' => 'EN: Really Goodbye',
494  '_children' => [
495  ],
496  ],
497  ],
498  ],
499  [
500  'uid' => 1100,
501  'title' => 'EN: Welcome',
502  '_children' => [
503  ],
504  ],
505  [
506  'uid' => 1200,
507  'title' => 'EN: Features modified',
508  '_children' => [
509  [
510  'uid' => 1240,
511  'title' => 'EN: Managing data',
512  '_children' => [],
513  ],
514  [
515  'uid' => 1230,
516  'title' => 'EN: Managing content',
517  '_children' => [
518  ],
519  ],
520  ],
521  ],
522  [
523  'uid' => 1500,
524  'title' => 'Internal',
525  '_children' => [
526  [
527  'uid' => 1520,
528  'title' => 'Forecasts',
529  '_children' => [],
530  ],
531  [
532  'uid' => 1530,
533  'title' => 'Reports',
534  '_children' => [
535  ],
536  ],
537  ],
538  ],
539  [
540  'uid' => 1700,
541  'title' => 'Announcements & News',
542  '_children' => [
543  [
544  // page moved in workspace 1
545  // from pid 8110 to pid 1700 (visible now)
546  'uid' => 811000,
547  'title' => 'France',
548  '_children' => [],
549  ],
550  [
551  // page with sub-pages moved in workspace 1
552  // from pid 1510 (missing permissions) to pid 1700 (visible now)
553  'uid' => 1511,
554  'title' => 'Products',
555  '_children' => [],
556  ],
557  ],
558  ],
559  [
560  'uid' => 404,
561  'title' => 'Page not found',
562  '_children' => [
563  ],
564  ],
565  [
566  'uid' => 1930,
567  'title' => 'Our Blog',
568  '_children' => [
569  ],
570  ],
571  [
572  'uid' => 1990,
573  'title' => 'Storage',
574  '_children' => [
575  ],
576  ],
577  ],
578  ],
579  [
580  'uid' => 8110,
581  'title' => 'Europe',
582  '_children' => [
583  ],
584  ],
585  ],
586  ],
587  ];
588  self::assertEquals($expected, $actual);
589  }
590 
592  {
593  return [
594  'search for "ACME in your Region" (live value, but deleted in workspace)' => [
595  'ACME in your Region',
596  [],
597  ],
598  'search for non-existing value' => [
599  sha1(random_bytes(10)),
600  [],
601  ],
602  'search for "groups" (live value, but changed in workspace)' => [
603  'Groups',
604  [],
605  ],
606  'search for "teams" (workspace value)' => [
607  'Teams',
608  [
609  [
610  'uid' => 1400,
611  'title' => 'EN: ACME in your Region',
612  '_children' => [
613  [
614  'uid' => 1410,
615  'title' => 'EN: Teams modified',
616  '_children' => [],
617  ],
618  ],
619  ],
620  ],
621  ],
622  // page with sub-pages moved in workspace 1
623  // from pid 1510 (missing permissions) to pid 1700 (visible now)
624  'search for "products" (moved from pid 1510 to pid 1700 in workspace)' => [
625  'Product',
626  [
627  [
628  'uid' => 1700,
629  'title' => 'Announcements & News',
630  '_children' => [
631  [
632  'uid' => 1511,
633  'title' => 'Products',
634  '_children' => [
635  [
636  'uid' => 151110,
637  'title' => 'Product 1',
638  '_children' => [],
639  ],
640  ],
641  ],
642  ],
643  ],
644  ],
645  ],
646  ];
647  }
648 
656  public function ‪getAllEntryPointPageTreesInWorkspaceWithSearch(string $search, array $expectedChildren): void
657  {
658  $this->‪setWorkspace(1);
659  // the record was changed from live "Groups" to "Teams modified" in a workspace
660  $actual = $this->subject->_call('getAllEntryPointPageTrees', 0, $search);
661  $keepProperties = array_flip(['uid', 'title', '_children']);
662  $actual = $this->sortTreeArray($actual);
663  $actual = $this->normalizeTreeArray($actual, $keepProperties);
664 
665  $expected = [
666  [
667  'uid' => 0,
668  'title' => 'New TYPO3 site',
669  '_children' => [
670  [
671  'uid' => 1000,
672  'title' => 'ACME Inc',
673  '_children' => $expectedChildren,
674  ],
675  [
676  'uid' => 8110,
677  'title' => 'Europe',
678  '_children' => [
679  ],
680  ],
681  ],
682  ],
683  ];
684  self::assertEquals($expected, $actual);
685  }
686 
690  public function ‪getSubtreeForAccessiblePageInWorkspace(): void
691  {
692  $this->‪setWorkspace(1);
693  $actual = $this->subject->_call('getAllEntryPointPageTrees', 1200);
694  $keepProperties = array_flip(['uid', 'title', '_children']);
695  $actual = $this->sortTreeArray($actual);
696  $actual = $this->normalizeTreeArray($actual, $keepProperties);
697 
698  $expected = [
699  [
700  'uid' => 1200,
701  'title' => 'EN: Features modified',
702  '_children' => [
703  [
704  'uid' => 1240,
705  'title' => 'EN: Managing data',
706  '_children' => [
707  [
708  'uid' => 124010,
709  'title' => 'EN: Managing complex data',
710  '_children' => [],
711  ],
712  ],
713  ],
714  [
715  'uid' => 1230,
716  'title' => 'EN: Managing content',
717  '_children' => [
718  ],
719  ],
720  ],
721  ],
722  ];
723  self::assertEquals($expected, $actual);
724  }
725 
729  private function ‪setWorkspace(int $workspaceId): void
730  {
731  $this->backendUser->workspace = $workspaceId;
732  $this->context->setAspect('workspace', new ‪WorkspaceAspect($workspaceId));
733  }
734 }
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getSubtreeForNonAccessiblePage
‪getSubtreeForNonAccessiblePage()
Definition: TreeControllerTest.php:404
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\setUp
‪setUp()
Definition: TreeControllerTest.php:63
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesWithRootPageAsMountPoint
‪getAllEntryPointPageTreesWithRootPageAsMountPoint()
Definition: TreeControllerTest.php:212
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: TreeControllerTest.php:40
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesWithSearch
‪getAllEntryPointPageTreesWithSearch()
Definition: TreeControllerTest.php:326
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesWithMountPointPreservesOrdering
‪getAllEntryPointPageTreesWithMountPointPreservesOrdering()
Definition: TreeControllerTest.php:432
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getSubtreeForAccessiblePageInWorkspace
‪getSubtreeForAccessiblePageInWorkspace()
Definition: TreeControllerTest.php:686
‪TYPO3\CMS\Backend\Tests\Functional\Tree\Repository\Fixtures\Tree\NormalizeTreeTrait
Definition: NormalizeTreeTrait.php:21
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesInWorkspace
‪getAllEntryPointPageTreesInWorkspace()
Definition: TreeControllerTest.php:466
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getSubtreeForPageOutsideMountPoint
‪getSubtreeForPageOutsideMountPoint()
Definition: TreeControllerTest.php:418
‪TYPO3\CMS\Backend\Controller\Page\TreeController
Definition: TreeController.php:48
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\$subject
‪TreeController AccessibleObjectInterface $subject
Definition: TreeControllerTest.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTrees
‪getAllEntryPointPageTrees()
Definition: TreeControllerTest.php:97
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesInWorkspaceWithSearchDataProvider
‪getAllEntryPointPageTreesInWorkspaceWithSearchDataProvider()
Definition: TreeControllerTest.php:587
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getAllEntryPointPageTreesInWorkspaceWithSearch
‪getAllEntryPointPageTreesInWorkspaceWithSearch(string $search, array $expectedChildren)
Definition: TreeControllerTest.php:652
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: TreeControllerTest.php:42
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\setWorkspace
‪setWorkspace(int $workspaceId)
Definition: TreeControllerTest.php:725
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\setUpDatabase
‪setUpDatabase()
Definition: TreeControllerTest.php:82
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\$backendUserFixture
‪string $backendUserFixture
Definition: TreeControllerTest.php:61
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page
Definition: LocalizationControllerTest.php:18
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: TreeControllerTest.php:51
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\$context
‪Context $context
Definition: TreeControllerTest.php:55
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest
Definition: TreeControllerTest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\getSubtreeForAccessiblePage
‪getSubtreeForAccessiblePage()
Definition: TreeControllerTest.php:371
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tests\Functional\Controller\Page\TreeControllerTest\tearDown
‪tearDown()
Definition: TreeControllerTest.php:76