TYPO3 CMS  TYPO3_7-6
TcaGroupTest.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 
24 
29 {
33  protected $subject;
34 
39 
40  protected function setUp()
41  {
42  $this->subject = new TcaGroup();
43  $this->singletonInstances = GeneralUtility::getSingletonInstances();
44  }
45 
46  protected function tearDown()
47  {
48  GeneralUtility::resetSingletonInstances($this->singletonInstances);
49  parent::tearDown();
50  }
51 
56  {
57  $input = [
58  'databaseRow' => [
59  'aField' => 'aValue',
60  ],
61  'processedTca' => [
62  'columns' => [
63  'aField' => [
64  'config' => [
65  'type' => 'foo',
66  ],
67  ],
68  ],
69  ],
70  ];
71  $expected = $input;
72  $this->assertSame($expected, $this->subject->addData($input));
73  }
74 
79  {
80  $input = [
81  'processedTca' => [
82  'columns' => [
83  'aField' => [
84  'config' => [
85  'type' => 'group',
86  'internal_type' => 'foo',
87  ],
88  ],
89  ],
90  ],
91  ];
92  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438780511);
93  $this->subject->addData($input);
94  }
95 
99  public function addDataSetsFileData()
100  {
101  $input = [
102  'databaseRow' => [
103  'aField' => '/aDir/aFile.txt,/anotherDir/anotherFile.css',
104  ],
105  'processedTca' => [
106  'columns' => [
107  'aField' => [
108  'config' => [
109  'type' => 'group',
110  'internal_type' => 'file',
111  ],
112  ],
113  ],
114  ],
115  ];
116  $expected = $input;
117  $expected['databaseRow']['aField'] = '%2FaDir%2FaFile.txt|aFile.txt,%2FanotherDir%2FanotherFile.css|anotherFile.css';
118  $this->assertSame($expected, $this->subject->addData($input));
119  }
120 
124  public function addDataSetsFolderData()
125  {
126  $input = [
127  'databaseRow' => [
128  'aField' => '1:/aFolder/anotherFolder/',
129  ],
130  'processedTca' => [
131  'columns' => [
132  'aField' => [
133  'config' => [
134  'type' => 'group',
135  'internal_type' => 'folder',
136  ],
137  ],
138  ],
139  ],
140  ];
141 
143  $folderProphecy = $this->prophesize(Folder::class);
144  $folderProphecy->getIdentifier()->shouldBeCalled()->willReturn('anotherFolder');
145 
147  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
148  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
149  $resourceFactoryProphecy->retrieveFileOrFolderObject('1:/aFolder/anotherFolder/')
150  ->shouldBeCalled()
151  ->willReturn($folderProphecy->reveal());
152 
153  $expected = $input;
154  $expected['databaseRow']['aField'] = '1%3A%2FaFolder%2FanotherFolder%2F|anotherFolder';
155  $this->assertSame($expected, $this->subject->addData($input));
156  }
157 
161  public function addDataSetsDatabaseData()
162  {
163  $aFieldConfig = [
164  'type' => 'group',
165  'internal_type' => 'db',
166  'MM' => 'mmTableName',
167  'allowed' => 'aForeignTable',
168  ];
169  $input = [
170  'tableName' => 'aTable',
171  'databaseRow' => [
172  'uid' => 42,
173  'aField' => '1,2',
174  ],
175  'processedTca' => [
176  'columns' => [
177  'aField' => [
178  'config' => $aFieldConfig,
179  ],
180  ],
181  ],
182  ];
183 
185  $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
186  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
187  $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled();
188  $relationHandlerProphecy->getFromDB()->shouldBeCalled();
189  $relationHandlerProphecy->readyForInterface()->shouldBeCalled()->willReturn('1|aLabel,2|anotherLabel');
190 
191  $expected = $input;
192  $expected['databaseRow']['aField'] = '1|aLabel,2|anotherLabel';
193 
194  $this->assertSame($expected, $this->subject->addData($input));
195  }
196 }
static addInstance($className, $instance)
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)