‪TYPO3CMS  11.5
FileCollectionRegistryTest.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 
25 
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->‪initializeTestSubject();
37  }
38 
39  protected function ‪initializeTestSubject(): void
40  {
41  $this->testSubject = new ‪FileCollectionRegistry();
42  }
43 
48  {
49  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
50  $this->testSubject->registerFileCollectionClass($className, 'foobar');
51  $returnedClassName = $this->testSubject->getFileCollectionClass('foobar');
52  self::assertEquals($className, $returnedClassName);
53  }
54 
59  {
60  $this->expectException(\InvalidArgumentException::class);
61  $this->expectExceptionCode(1391295613);
62 
63  $this->testSubject->registerFileCollectionClass(‪StringUtility::getUniqueId('class_'), substr(‪StringUtility::getUniqueId('type_'), 0, 30));
64  }
65 
70  {
71  $this->expectException(\InvalidArgumentException::class);
72  $this->expectExceptionCode(1391295611);
73 
74  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
75  $type = str_pad('', 40);
76  $this->testSubject->registerFileCollectionClass($className, $type);
77  }
78 
83  {
84  $this->expectException(\InvalidArgumentException::class);
85  $this->expectExceptionCode(1391295643);
86 
87  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
88  $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
89  $this->testSubject->registerFileCollectionClass($className, 'foobar');
90  $this->testSubject->registerFileCollectionClass($className2, 'foobar');
91  }
92 
97  {
98  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
99  $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
100  $this->testSubject->registerFileCollectionClass($className, 'foobar');
101  $this->testSubject->registerFileCollectionClass($className2, 'foobar', true);
102  }
103 
108  {
109  $this->expectException(\InvalidArgumentException::class);
110  $this->expectExceptionCode(1391295644);
111 
112  $this->testSubject->getFileCollectionClass(‪StringUtility::getUniqueId());
113  }
114 
119  {
120  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
121  $this->testSubject->registerFileCollectionClass($className, 'foobar');
122  self::assertEquals($className, $this->testSubject->getFileCollectionClass('foobar'));
123  }
124 
129  {
130  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
131  $type = substr(‪StringUtility::getUniqueId('type_'), 0, 30);
132  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
133  $type => $className,
134  ];
135  $this->‪initializeTestSubject();
136  self::assertEquals($className, $this->testSubject->getFileCollectionClass($type));
137  }
138 
143  {
144  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
145  $type = 'foo';
146  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
147  $type => $className,
148  ];
149  $this->‪initializeTestSubject();
150  self::assertTrue($this->testSubject->fileCollectionTypeExists($type));
151  self::assertFalse($this->testSubject->fileCollectionTypeExists('bar'));
152  }
153 
158  {
159  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredFileCollections'] = [];
160  $this->‪initializeTestSubject();
161  self::assertFalse($this->testSubject->fileCollectionTypeExists(‪StringUtility::getUniqueId('name_')));
162  }
163 
167  public function ‪addNewTypeToTCA(): void
168  {
169  // Create a TCA fixture for sys_file_collection
170  ‪$GLOBALS['TCA']['sys_file_collection'] = [
171  'types' => [
172  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldD'],
173  ],
174  'columns' => [
175  'type' => [
176  'config' => [
177  'items' => ['Type B', 'typeB'],
178  ],
179  ],
180  ],
181  ];
182 
183  $type = 'my_type';
184  $label = 'The Label';
185 
186  $this->testSubject->addTypeToTCA($type, $label, 'something');
187 
188  // check type
189  self::assertEquals('sys_language_uid, l10n_parent, l10n_diffsource, title, --palette--;;1, type, something', ‪$GLOBALS['TCA']['sys_file_collection']['types']['my_type']['showitem']);
190 
191  $indexOfNewType = count(‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items']) - 1;
192 
193  // check if columns.type.item exist
194  self::assertEquals($type, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][1]);
195  self::assertEquals($label, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][0]);
196  }
197 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfTypeIsTooLong
‪registerFileCollectionClassThrowsExceptionIfTypeIsTooLong()
Definition: FileCollectionRegistryTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\addNewTypeToTCA
‪addNewTypeToTCA()
Definition: FileCollectionRegistryTest.php:167
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionExistsReturnsTrueForAllExistingFileCollections
‪fileCollectionExistsReturnsTrueForAllExistingFileCollections()
Definition: FileCollectionRegistryTest.php:142
‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
Definition: AbstractFileCollection.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionExistsReturnsFalseIfFileCollectionDoesNotExist
‪fileCollectionExistsReturnsFalseIfFileCollectionDoesNotExist()
Definition: FileCollectionRegistryTest.php:157
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\getFileCollectionClassAcceptsClassNameIfClassIsRegistered
‪getFileCollectionClassAcceptsClassNameIfClassIsRegistered()
Definition: FileCollectionRegistryTest.php:118
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\$testSubject
‪FileCollectionRegistry $testSubject
Definition: FileCollectionRegistryTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass
‪registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass()
Definition: FileCollectionRegistryTest.php:96
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfClassDoesNotExist
‪registerFileCollectionClassThrowsExceptionIfClassDoesNotExist()
Definition: FileCollectionRegistryTest.php:58
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\setUp
‪setUp()
Definition: FileCollectionRegistryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest
Definition: FileCollectionRegistryTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\getFileCollectionClassThrowsExceptionIfClassIsNotRegistered
‪getFileCollectionClassThrowsExceptionIfClassIsNotRegistered()
Definition: FileCollectionRegistryTest.php:107
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegistered
‪registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegistered()
Definition: FileCollectionRegistryTest.php:82
‪TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry
Definition: FileCollectionRegistry.php:25
‪TYPO3\CMS\Core\Resource\Collection\StaticFileCollection
Definition: StaticFileCollection.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionRegistryIsInitializedWithPreconfiguredFileCollections
‪fileCollectionRegistryIsInitializedWithPreconfiguredFileCollections()
Definition: FileCollectionRegistryTest.php:128
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:128
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\initializeTestSubject
‪initializeTestSubject()
Definition: FileCollectionRegistryTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registeredFileCollectionClassesCanBeRetrieved
‪registeredFileCollectionClassesCanBeRetrieved()
Definition: FileCollectionRegistryTest.php:47
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection
Definition: FileCollectionRegistryTest.php:18