TYPO3 CMS  TYPO3_7-6
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 
54  {
55  $this->testSubject->registerFileCollectionClass($this->getUniqueId(), substr($this->getUniqueId(), 0, 30));
56  }
57 
64  {
65  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
66  $type = str_pad('', 40);
67  $this->testSubject->registerFileCollectionClass($className, $type);
68  }
69 
76  {
77  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
78  $className2 = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\StaticFileCollection::class));
79  $this->testSubject->registerFileCollectionClass($className, 'foobar');
80  $this->testSubject->registerFileCollectionClass($className2, 'foobar');
81  }
82 
87  {
88  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
89  $className2 = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\StaticFileCollection::class));
90  $this->testSubject->registerFileCollectionClass($className, 'foobar');
91  $this->testSubject->registerFileCollectionClass($className2, 'foobar', true);
92  }
93 
100  {
101  $this->testSubject->getFileCollectionClass($this->getUniqueId());
102  }
103 
108  {
109  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
110  $this->testSubject->registerFileCollectionClass($className, 'foobar');
111  $this->assertEquals($className, $this->testSubject->getFileCollectionClass('foobar'));
112  }
113 
118  {
119  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
120  $type = substr($this->getUniqueId(), 0, 30);
121  $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
122  $type => $className
123  ];
124  $this->initializeTestSubject();
125  $this->assertEquals($className, $this->testSubject->getFileCollectionClass($type));
126  }
127 
132  {
133  $className = get_class($this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection::class));
134  $type = 'foo';
135  $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredCollections'] = [
136  $type => $className
137  ];
138  $this->initializeTestSubject();
139  $this->assertTrue($this->testSubject->fileCollectionTypeExists($type));
140  $this->assertFalse($this->testSubject->fileCollectionTypeExists('bar'));
141  }
142 
147  {
148  $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredFileCollections'] = [];
149  $this->initializeTestSubject();
150  $this->assertFalse($this->testSubject->fileCollectionTypeExists($this->getUniqueId()));
151  }
152 
156  public function addNewTypeToTCA()
157  {
158 
159  // Create a TCA fixture for sys_file_collection
160  $GLOBALS['TCA']['sys_file_collection'] = [
161  'types' => [
162  'typeB' => ['showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldD'],
163  ],
164  'columns' => [
165  'type' => [
166  'config' => [
167  'items' => ['Type B', 'typeB']
168  ]
169  ]
170  ]
171  ];
172 
173  $type = 'my_type';
174  $label = 'The Label';
175 
176  $this->testSubject->addTypeToTCA($type, $label, 'something');
177 
178  // check type
179  $this->assertEquals('sys_language_uid, l10n_parent, l10n_diffsource, title, --palette--;;1, type, something', $GLOBALS['TCA']['sys_file_collection']['types']['my_type']['showitem']);
180 
181  $indexOfNewType = count($GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items']) - 1;
182 
183  // check if columns.type.item exist
184  $this->assertEquals($type, $GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][1]);
185  $this->assertEquals($label, $GLOBALS['TCA']['sys_file_collection']['columns']['type']['config']['items'][$indexOfNewType][0]);
186  }
187 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']