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