TYPO3  7.6
TcaGroupTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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 
17 
18 use Prophecy\Prophecy\ObjectProphecy;
20 use TYPO3\CMS\Core\Tests\UnitTestCase;
23 
27 class TcaGroupTest extends UnitTestCase
28 {
32  protected $subject;
33 
34  protected function setUp()
35  {
36  $this->subject = new TcaGroup();
37  }
38 
43  {
44  $input = [
45  'databaseRow' => [
46  'aField' => 'aValue',
47  ],
48  'processedTca' => [
49  'columns' => [
50  'aField' => [
51  'config' => [
52  'type' => 'foo',
53  ],
54  ],
55  ],
56  ],
57  ];
58  $expected = $input;
59  $this->assertSame($expected, $this->subject->addData($input));
60  }
61 
66  {
67  $input = [
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => [
72  'type' => 'group',
73  'internal_type' => 'foo',
74  ],
75  ],
76  ],
77  ],
78  ];
79  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438780511);
80  $this->subject->addData($input);
81  }
82 
86  public function addDataSetsFileData()
87  {
88  $input = [
89  'databaseRow' => [
90  'aField' => '/aDir/aFile.txt,/anotherDir/anotherFile.css',
91  ],
92  'processedTca' => [
93  'columns' => [
94  'aField' => [
95  'config' => [
96  'type' => 'group',
97  'internal_type' => 'file',
98  ],
99  ],
100  ],
101  ],
102  ];
103  $expected = $input;
104  $expected['databaseRow']['aField'] = '%2FaDir%2FaFile.txt|aFile.txt,%2FanotherDir%2FanotherFile.css|anotherFile.css';
105  $this->assertSame($expected, $this->subject->addData($input));
106  }
107 
111  public function addDataSetsDatabaseData()
112  {
113  $aFieldConfig = [
114  'type' => 'group',
115  'internal_type' => 'db',
116  'MM' => 'mmTableName',
117  'allowed' => 'aForeignTable',
118  ];
119  $input = [
120  'tableName' => 'aTable',
121  'databaseRow' => [
122  'uid' => 42,
123  'aField' => '1,2',
124  ],
125  'processedTca' => [
126  'columns' => [
127  'aField' => [
128  'config' => $aFieldConfig,
129  ],
130  ],
131  ],
132  ];
133 
135  $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
136  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
137  $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled();
138  $relationHandlerProphecy->getFromDB()->shouldBeCalled();
139  $relationHandlerProphecy->readyForInterface()->shouldBeCalled()->willReturn('1|aLabel,2|anotherLabel');
140 
141  $expected = $input;
142  $expected['databaseRow']['aField'] = '1|aLabel,2|anotherLabel';
143 
144  $this->assertSame($expected, $this->subject->addData($input));
145  }
146 }