TYPO3 CMS  TYPO3_7-6
ExtensionManagementUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
28 
33 {
37  protected $singletonInstances = [];
38 
43 
44  protected function setUp()
45  {
46  $this->singletonInstances = GeneralUtility::getSingletonInstances();
48  $this->singletonInstances = GeneralUtility::getSingletonInstances();
49  }
50 
51  protected function tearDown()
52  {
56  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->backUpPackageManager);
57  GeneralUtility::resetSingletonInstances($this->singletonInstances);
58  parent::tearDown();
59  }
60 
66  protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = ['getPackagePath', 'getPackageKey'])
67  {
68  $packagePath = PATH_site . 'typo3temp/' . $packageKey . '/';
69  GeneralUtility::mkdir_deep($packagePath);
70  $this->testFilesToDelete[] = $packagePath;
71  $package = $this->getMockBuilder(Package::class)
72  ->disableOriginalConstructor()
73  ->setMethods($packageMethods)
74  ->getMock();
75  $packageManager = $this->getMock(
76  PackageManager::class,
77  ['isPackageActive', 'getPackage', 'getActivePackages']
78  );
79  $package->expects($this->any())
80  ->method('getPackagePath')
81  ->will($this->returnValue($packagePath));
82  $package->expects($this->any())
83  ->method('getPackageKey')
84  ->will($this->returnValue($packageKey));
85  $packageManager->expects($this->any())
86  ->method('isPackageActive')
87  ->will($this->returnValueMap([
88  [null, false],
89  [$packageKey, true]
90  ]));
91  $packageManager->expects($this->any())
92  ->method('getPackage')
93  ->with($this->equalTo($packageKey))
94  ->will($this->returnValue($package));
95  $packageManager->expects($this->any())
96  ->method('getActivePackages')
97  ->will($this->returnValue([$packageKey => $package]));
98  return $packageManager;
99  }
100 
102  // Tests concerning isLoaded
104 
108  {
109  $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), false));
110  }
111 
117  {
118  $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), true));
119  }
120 
122  // Tests concerning extPath
124 
128  public function extPathThrowsExceptionIfExtensionIsNotLoaded()
129  {
130  $packageName = $this->getUniqueId('foo');
132  $packageManager = $this->getMock(PackageManager::class, ['isPackageActive']);
133  $packageManager->expects($this->once())
134  ->method('isPackageActive')
135  ->with($this->equalTo($packageName))
136  ->will($this->returnValue(false));
139  }
140 
144  public function extPathAppendsScriptNameToPath()
145  {
146  $package = $this->getMockBuilder(Package::class)
147  ->disableOriginalConstructor()
148  ->setMethods(['getPackagePath'])
149  ->getMock();
151  $packageManager = $this->getMock(PackageManager::class, ['isPackageActive', 'getPackage']);
152  $package->expects($this->once())
153  ->method('getPackagePath')
154  ->will($this->returnValue(PATH_site . 'foo/'));
155  $packageManager->expects($this->once())
156  ->method('isPackageActive')
157  ->with($this->equalTo('foo'))
158  ->will($this->returnValue(true));
159  $packageManager->expects($this->once())
160  ->method('getPackage')
161  ->with('foo')
162  ->will($this->returnValue($package));
164  $this->assertSame(PATH_site . 'foo/bar.txt', ExtensionManagementUtility::extPath('foo', 'bar.txt'));
165  }
166 
168  // Utility functions
170 
176  private function generateTCAForTable($table)
177  {
178  $tca = [];
179  $tca[$table] = [];
180  $tca[$table]['columns'] = [
181  'fieldA' => [],
182  'fieldC' => []
183  ];
184  $tca[$table]['types'] = [
185  'typeA' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
186  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
187  'typeC' => ['showitem' => 'fieldC;;paletteD']
188  ];
189  $tca[$table]['palettes'] = [
190  'paletteA' => ['showitem' => 'fieldX, fieldX1, fieldY'],
191  'paletteB' => ['showitem' => 'fieldX, fieldX1, fieldY'],
192  'paletteC' => ['showitem' => 'fieldX, fieldX1, fieldY'],
193  'paletteD' => ['showitem' => 'fieldX, fieldX1, fieldY']
194  ];
195  return $tca;
196  }
197 
203  public function extensionKeyDataProvider()
204  {
205  return [
206  'Without underscores' => [
207  'testkey',
208  'tx_testkey'
209  ],
210  'With underscores' => [
211  'this_is_a_test_extension',
212  'tx_thisisatestextension'
213  ],
214  'With user prefix and without underscores' => [
215  'user_testkey',
216  'user_testkey'
217  ],
218  'With user prefix and with underscores' => [
219  'user_test_key',
220  'user_testkey'
221  ],
222  ];
223  }
224 
231  public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix)
232  {
233  $this->assertSame($expectedPrefix, ExtensionManagementUtility::getCN($extensionName));
234  }
235 
237  // Tests concerning getExtensionKeyByPrefix
239 
243  public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey()
244  {
246  $uniqueSuffix = $this->getUniqueId('test');
247  $extensionKey = 'tt_news' . $uniqueSuffix;
248  $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
249  $package = $this->getMockBuilder(Package::class)
250  ->disableOriginalConstructor()
251  ->setMethods(['getPackageKey'])
252  ->getMock();
253  $package->expects($this->exactly(2))
254  ->method('getPackageKey')
255  ->will($this->returnValue($extensionKey));
257  $packageManager = $this->getMock(PackageManager::class, ['getActivePackages']);
258  $packageManager->expects($this->once())
259  ->method('getActivePackages')
260  ->will($this->returnValue([$extensionKey => $package]));
262  $this->assertEquals($extensionKey, ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
263  }
264 
269  public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey()
270  {
272  $uniqueSuffix = $this->getUniqueId('test');
273  $extensionKey = 'kickstarter' . $uniqueSuffix;
274  $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
275  $package = $this->getMockBuilder(Package::class)
276  ->disableOriginalConstructor()
277  ->setMethods(['getPackageKey'])
278  ->getMock();
279  $package->expects($this->exactly(2))
280  ->method('getPackageKey')
281  ->will($this->returnValue($extensionKey));
283  $packageManager = $this->getMock(PackageManager::class, ['getActivePackages']);
284  $packageManager->expects($this->once())
285  ->method('getActivePackages')
286  ->will($this->returnValue([$extensionKey => $package]));
288  $this->assertEquals($extensionKey, ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
289  }
290 
296  {
298  $uniqueSuffix = $this->getUniqueId('test');
299  $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
300  $this->assertFalse(ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
301  }
302 
304  // Tests concerning addToAllTCAtypes
306 
313  {
314  $table = $this->getUniqueId('tx_coretest_table');
315  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
316  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
317  // Checking typeA:
318  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
319  // Checking typeB:
320  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
321  }
322 
330  {
331  $table = $this->getUniqueId('tx_coretest_table');
332  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
333  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
334  // Checking typeA:
335  $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
336  // Checking typeB:
337  $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
338  }
339 
347  {
348  $table = $this->getUniqueId('tx_coretest_table');
349  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
350  $GLOBALS['TCA'][$table]['types']['typeD'] = ['showitem' => 'fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, fieldZ'];
351  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard');
352  // Checking typeD:
353  $this->assertEquals('fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, newA, newB, fieldA, fieldZ', $GLOBALS['TCA'][$table]['types']['typeD']['showitem']);
354  }
355 
363  {
364  $table = $this->getUniqueId('tx_coretest_table');
365  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
366  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldX1');
367  // Checking typeA:
368  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
369  }
370 
378  {
379  $table = $this->getUniqueId('tx_coretest_table');
380  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
381  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
382  // Checking typeA:
383  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
384  // Checking typeB:
385  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
386  }
387 
395  {
396  $table = $this->getUniqueId('tx_coretest_table');
397  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
398  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
399  // Checking typeA:
400  $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
401  // Checking typeB:
402  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
403  }
404 
409  {
410  $table = $this->getUniqueId('tx_coretest_table');
411  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
412  ExtensionManagementUtility::addToAllTCAtypes($table, 'field', 'typeA', 'after:fieldD1');
413 
414  $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1, field', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
415  }
416 
424  {
425  $table = $this->getUniqueId('tx_coretest_table');
426  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
427  $typesBefore = $GLOBALS['TCA'][$table]['types'];
428  ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
429  $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
430  // unchanged because the palette is not used
431  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
432  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
433  // changed
434  $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
435  $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
436  }
437 
442  {
443  $table = $this->getUniqueId('tx_coretest_table');
444  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
445  $typesBefore = $GLOBALS['TCA'][$table]['types'];
446  ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldX, --palette--;;foo', '', 'replace:fieldX');
447  $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
448  // unchanged because the palette is not used
449  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
450  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
451  // changed
452  $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
453  $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
454  }
455 
463  {
464  $table = $this->getUniqueId('tx_coretest_table');
465  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
466  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
467  $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
468  }
469 
477  {
478  $table = $this->getUniqueId('tx_coretest_table');
479  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
480  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
481  $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
482  }
483 
491  {
492  $table = $this->getUniqueId('tx_coretest_table');
493  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
494  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . $this->getUniqueId('notExisting'));
495  $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
496  }
497 
502  {
503  return [
504  'Simple' => [
505  'field_b, field_d, field_c',
506  'field_a, field_b, field_c',
507  'field_d'
508  ],
509  'with linebreaks' => [
510  'field_b, --linebreak--, field_d, --linebreak--, field_c',
511  'field_a, field_b, field_c',
512  '--linebreak--, field_d, --linebreak--'
513  ],
514  'with linebreaks in list and insertion list' => [
515  'field_b, --linebreak--, field_d, --linebreak--, field_c',
516  'field_a, field_b, --linebreak--, field_c',
517  '--linebreak--, field_d, --linebreak--'
518  ],
519  ];
520  }
521 
529  public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected)
530  {
532  $this->assertSame($expected, $result);
533  }
534 
536  // Tests concerning addFieldsToAllPalettesOfField
538 
543  {
544  $GLOBALS['TCA'] = [
545  'aTable' => [
546  'types' => [
547  'typeA' => [
548  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
549  ],
550  ],
551  'palettes' => [
552  'paletteA' => [
553  'showitem' => 'fieldX, fieldY',
554  ],
555  ],
556  ],
557  ];
558  $expected = $GLOBALS['TCA'];
560  'aTable',
561  'fieldA',
562  'newA'
563  );
564  $this->assertEquals($expected, $GLOBALS['TCA']);
565  }
566 
571  {
572  $GLOBALS['TCA'] = [
573  'aTable' => [
574  'columns' => [
575  'fieldA' => [],
576  ],
577  'types' => [
578  'typeA' => [
579  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
580  ],
581  ],
582  'palettes' => [
583  'paletteA' => [
584  'showitem' => 'fieldX, fieldY',
585  ],
586  ],
587  ],
588  ];
589  $expected = [
590  'aTable' => [
591  'columns' => [
592  'fieldA' => [],
593  ],
594  'types' => [
595  'typeA' => [
596  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
597  ],
598  ],
599  'palettes' => [
600  'paletteA' => [
601  'showitem' => 'fieldX, fieldY, dupeA',
602  ],
603  ],
604  ],
605  ];
607  'aTable',
608  'fieldA',
609  'dupeA, dupeA' // Duplicate
610  );
611  $this->assertEquals($expected, $GLOBALS['TCA']);
612  }
613 
618  {
619  $GLOBALS['TCA'] = [
620  'aTable' => [
621  'columns' => [
622  'fieldA' => [],
623  ],
624  'types' => [
625  'typeA' => [
626  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
627  ],
628  ],
629  'palettes' => [
630  'paletteA' => [
631  'showitem' => 'existingA',
632  ],
633  ],
634  ],
635  ];
636  $expected = [
637  'aTable' => [
638  'columns' => [
639  'fieldA' => [],
640  ],
641  'types' => [
642  'typeA' => [
643  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
644  ],
645  ],
646  'palettes' => [
647  'paletteA' => [
648  'showitem' => 'existingA',
649  ],
650  ],
651  ],
652  ];
654  'aTable',
655  'fieldA',
656  'existingA'
657  );
658  $this->assertEquals($expected, $GLOBALS['TCA']);
659  }
660 
665  {
666  $GLOBALS['TCA'] = [
667  'aTable' => [
668  'columns' => [
669  'fieldA' => [],
670  ],
671  'types' => [
672  'typeA' => [
673  'showitem' => 'fieldA, --palette--;;palette1',
674  ],
675  'typeB' => [
676  'showitem' => 'fieldA;aLabel, --palette--;;palette2',
677  ],
678  ],
679  'palettes' => [
680  'palette1' => [
681  'showitem' => 'fieldX',
682  ],
683  'palette2' => [
684  'showitem' => 'fieldY',
685  ],
686  ],
687  ],
688  ];
689  $expected = [
690  'aTable' => [
691  'columns' => [
692  'fieldA' => [],
693  ],
694  'types' => [
695  'typeA' => [
696  'showitem' => 'fieldA, --palette--;;palette1',
697  ],
698  'typeB' => [
699  'showitem' => 'fieldA;aLabel, --palette--;;palette2',
700  ],
701  ],
702  'palettes' => [
703  'palette1' => [
704  'showitem' => 'fieldX, newA',
705  ],
706  'palette2' => [
707  'showitem' => 'fieldY, newA',
708  ],
709  ],
710  ],
711  ];
713  'aTable',
714  'fieldA',
715  'newA'
716  );
717  $this->assertEquals($expected, $GLOBALS['TCA']);
718  }
719 
724  {
725  $GLOBALS['TCA'] = [
726  'aTable' => [
727  'columns' => [
728  'fieldA' => [],
729  ],
730  'types' => [
731  'typeA' => [
732  'showitem' => 'fieldA, --palette--;;palette1',
733  ],
734  ],
735  'palettes' => [
736  'palette1' => [
737  'showitem' => 'fieldX',
738  ],
739  ],
740  ],
741  ];
742  $expected = [
743  'aTable' => [
744  'columns' => [
745  'fieldA' => [],
746  ],
747  'types' => [
748  'typeA' => [
749  'showitem' => 'fieldA, --palette--;;palette1',
750  ],
751  ],
752  'palettes' => [
753  'palette1' => [
754  'showitem' => 'fieldX, newA, newB',
755  ],
756  ],
757  ],
758  ];
760  'aTable',
761  'fieldA',
762  'newA, newB'
763  );
764  $this->assertEquals($expected, $GLOBALS['TCA']);
765  }
766 
771  {
772  $GLOBALS['TCA'] = [
773  'aTable' => [
774  'columns' => [
775  'fieldA' => [],
776  ],
777  'types' => [
778  'typeA' => [
779  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
780  ],
781  ],
782  'palettes' => [
783  'paletteA' => [
784  'showitem' => 'existingA, existingB',
785  ],
786  ],
787  ],
788  ];
789  $expected = [
790  'aTable' => [
791  'columns' => [
792  'fieldA' => [],
793  ],
794  'types' => [
795  'typeA' => [
796  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
797  ],
798  ],
799  'palettes' => [
800  'paletteA' => [
801  'showitem' => 'existingA, newA, existingB',
802  ],
803  ],
804  ],
805  ];
807  'aTable',
808  'fieldA',
809  'newA',
810  'before:existingB'
811  );
812  $this->assertEquals($expected, $GLOBALS['TCA']);
813  }
814 
819  {
820  $GLOBALS['TCA'] = [
821  'aTable' => [
822  'columns' => [
823  'fieldA' => [],
824  ],
825  'types' => [
826  'typeA' => [
827  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
828  ],
829  ],
830  'palettes' => [
831  'paletteA' => [
832  'showitem' => 'fieldX, fieldY',
833  ],
834  ],
835  ],
836  ];
837  $expected = [
838  'aTable' => [
839  'columns' => [
840  'fieldA' => [],
841  ],
842  'types' => [
843  'typeA' => [
844  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
845  ],
846  ],
847  'palettes' => [
848  'paletteA' => [
849  'showitem' => 'fieldX, fieldY, newA, newB',
850  ],
851  ],
852  ],
853  ];
855  'aTable',
856  'fieldA',
857  'newA, newB',
858  'before:notExisting'
859  );
860  $this->assertEquals($expected, $GLOBALS['TCA']);
861  }
862 
867  {
868  $GLOBALS['TCA'] = [
869  'aTable' => [
870  'columns' => [
871  'fieldA' => [],
872  ],
873  'types' => [
874  'typeA' => [
875  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
876  ],
877  ],
878  'palettes' => [
879  'paletteA' => [
880  'showitem' => 'existingA, existingB',
881  ],
882  ],
883  ],
884  ];
885  $expected = [
886  'aTable' => [
887  'columns' => [
888  'fieldA' => [],
889  ],
890  'types' => [
891  'typeA' => [
892  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
893  ],
894  ],
895  'palettes' => [
896  'paletteA' => [
897  'showitem' => 'existingA, newA, existingB',
898  ],
899  ],
900  ],
901  ];
903  'aTable',
904  'fieldA',
905  'newA',
906  'after:existingA'
907  );
908  $this->assertEquals($expected, $GLOBALS['TCA']);
909  }
910 
915  {
916  $GLOBALS['TCA'] = [
917  'aTable' => [
918  'columns' => [
919  'fieldA' => [],
920  ],
921  'types' => [
922  'typeA' => [
923  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
924  ],
925  ],
926  'palettes' => [
927  'paletteA' => [
928  'showitem' => 'existingA, existingB',
929  ],
930  ],
931  ],
932  ];
933  $expected = [
934  'aTable' => [
935  'columns' => [
936  'fieldA' => [],
937  ],
938  'types' => [
939  'typeA' => [
940  'showitem' => 'fieldA;labelA, --palette--;;paletteA',
941  ],
942  ],
943  'palettes' => [
944  'paletteA' => [
945  'showitem' => 'existingA, existingB, newA, newB',
946  ],
947  ],
948  ],
949  ];
951  'aTable',
952  'fieldA',
953  'newA, newB',
954  'after:notExistingA'
955  );
956  $this->assertEquals($expected, $GLOBALS['TCA']);
957  }
958 
963  {
964  $GLOBALS['TCA'] = [
965  'aTable' => [
966  'columns' => [
967  'fieldA' => [],
968  ],
969  'types' => [
970  'typeA' => [
971  'showitem' => 'fieldA',
972  ],
973  ],
974  ],
975  ];
976  $expected = [
977  'aTable' => [
978  'columns' => [
979  'fieldA' => [],
980  ],
981  'types' => [
982  'typeA' => [
983  'showitem' => 'fieldA, --palette--;;generatedFor-fieldA',
984  ],
985  ],
986  'palettes' => [
987  'generatedFor-fieldA' => [
988  'showitem' => 'newA',
989  ],
990  ],
991  ],
992  ];
994  'aTable',
995  'fieldA',
996  'newA'
997  );
998  $this->assertEquals($expected, $GLOBALS['TCA']);
999  }
1000 
1005  {
1006  $GLOBALS['TCA'] = [
1007  'aTable' => [
1008  'columns' => [
1009  'fieldA' => [],
1010  ],
1011  'types' => [
1012  'typeA' => [
1013  'showitem' => 'fieldA;labelA',
1014  ],
1015  ],
1016  ],
1017  ];
1018  $expected = [
1019  'aTable' => [
1020  'columns' => [
1021  'fieldA' => [],
1022  ],
1023  'types' => [
1024  'typeA' => [
1025  'showitem' => 'fieldA;labelA, --palette--;;generatedFor-fieldA',
1026  ],
1027  ],
1028  'palettes' => [
1029  'generatedFor-fieldA' => [
1030  'showitem' => 'newA',
1031  ],
1032  ],
1033  ],
1034  ];
1036  'aTable',
1037  'fieldA',
1038  'newA'
1039  );
1040  $this->assertEquals($expected, $GLOBALS['TCA']);
1041  }
1042 
1044  // Tests concerning executePositionedStringInsertion
1046 
1052  {
1053  return [
1054  'normal characters' => [
1055  'tr0',
1056  'tr0',
1057  ],
1058  'newlines' => [
1059  "test\n",
1060  'test',
1061  ],
1062  'newlines with carriage return' => [
1063  "test\r\n",
1064  'test',
1065  ],
1066  'tabs' => [
1067  "test\t",
1068  'test',
1069  ],
1070  'commas' => [
1071  'test,',
1072  'test',
1073  ],
1074  'multiple commas with trailing spaces' => [
1075  "test,,\t, \r\n",
1076  'test',
1077  ],
1078  ];
1079  }
1080 
1087  public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult)
1088  {
1089  $extensionManagementUtility = $this->getAccessibleMock(ExtensionManagementUtility::class, ['dummy']);
1090  $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
1091  $this->assertEquals($expectedResult, $string);
1092  }
1093 
1095  // Tests concerning addTcaSelectItem
1097 
1102  {
1104  }
1105 
1111  {
1113  }
1114 
1120  {
1121  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', [], []);
1122  }
1123 
1129  {
1130  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', [], 'foo', []);
1131  }
1132 
1138  {
1139  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', [], 'foo', 'not allowed keyword');
1140  }
1141 
1147  {
1148  $GLOBALS['TCA'] = [];
1150  }
1151 
1156  {
1157  // Every array splits into:
1158  // - relativeToField
1159  // - relativePosition
1160  // - expectedResultArray
1161  return [
1162  'add at end of array' => [
1163  '',
1164  '',
1165  [
1166  0 => ['firstElement'],
1167  1 => ['matchMe'],
1168  2 => ['thirdElement'],
1169  3 => ['insertedElement']
1170  ]
1171  ],
1172  'replace element' => [
1173  'matchMe',
1174  'replace',
1175  [
1176  0 => ['firstElement'],
1177  1 => ['insertedElement'],
1178  2 => ['thirdElement']
1179  ]
1180  ],
1181  'add element after' => [
1182  'matchMe',
1183  'after',
1184  [
1185  0 => ['firstElement'],
1186  1 => ['matchMe'],
1187  2 => ['insertedElement'],
1188  3 => ['thirdElement']
1189  ]
1190  ],
1191  'add element before' => [
1192  'matchMe',
1193  'before',
1194  [
1195  0 => ['firstElement'],
1196  1 => ['insertedElement'],
1197  2 => ['matchMe'],
1198  3 => ['thirdElement']
1199  ]
1200  ],
1201  'add at end if relative position was not found' => [
1202  'notExistingItem',
1203  'after',
1204  [
1205  0 => ['firstElement'],
1206  1 => ['matchMe'],
1207  2 => ['thirdElement'],
1208  3 => ['insertedElement']
1209  ]
1210  ]
1211  ];
1212  }
1213 
1221  public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
1222  {
1223  $GLOBALS['TCA'] = [
1224  'testTable' => [
1225  'columns' => [
1226  'testField' => [
1227  'config' => [
1228  'items' => [
1229  '0' => ['firstElement'],
1230  '1' => ['matchMe'],
1231  2 => ['thirdElement']
1232  ]
1233  ]
1234  ]
1235  ]
1236  ]
1237  ];
1238  ExtensionManagementUtility::addTcaSelectItem('testTable', 'testField', ['insertedElement'], $relativeToField, $relativePosition);
1239  $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
1240  }
1241 
1243  // Tests concerning loadExtLocalconf
1245 
1248  public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied()
1249  {
1251  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1252  $mockCacheManager->expects($this->never())->method('getCache');
1254  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1255  ExtensionManagementUtility::loadExtLocalconf(false);
1256  }
1257 
1261  public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed()
1262  {
1263  $mockCache = $this->getMock(
1264  AbstractFrontend::class,
1265  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1266  [],
1267  '',
1268  false
1269  );
1271  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1272  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1274  $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1275  $mockCache->expects($this->once())->method('requireOnce');
1276  ExtensionManagementUtility::loadExtLocalconf(true);
1277  }
1278 
1280  // Tests concerning loadSingleExtLocalconfFiles
1282 
1287  {
1288  $extensionName = $this->getUniqueId('foo');
1289  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1290  $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1291  file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
1292  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1294  }
1295 
1297  // Tests concerning addModule
1299 
1305  {
1306  return [
1307  'can add new main module if none exists' => [
1308  'top',
1309  '',
1310  'newModule'
1311  ],
1312  'can add new sub module if no position specified' => [
1313  '',
1314  'some,modules',
1315  'some,modules,newModule'
1316  ],
1317  'can add new sub module to top of module' => [
1318  'top',
1319  'some,modules',
1320  'newModule,some,modules'
1321  ],
1322  'can add new sub module if bottom of module' => [
1323  'bottom',
1324  'some,modules',
1325  'some,modules,newModule'
1326  ],
1327  'can add new sub module before specified sub module' => [
1328  'before:modules',
1329  'some,modules',
1330  'some,newModule,modules'
1331  ],
1332  'can add new sub module after specified sub module' => [
1333  'after:some',
1334  'some,modules',
1335  'some,newModule,modules'
1336  ],
1337  'can add new sub module at the bottom if specified sub module to add before does not exist' => [
1338  'before:modules',
1339  'some,otherModules',
1340  'some,otherModules,newModule'
1341  ],
1342  'can add new sub module at the bottom if specified sub module to add after does not exist' => [
1343  'after:some',
1344  'someOther,modules',
1345  'someOther,modules,newModule'
1346  ],
1347  ];
1348  }
1349 
1357  public function addModuleCanAddModule($position, $existing, $expected)
1358  {
1359  $mainModule = 'foobar';
1360  $subModule = 'newModule';
1361  if ($existing) {
1362  $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
1363  }
1364 
1365  ExtensionManagementUtility::addModule($mainModule, $subModule, $position);
1366 
1367  $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
1368  $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
1369  }
1370 
1372  // Tests concerning createExtLocalconfCacheEntry
1374 
1377  public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf()
1378  {
1379  $extensionName = $this->getUniqueId('foo');
1380  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1381  $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1382  $uniqueStringInLocalconf = $this->getUniqueId('foo');
1383  file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
1384  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1385  $mockCache = $this->getMock(
1386  AbstractFrontend::class,
1387  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1388  [],
1389  '',
1390  false
1391  );
1393  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1394  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1396  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
1398  }
1399 
1403  public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists()
1404  {
1405  $extensionName = $this->getUniqueId('foo');
1406  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1407  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1408  $mockCache = $this->getMock(
1409  AbstractFrontend::class,
1410  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1411  [],
1412  '',
1413  false
1414  );
1416  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1417  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1419  $mockCache->expects($this->once())
1420  ->method('set')
1421  ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1423  }
1424 
1428  public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags()
1429  {
1430  $mockCache = $this->getMock(
1431  AbstractFrontend::class,
1432  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1433  [],
1434  '',
1435  false
1436  );
1438  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1439  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1441  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1442  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1444  }
1445 
1447  // Tests concerning getExtLocalconfCacheIdentifier
1449 
1453  {
1454  $prefix = 'ext_localconf_';
1456  $this->assertStringStartsWith($prefix, $identifier);
1457  $sha1 = str_replace($prefix, '', $identifier);
1458  $this->assertEquals(40, strlen($sha1));
1459  }
1460 
1462  // Tests concerning loadBaseTca
1464 
1468  public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied()
1469  {
1471  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1472  $mockCacheManager->expects($this->never())->method('getCache');
1474  ExtensionManagementUtilityAccessibleProxy::loadBaseTca(false);
1475  }
1476 
1480  public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed()
1481  {
1482  $mockCache = $this->getMock(
1483  AbstractFrontend::class,
1484  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1485  [],
1486  '',
1487  false
1488  );
1490  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1491  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1493  $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1494  $mockCache->expects($this->once())->method('get')->willReturn('<?php ' . serialize(['tca' => [], 'categoryRegistry' => CategoryRegistry::getInstance()]) . '?>');
1495  ExtensionManagementUtilityAccessibleProxy::loadBaseTca(true);
1496  }
1497 
1501  public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile()
1502  {
1503  $extensionName = $this->getUniqueId('test_baseTca_');
1504  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1505  $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
1506  GeneralUtility::mkdir($packagePath);
1507  GeneralUtility::mkdir($packagePath . 'Configuration/');
1508  GeneralUtility::mkdir($packagePath . 'Configuration/TCA/');
1509  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1511  $uniqueTableName = $this->getUniqueId('table_name_');
1512  $uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_');
1513  $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
1514  file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
1515  $mockCache = $this->getMock(
1516  AbstractFrontend::class,
1517  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1518  [],
1519  '',
1520  false
1521  );
1523  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1524  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1525  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1526  $mockCache->expects($this->once())->method('has')->will($this->returnValue(false));
1527  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1528  ExtensionManagementUtility::loadBaseTca(true);
1529  }
1530 
1534  public function loadBaseTcaWritesCacheEntryWithNoTags()
1535  {
1536  $mockCache = $this->getMock(
1537  AbstractFrontend::class,
1538  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1539  [],
1540  '',
1541  false
1542  );
1544  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1545  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1546  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1547  $mockCache->expects($this->once())->method('has')->will($this->returnValue(false));
1548  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1549  ExtensionManagementUtilityAccessibleProxy::loadBaseTca();
1550  }
1551 
1553  // Tests concerning getBaseTcaCacheIdentifier
1555 
1559  public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1560  {
1561  $prefix = 'tca_base_';
1562  $identifier = ExtensionManagementUtilityAccessibleProxy::getBaseTcaCacheIdentifier();
1563  $this->assertStringStartsWith($prefix, $identifier);
1564  $sha1 = str_replace($prefix, '', $identifier);
1565  $this->assertEquals(40, strlen($sha1));
1566  }
1567 
1569  // Tests concerning loadExtTables
1571 
1574  public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied()
1575  {
1577  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1578  $mockCacheManager->expects($this->never())->method('getCache');
1579  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1580  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1581  ExtensionManagementUtility::loadExtLocalconf(false);
1582  }
1583 
1587  public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed()
1588  {
1589  $mockCache = $this->getMock(
1590  AbstractFrontend::class,
1591  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1592  [],
1593  '',
1594  false
1595  );
1597  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1598  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1599  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1600  $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1601  $mockCache->expects($this->once())->method('requireOnce');
1602  // Reset the internal cache access tracking variable of extMgm
1603  // This method is only in the ProxyClass!
1604  ExtensionManagementUtilityAccessibleProxy::resetExtTablesWasReadFromCacheOnceBoolean();
1605  ExtensionManagementUtility::loadExtTables(true);
1606  }
1607 
1609  // Tests concerning createExtTablesCacheEntry
1611 
1614  public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
1615  {
1616  $extensionName = $this->getUniqueId('foo');
1617  $extTablesLocation = PATH_site . 'typo3temp/' . $this->getUniqueId('test_ext_tables') . '.php';
1618  $this->testFilesToDelete[] = $extTablesLocation;
1619  $uniqueStringInTables = $this->getUniqueId('foo');
1620  file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1621  $GLOBALS['TYPO3_LOADED_EXT'] = [
1622  $extensionName => [
1623  'ext_tables.php' => $extTablesLocation
1624  ]
1625  ];
1626  $mockCache = $this->getMock(
1627  AbstractFrontend::class,
1628  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1629  [],
1630  '',
1631  false
1632  );
1634  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1635  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1636  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1637  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1638  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1639  }
1640 
1644  public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists()
1645  {
1646  $extensionName = $this->getUniqueId('foo');
1647  $GLOBALS['TYPO3_LOADED_EXT'] = [
1648  $extensionName => [],
1649  ];
1650  $mockCache = $this->getMock(
1651  AbstractFrontend::class,
1652  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1653  [],
1654  '',
1655  false
1656  );
1658  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1659  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1660  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1661  $mockCache->expects($this->once())
1662  ->method('set')
1663  ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1664  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1665  }
1666 
1670  public function createExtTablesCacheEntryWritesCacheEntryWithNoTags()
1671  {
1672  $mockCache = $this->getMock(
1673  AbstractFrontend::class,
1674  ['getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'],
1675  [],
1676  '',
1677  false
1678  );
1680  $mockCacheManager = $this->getMock(CacheManager::class, ['getCache']);
1681  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1682  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1683  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1684  $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1685  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1686  }
1687 
1689  // Tests concerning getExtTablesCacheIdentifier
1691 
1694  public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1695  {
1696  $prefix = 'ext_tables_';
1697  $identifier = ExtensionManagementUtilityAccessibleProxy::getExtTablesCacheIdentifier();
1698  $this->assertStringStartsWith($prefix, $identifier);
1699  $sha1 = str_replace($prefix, '', $identifier);
1700  $this->assertEquals(40, strlen($sha1));
1701  }
1702 
1704  // Tests concerning removeCacheFiles
1706 
1709  public function removeCacheFilesFlushesSystemCaches()
1710  {
1712  $mockCacheManager = $this->getMock(CacheManager::class, ['flushCachesInGroup']);
1713  $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1714  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1715  ExtensionManagementUtility::removeCacheFiles();
1716  }
1717 
1719  // Tests concerning loadNewTcaColumnsConfigFiles
1721 
1726  public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist()
1727  {
1728  $GLOBALS['TCA'] = [
1729  'test' => [
1730  'ctrl' => [
1731  'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1732  ],
1733  ],
1734  ];
1735  ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1736  }
1737 
1741  public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist()
1742  {
1743  $GLOBALS['TCA'] = [
1744  'test' => [
1745  'ctrl' => [
1746  'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1747  ],
1748  'columns' => [
1749  'foo' => 'bar',
1750  ],
1751  ],
1752  ];
1753  ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1754  }
1755 
1757  // Tests concerning getExtensionVersion
1759 
1764  public function getExtensionVersionFaultyDataProvider()
1765  {
1766  return [
1767  [''],
1768  [0],
1769  [new \stdClass()],
1770  [true]
1771  ];
1772  }
1773 
1781  public function getExtensionVersionForFaultyExtensionKeyThrowsException($key)
1782  {
1783  ExtensionManagementUtility::getExtensionVersion($key);
1784  }
1785 
1789  public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString()
1790  {
1791  ExtensionManagementUtility::clearExtensionKeyMap();
1792  $uniqueSuffix = $this->getUniqueId('test');
1793  $extensionKey = 'unloadedextension' . $uniqueSuffix;
1794  $this->assertEquals('', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1795  }
1796 
1800  public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion()
1801  {
1802  ExtensionManagementUtility::clearExtensionKeyMap();
1803  $uniqueSuffix = $this->getUniqueId('test');
1804  $extensionKey = 'unloadedextension' . $uniqueSuffix;
1805  $packageMetaData = $this->getMock(MetaData::class, ['getVersion'], [$extensionKey]);
1806  $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1807  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, ['getPackagePath', 'getPackageKey', 'getPackageMetaData']);
1809  $package = $packageManager->getPackage($extensionKey);
1810  $package->expects($this->any())
1811  ->method('getPackageMetaData')
1812  ->will($this->returnValue($packageMetaData));
1813  ExtensionManagementUtility::setPackageManager($packageManager);
1814  $this->assertEquals('1.2.3', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1815  }
1816 
1818  // Tests concerning loadExtension
1820 
1824  public function loadExtensionThrowsExceptionIfExtensionIsLoaded()
1825  {
1826  $extensionKey = $this->getUniqueId('test');
1827  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1828  ExtensionManagementUtility::setPackageManager($packageManager);
1829  ExtensionManagementUtility::loadExtension($extensionKey);
1830  }
1831 
1833  // Tests concerning unloadExtension
1835 
1839  public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded()
1840  {
1841  $packageName = $this->getUniqueId('foo');
1843  $packageManager = $this->getMock(PackageManager::class, ['isPackageActive']);
1844  $packageManager->expects($this->once())
1845  ->method('isPackageActive')
1846  ->with($this->equalTo($packageName))
1847  ->will($this->returnValue(false));
1848  ExtensionManagementUtility::setPackageManager($packageManager);
1849  ExtensionManagementUtility::unloadExtension($packageName);
1850  }
1851 
1855  public function unloadExtensionCallsPackageManagerToDeactivatePackage()
1856  {
1857  $packageName = $this->getUniqueId('foo');
1859  $packageManager = $this->getMock(
1860  PackageManager::class,
1861  ['isPackageActive', 'deactivatePackage']
1862  );
1863  $packageManager->expects($this->any())
1864  ->method('isPackageActive')
1865  ->will($this->returnValue(true));
1866  $packageManager->expects($this->once())
1867  ->method('deactivatePackage')
1868  ->with($packageName);
1869  ExtensionManagementUtility::setPackageManager($packageManager);
1870  ExtensionManagementUtility::unloadExtension($packageName);
1871  }
1872 
1874  // Tests concerning makeCategorizable
1876 
1879  public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
1880  {
1881  $extensionKey = $this->getUniqueId('extension');
1882  $tableName = $this->getUniqueId('table');
1883 
1885  $registryMock = $this->getMock(CategoryRegistry::class);
1886  $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', []);
1887  GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1888  ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
1889  }
1890 
1894  public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
1895  {
1896  $extensionKey = $this->getUniqueId('extension');
1897  $tableName = $this->getUniqueId('table');
1898  $fieldName = $this->getUniqueId('field');
1899 
1901  $registryMock = $this->getMock(CategoryRegistry::class);
1902  $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, []);
1903  GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1904  ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
1905  }
1906 
1908  // Tests concerning addPlugin
1910 
1914  public function addPluginSetsTcaCorrectlyForGivenExtKeyAsParameter()
1915  {
1916  $extKey = 'indexed_search';
1917  $GLOBALS['TYPO3_LOADED_EXT'] = [];
1918  $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1919  $expectedTCA = [
1920  [
1921  'label',
1922  $extKey,
1923  'EXT:' . $extKey . '/foo.gif'
1924  ]
1925  ];
1926  $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
1927  ExtensionManagementUtility::addPlugin(['label', $extKey], 'list_type', $extKey);
1928  $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1929  }
1930 
1934  public function addPluginSetsTcaCorrectlyForGivenExtKeyAsGlobal()
1935  {
1936  $extKey = 'indexed_search';
1937  $GLOBALS['TYPO3_LOADED_EXT'] = [];
1938  $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1939  $GLOBALS['_EXTKEY'] = $extKey;
1940  $expectedTCA = [
1941  [
1942  'label',
1943  $extKey,
1944  'EXT:' . $extKey . '/foo.gif'
1945  ]
1946  ];
1947  $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = [];
1948  ExtensionManagementUtility::addPlugin(['label', $extKey]);
1949  $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1950  }
1951 
1956  public function addPluginThrowsExceptionForMissingExtkey()
1957  {
1958  ExtensionManagementUtility::addPlugin('test');
1959  }
1960 }
static addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition='')
static mkdir_deep($directory, $deepDirectory='')
static resetSingletonInstances(array $newSingletonInstances)
static addToAllTCAtypes($table, $newFieldsString, $typeList='', $position='')
static addTcaSelectItem($table, $field, array $item, $relativeToField='', $relativePosition='')
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static addModule($main, $sub='', $position='', $path='', $moduleConfiguration=[])
createMockPackageManagerWithMockPackage($packageKey, $packageMethods=['getPackagePath', 'getPackageKey'])
static setPackageManager(PackageManager $packageManager)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
static addFieldsToPalette($table, $palette, $addFields, $insertionPosition='')