‪TYPO3CMS  9.5
FormDataCompilerTest.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 
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪FormDataCompilerTest extends UnitTestCase
27 {
31  protected ‪$subject;
32 
37 
38  protected function ‪setUp()
39  {
40  $this->formDataGroupProphecy = $this->prophesize(FormDataGroupInterface::class);
41  $this->subject = new ‪FormDataCompiler($this->formDataGroupProphecy->reveal());
42  }
43 
48  {
49  $input = [
50  'foo' => 'bar',
51  ];
52  $this->expectException(\InvalidArgumentException::class);
53  $this->expectExceptionCode(1440601540);
54  $this->subject->compile($input);
55  }
56 
61  {
62  $input = [
63  'command' => 'unknownCommand',
64  ];
65  $this->expectException(\InvalidArgumentException::class);
66  $this->expectExceptionCode(1437653136);
67  $this->subject->compile($input);
68  }
69 
74  {
75  $input = [
76  'tableName' => '',
77  ];
78  $this->expectException(\InvalidArgumentException::class);
79  $this->expectExceptionCode(1437654409);
80  $this->subject->compile($input);
81  }
82 
87  {
88  $input = [
89  'vanillaUid' => 'foo123',
90  ];
91  $this->expectException(\InvalidArgumentException::class);
92  $this->expectExceptionCode(1437654247);
93  $this->subject->compile($input);
94  }
95 
100  {
101  $input = [
102  'command' => 'edit',
103  'vanillaUid' => -100,
104  ];
105  $this->expectException(\InvalidArgumentException::class);
106  $this->expectExceptionCode(1437654332);
107  $this->subject->compile($input);
108  }
109 
114  {
115  $input = [
116  'tableName' => 'pages',
117  'vanillaUid' => 123,
118  'command' => 'edit',
119  ];
120  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
121  $result = $this->subject->compile($input);
122  $this->assertEquals('pages', $result['tableName']);
123  $this->assertEquals(123, $result['vanillaUid']);
124  $this->assertEquals('edit', $result['command']);
125  }
126 
131  {
132  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
133  $result = $arguments[0];
134  $result['databaseRow'] = 'newData';
135  return $result;
136  });
137  $result = $this->subject->compile([]);
138  $this->assertEquals('newData', $result['databaseRow']);
139  }
140 
145  {
146  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn(null);
147  $this->expectException(\UnexpectedValueException::class);
148  $this->expectExceptionCode(1446664764);
149  $this->subject->compile([]);
150  }
151 
156  {
157  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn([
158  'renderData' => [ 'foo' ],
159  ]);
160  $this->expectException(\RuntimeException::class);
161  $this->expectExceptionCode(1485201279);
162  $this->subject->compile([]);
163  }
164 
169  {
170  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
171  $result = $arguments[0];
172  unset($result['tableName']);
173  return $result;
174  });
175  $this->expectException(\UnexpectedValueException::class);
176  $this->expectExceptionCode(1438079402);
177  $this->subject->compile([]);
178  }
179 
184  {
185  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
186  $result = $arguments[0];
187  $result['newKey'] = 'newData';
188  return $result;
189  });
190  $this->expectException(\UnexpectedValueException::class);
191  $this->expectExceptionCode(1438079402);
192  $this->subject->compile([]);
193  }
194 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileReturnsResultArrayWithInputDataSet
‪compileReturnsResultArrayWithInputDataSet()
Definition: FormDataCompilerTest.php:111
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray
‪compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray()
Definition: FormDataCompilerTest.php:166
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfInputContainsKeysNotValidInResult
‪compileThrowsExceptionIfInputContainsKeysNotValidInResult()
Definition: FormDataCompilerTest.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfCommandIsEditAndUidIsNegative
‪compileThrowsExceptionIfCommandIsEditAndUidIsNegative()
Definition: FormDataCompilerTest.php:97
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\setUp
‪setUp()
Definition: FormDataCompilerTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfUidIsNotAnInteger
‪compileThrowsExceptionIfUidIsNotAnInteger()
Definition: FormDataCompilerTest.php:84
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileReturnsResultArrayWithAdditionalDataFormFormDataGroup
‪compileReturnsResultArrayWithAdditionalDataFormFormDataGroup()
Definition: FormDataCompilerTest.php:128
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfRenderDataIsNotEmpty
‪compileThrowsExceptionIfRenderDataIsNotEmpty()
Definition: FormDataCompilerTest.php:153
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupDoesNotReturnArray
‪compileThrowsExceptionIfFormDataGroupDoesNotReturnArray()
Definition: FormDataCompilerTest.php:142
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray
‪compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray()
Definition: FormDataCompilerTest.php:181
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfNoTableNameGiven
‪compileThrowsExceptionIfNoTableNameGiven()
Definition: FormDataCompilerTest.php:71
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionAtUnknownCommand
‪compileThrowsExceptionAtUnknownCommand()
Definition: FormDataCompilerTest.php:58
‪TYPO3\CMS\Backend\Form\FormDataGroupInterface
Definition: FormDataGroupInterface.php:22
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\$formDataGroupProphecy
‪FormDataGroupInterface $formDataGroupProphecy
Definition: FormDataCompilerTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\$subject
‪FormDataCompiler $subject
Definition: FormDataCompilerTest.php:30
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest
Definition: FormDataCompilerTest.php:27