‪TYPO3CMS  9.5
FileCollectionRegistryTest.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 
21 {
25  protected ‪$testSubject;
26 
27  protected function ‪setUp()
28  {
29  $this->‪initializeTestSubject();
30  }
31 
32  protected function ‪initializeTestSubject()
33  {
34  $this->testSubject = new \TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry();
35  }
36 
41  {
42  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
43  $this->testSubject->registerFileCollectionClass($className, 'foobar');
44  $returnedClassName = $this->testSubject->getFileCollectionClass('foobar');
45  $this->assertEquals($className, $returnedClassName);
46  }
47 
52  {
53  $this->expectException(\InvalidArgumentException::class);
54  $this->expectExceptionCode(1391295613);
55 
56  $this->testSubject->registerFileCollectionClass($this->getUniqueId(), substr($this->getUniqueId(), 0, 30));
57  }
58 
63  {
64  $this->expectException(\InvalidArgumentException::class);
65  $this->expectExceptionCode(1391295611);
66 
67  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
68  $type = str_pad('', 40);
69  $this->testSubject->registerFileCollectionClass($className, $type);
70  }
71 
76  {
77  $this->expectException(\InvalidArgumentException::class);
78  $this->expectExceptionCode(1391295643);
79 
80  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
81  $className2 = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\StaticFileCollection::class));
82  $this->testSubject->registerFileCollectionClass($className, 'foobar');
83  $this->testSubject->registerFileCollectionClass($className2, 'foobar');
84  }
85 
90  {
91  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
92  $className2 = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\StaticFileCollection::class));
93  $this->testSubject->registerFileCollectionClass($className, 'foobar');
94  $this->testSubject->registerFileCollectionClass($className2, 'foobar', true);
95  }
96 
101  {
102  $this->expectException(\InvalidArgumentException::class);
103  $this->expectExceptionCode(1391295644);
104 
105  $this->testSubject->getFileCollectionClass($this->getUniqueId());
106  }
107 
112  {
113  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
114  $this->testSubject->registerFileCollectionClass($className, 'foobar');
115  $this->assertEquals($className, $this->testSubject->getFileCollectionClass('foobar'));
116  }
117 
122  {
123  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
124  $type = substr($this->getUniqueId(), 0, 30);
125  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
126  $type => $className
127  ];
128  $this->‪initializeTestSubject();
129  $this->assertEquals($className, $this->testSubject->getFileCollectionClass($type));
130  }
131 
136  {
137  $className = get_class($this->getMockForAbstractClass(\‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
138  $type = 'foo';
139  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
140  $type => $className
141  ];
142  $this->‪initializeTestSubject();
143  $this->assertTrue($this->testSubject->fileCollectionTypeExists($type));
144  $this->assertFalse($this->testSubject->fileCollectionTypeExists('bar'));
145  }
146 
151  {
152  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredFileCollections'] = [];
153  $this->‪initializeTestSubject();
154  $this->assertFalse($this->testSubject->fileCollectionTypeExists($this->getUniqueId()));
155  }
156 
160  public function ‪addNewTypeToTCA()
161  {
162 
163  // Create a TCA fixture for sys_file_collection
164  ‪$GLOBALS['TCA']['sys_file_collection'] = [
165  'types' => [
166  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldD'],
167  ],
168  'columns' => [
169  'type' => [
170  'config' => [
171  'items' => ['Type B', 'typeB']
172  ]
173  ]
174  ]
175  ];
176 
177  $type = 'my_type';
178  $label = 'The Label';
179 
180  $this->testSubject->addTypeToTCA($type, $label, 'something');
181 
182  // check type
183  $this->assertEquals('sys_language_uid, l10n_parent, l10n_diffsource, title, --palette--;;1, type, something', ‪$GLOBALS['TCA']['sys_file_collection']['types']['my_type']['showitem']);
184 
185  $indexOfNewType = count(‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items']) - 1;
186 
187  // check if columns.type.item exist
188  $this->assertEquals($type, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][1]);
189  $this->assertEquals($label, ‪$GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][0]);
190  }
191 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfTypeIsTooLong
‪registerFileCollectionClassThrowsExceptionIfTypeIsTooLong()
Definition: FileCollectionRegistryTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\addNewTypeToTCA
‪addNewTypeToTCA()
Definition: FileCollectionRegistryTest.php:159
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionExistsReturnsTrueForAllExistingFileCollections
‪fileCollectionExistsReturnsTrueForAllExistingFileCollections()
Definition: FileCollectionRegistryTest.php:134
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionExistsReturnsFalseIfFileCollectionDoesNotExist
‪fileCollectionExistsReturnsFalseIfFileCollectionDoesNotExist()
Definition: FileCollectionRegistryTest.php:149
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\getFileCollectionClassAcceptsClassNameIfClassIsRegistered
‪getFileCollectionClassAcceptsClassNameIfClassIsRegistered()
Definition: FileCollectionRegistryTest.php:110
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass
‪registerFileCollectionClassOverridesExistingRegisteredFileCollectionClass()
Definition: FileCollectionRegistryTest.php:88
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfClassDoesNotExist
‪registerFileCollectionClassThrowsExceptionIfClassDoesNotExist()
Definition: FileCollectionRegistryTest.php:50
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\setUp
‪setUp()
Definition: FileCollectionRegistryTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest
Definition: FileCollectionRegistryTest.php:21
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\getFileCollectionClassThrowsExceptionIfClassIsNotRegistered
‪getFileCollectionClassThrowsExceptionIfClassIsNotRegistered()
Definition: FileCollectionRegistryTest.php:99
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\$testSubject
‪TYPO3 CMS Core Resource Collection FileCollectionRegistry $testSubject
Definition: FileCollectionRegistryTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegistered
‪registerFileCollectionClassThrowsExceptionIfTypeIsAlreadyRegistered()
Definition: FileCollectionRegistryTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\fileCollectionRegistryIsInitializedWithPreconfiguredFileCollections
‪fileCollectionRegistryIsInitializedWithPreconfiguredFileCollections()
Definition: FileCollectionRegistryTest.php:120
‪$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:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection\FileCollectionRegistryTest\registeredFileCollectionClassesCanBeRetrieved
‪registeredFileCollectionClassesCanBeRetrieved()
Definition: FileCollectionRegistryTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Resource\Collection
Definition: FileCollectionRegistryTest.php:2