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