[TASK] Replace icon by IconFactory: actions-edit-restore-edit
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / DatabaseRowGroupRelationsTest.php
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;
19 use TYPO3\CMS\Core\Database\RelationHandler;
20 use TYPO3\CMS\Core\Tests\UnitTestCase;
21 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowGroupRelations;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Test case
26 */
27 class DatabaseRowGroupRelationsTest extends UnitTestCase {
28
29 /**
30 * @var DatabaseRowGroupRelations
31 */
32 protected $subject;
33
34 public function setUp() {
35 $this->subject = new DatabaseRowGroupRelations();
36 }
37
38 /**
39 * @test
40 */
41 public function addDataReturnsFieldUnchangedIfFieldIsNotTypeGroup() {
42 $input = [
43 'databaseRow' => [
44 'aField' => 'aValue',
45 ],
46 'vanillaTableTca' => [
47 'columns' => [
48 'aField' => [
49 'config' => [
50 'type' => 'foo',
51 ],
52 ],
53 ],
54 ],
55 ];
56 $expected = $input;
57 $this->assertSame($expected, $this->subject->addData($input));
58 }
59
60 /**
61 * @test
62 */
63 public function addDataThrowsExceptionWithTypeGroupAndNoValiInternalType() {
64 $input = [
65 'vanillaTableTca' => [
66 'columns' => [
67 'aField' => [
68 'config' => [
69 'type' => 'group',
70 'internal_type' => 'foo',
71 ],
72 ],
73 ],
74 ],
75 ];
76 $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438780511);
77 $this->subject->addData($input);
78 }
79
80 /**
81 * @test
82 */
83 public function addDataSetsFileData() {
84 $input = [
85 'databaseRow' => [
86 'aField' => '/aDir/aFile.txt,/anotherDir/anotherFile.css',
87 ],
88 'vanillaTableTca' => [
89 'columns' => [
90 'aField' => [
91 'config' => [
92 'type' => 'group',
93 'internal_type' => 'file',
94 ],
95 ],
96 ],
97 ],
98 ];
99 $expected = $input;
100 $expected['databaseRow']['aField'] = '%2FaDir%2FaFile.txt|aFile.txt,%2FanotherDir%2FanotherFile.css|anotherFile.css';
101 $this->assertSame($expected, $this->subject->addData($input));
102 }
103
104 /**
105 * @test
106 */
107 public function addDataSetsDatabaseData() {
108 $aFieldConfig = [
109 'type' => 'group',
110 'internal_type' => 'db',
111 'MM' => 'mmTableName',
112 'allowed' => 'aForeignTable',
113 ];
114 $input = [
115 'tableName' => 'aTable',
116 'databaseRow' => [
117 'uid' => 42,
118 'aField' => '1,2',
119 ],
120 'vanillaTableTca' => [
121 'columns' => [
122 'aField' => [
123 'config' => $aFieldConfig,
124 ],
125 ],
126 ],
127 ];
128
129 /** @var RelationHandler|ObjectProphecy $relationHandlerProphecy */
130 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
131 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
132 $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled();
133 $relationHandlerProphecy->getFromDB()->shouldBeCalled();
134 $relationHandlerProphecy->readyForInterface()->shouldBeCalled()->willReturn('1|aLabel,2|anotherLabel');
135
136 $expected = $input;
137 $expected['databaseRow']['aField'] = '1|aLabel,2|anotherLabel';
138
139 $this->assertSame($expected, $this->subject->addData($input));
140 }
141
142 }