‪TYPO3CMS  10.4
FormDataCompilerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪FormDataCompilerTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
38 
39  protected function ‪setUp(): void
40  {
41  $this->formDataGroupProphecy = $this->prophesize(FormDataGroupInterface::class);
42  $this->subject = new ‪FormDataCompiler($this->formDataGroupProphecy->reveal());
43  }
44 
49  {
50  $input = [
51  'foo' => 'bar',
52  ];
53  $this->expectException(\InvalidArgumentException::class);
54  $this->expectExceptionCode(1440601540);
55  $this->subject->compile($input);
56  }
57 
62  {
63  $input = [
64  'command' => 'unknownCommand',
65  ];
66  $this->expectException(\InvalidArgumentException::class);
67  $this->expectExceptionCode(1437653136);
68  $this->subject->compile($input);
69  }
70 
75  {
76  $input = [
77  'tableName' => '',
78  ];
79  $this->expectException(\InvalidArgumentException::class);
80  $this->expectExceptionCode(1437654409);
81  $this->subject->compile($input);
82  }
83 
88  {
89  $input = [
90  'vanillaUid' => 'foo123',
91  ];
92  $this->expectException(\InvalidArgumentException::class);
93  $this->expectExceptionCode(1437654247);
94  $this->subject->compile($input);
95  }
96 
101  {
102  $input = [
103  'command' => 'edit',
104  'vanillaUid' => -100,
105  ];
106  $this->expectException(\InvalidArgumentException::class);
107  $this->expectExceptionCode(1437654332);
108  $this->subject->compile($input);
109  }
110 
115  {
116  $input = [
117  'tableName' => 'pages',
118  'vanillaUid' => 123,
119  'command' => 'edit',
120  ];
121  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
122  $result = $this->subject->compile($input);
123  self::assertEquals('pages', $result['tableName']);
124  self::assertEquals(123, $result['vanillaUid']);
125  self::assertEquals('edit', $result['command']);
126  }
127 
132  {
133  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
134  $result = $arguments[0];
135  $result['databaseRow'] = 'newData';
136  return $result;
137  });
138  $result = $this->subject->compile([]);
139  self::assertEquals('newData', $result['databaseRow']);
140  }
141 
146  {
147  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn(null);
148  $this->expectException(\UnexpectedValueException::class);
149  $this->expectExceptionCode(1446664764);
150  $this->subject->compile([]);
151  }
152 
157  {
158  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn([
159  'renderData' => [ 'foo' ],
160  ]);
161  $this->expectException(\RuntimeException::class);
162  $this->expectExceptionCode(1485201279);
163  $this->subject->compile([]);
164  }
165 
170  {
171  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
172  $result = $arguments[0];
173  unset($result['tableName']);
174  return $result;
175  });
176  $this->expectException(\UnexpectedValueException::class);
177  $this->expectExceptionCode(1438079402);
178  $this->subject->compile([]);
179  }
180 
185  {
186  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
187  $result = $arguments[0];
188  $result['newKey'] = 'newData';
189  return $result;
190  });
191  $this->expectException(\UnexpectedValueException::class);
192  $this->expectExceptionCode(1438079402);
193  $this->subject->compile([]);
194  }
195 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileReturnsResultArrayWithInputDataSet
‪compileReturnsResultArrayWithInputDataSet()
Definition: FormDataCompilerTest.php:112
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray
‪compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray()
Definition: FormDataCompilerTest.php:167
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfInputContainsKeysNotValidInResult
‪compileThrowsExceptionIfInputContainsKeysNotValidInResult()
Definition: FormDataCompilerTest.php:46
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfCommandIsEditAndUidIsNegative
‪compileThrowsExceptionIfCommandIsEditAndUidIsNegative()
Definition: FormDataCompilerTest.php:98
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\setUp
‪setUp()
Definition: FormDataCompilerTest.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfUidIsNotAnInteger
‪compileThrowsExceptionIfUidIsNotAnInteger()
Definition: FormDataCompilerTest.php:85
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileReturnsResultArrayWithAdditionalDataFormFormDataGroup
‪compileReturnsResultArrayWithAdditionalDataFormFormDataGroup()
Definition: FormDataCompilerTest.php:129
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfRenderDataIsNotEmpty
‪compileThrowsExceptionIfRenderDataIsNotEmpty()
Definition: FormDataCompilerTest.php:154
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupDoesNotReturnArray
‪compileThrowsExceptionIfFormDataGroupDoesNotReturnArray()
Definition: FormDataCompilerTest.php:143
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray
‪compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray()
Definition: FormDataCompilerTest.php:182
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionIfNoTableNameGiven
‪compileThrowsExceptionIfNoTableNameGiven()
Definition: FormDataCompilerTest.php:72
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\compileThrowsExceptionAtUnknownCommand
‪compileThrowsExceptionAtUnknownCommand()
Definition: FormDataCompilerTest.php:59
‪TYPO3\CMS\Backend\Form\FormDataGroupInterface
Definition: FormDataGroupInterface.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\$formDataGroupProphecy
‪FormDataGroupInterface ObjectProphecy $formDataGroupProphecy
Definition: FormDataCompilerTest.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest\$subject
‪FormDataCompiler $subject
Definition: FormDataCompilerTest.php:31
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataCompilerTest
Definition: FormDataCompilerTest.php:28