‪TYPO3CMS  10.4
FileCollectionRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
28 {
32  protected ‪$testSubject;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->‪initializeTestSubject();
38  }
39 
40  protected function ‪initializeTestSubject()
41  {
42  $this->testSubject = new ‪FileCollectionRegistry();
43  }
44 
49  {
50  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
51  $this->testSubject->registerFileCollectionClass($className, 'foobar');
52  $returnedClassName = $this->testSubject->getFileCollectionClass('foobar');
53  self::assertEquals($className, $returnedClassName);
54  }
55 
60  {
61  $this->expectException(\InvalidArgumentException::class);
62  $this->expectExceptionCode(1391295613);
63 
64  $this->testSubject->registerFileCollectionClass(‪StringUtility::getUniqueId('class_'), substr(‪StringUtility::getUniqueId('type_'), 0, 30));
65  }
66 
71  {
72  $this->expectException(\InvalidArgumentException::class);
73  $this->expectExceptionCode(1391295611);
74 
75  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
76  $type = str_pad('', 40);
77  $this->testSubject->registerFileCollectionClass($className, $type);
78  }
79 
84  {
85  $this->expectException(\InvalidArgumentException::class);
86  $this->expectExceptionCode(1391295643);
87 
88  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
89  $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
90  $this->testSubject->registerFileCollectionClass($className, 'foobar');
91  $this->testSubject->registerFileCollectionClass($className2, 'foobar');
92  }
93 
98  {
99  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
100  $className2 = get_class($this->getMockForAbstractClass(StaticFileCollection::class));
101  $this->testSubject->registerFileCollectionClass($className, 'foobar');
102  $this->testSubject->registerFileCollectionClass($className2, 'foobar', true);
103  }
104 
109  {
110  $this->expectException(\InvalidArgumentException::class);
111  $this->expectExceptionCode(1391295644);
112 
113  $this->testSubject->getFileCollectionClass(‪StringUtility::getUniqueId());
114  }
115 
120  {
121  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
122  $this->testSubject->registerFileCollectionClass($className, 'foobar');
123  self::assertEquals($className, $this->testSubject->getFileCollectionClass('foobar'));
124  }
125 
130  {
131  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
132  $type = substr(‪StringUtility::getUniqueId('type_'), 0, 30);
133  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
134  $type => $className
135  ];
136  $this->‪initializeTestSubject();
137  self::assertEquals($className, $this->testSubject->getFileCollectionClass($type));
138  }
139 
144  {
145  $className = get_class($this->getMockForAbstractClass(AbstractFileCollection::class));
146  $type = 'foo';
147  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
148  $type => $className
149  ];
150  $this->‪initializeTestSubject();
151  self::assertTrue($this->testSubject->fileCollectionTypeExists($type));
152  self::assertFalse($this->testSubject->fileCollectionTypeExists('bar'));
153  }
154 
159  {
160  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredFileCollections'] = [];
161  $this->‪initializeTestSubject();
162  self::assertFalse($this->testSubject->fileCollectionTypeExists(‪StringUtility::getUniqueId('name_')));
163  }
164 
168  public function ‪addNewTypeToTCA()
169  {
170 
171  // Create a TCA fixture for sys_file_collection
172  ‪$GLOBALS['TCA']['sys_file_collection'] = [
173  'types' => [
174  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldD'],
175  ],
176  'columns' => [
177  'type' => [
178  'config' => [
179  'items' => ['Type B', 'typeB']
180  ]
181  ]
182  ]
183  ];
184 
185  $type = 'my_type';
186  $label = 'The Label';
187 
188  $this->testSubject->addTypeToTCA($type, $label, 'something');
189 
190  // check type
191  self::assertEquals('sys_language_uid, l10n_parent, l10n_diffsource, title, --palette--;;1, type, something', ‪$GLOBALS['TCA']['sys_file_collection']['types']['my_type']['showitem']);
192 
193  $indexOfNewType = count(‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items']) - 1;
194 
195  // check if columns.type.item exist
196  self::assertEquals($type, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][1]);
197  self::assertEquals($label, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][0]);
198  }
199 }
‪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:27
‪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\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:29
‪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:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\getFileCollectionClassThrowsExceptionIfClassIsNotRegistered
‪getFileCollectionClassThrowsExceptionIfClassIsNotRegistered()
Definition: FileCollectionRegistryTest.php:107
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\$testSubject
‪TYPO3 CMS Core Resource Collection FileCollectionRegistry $testSubject
Definition: FileCollectionRegistryTest.php:31
‪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:92
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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:16