TYPO3 CMS  TYPO3_8-7
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 
21 
25 class FormDataCompilerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
30  protected $subject;
31 
36 
37  protected function setUp()
38  {
39  $this->formDataGroupProphecy = $this->prophesize(FormDataGroupInterface::class);
40  $this->subject = new FormDataCompiler($this->formDataGroupProphecy->reveal());
41  }
42 
47  {
48  $input = [
49  'foo' => 'bar',
50  ];
51  $this->expectException(\InvalidArgumentException::class);
52  $this->expectExceptionCode(1440601540);
53  $this->subject->compile($input);
54  }
55 
60  {
61  $input = [
62  'command' => 'unknownCommand',
63  ];
64  $this->expectException(\InvalidArgumentException::class);
65  $this->expectExceptionCode(1437653136);
66  $this->subject->compile($input);
67  }
68 
73  {
74  $input = [
75  'tableName' => '',
76  ];
77  $this->expectException(\InvalidArgumentException::class);
78  $this->expectExceptionCode(1437654409);
79  $this->subject->compile($input);
80  }
81 
86  {
87  $input = [
88  'vanillaUid' => 'foo123',
89  ];
90  $this->expectException(\InvalidArgumentException::class);
91  $this->expectExceptionCode(1437654247);
92  $this->subject->compile($input);
93  }
94 
99  {
100  $input = [
101  'command' => 'edit',
102  'vanillaUid' => -100,
103  ];
104  $this->expectException(\InvalidArgumentException::class);
105  $this->expectExceptionCode(1437654332);
106  $this->subject->compile($input);
107  }
108 
113  {
114  $input = [
115  'tableName' => 'pages',
116  'vanillaUid' => 123,
117  'command' => 'edit',
118  ];
119  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
120  $result = $this->subject->compile($input);
121  $this->assertEquals('pages', $result['tableName']);
122  $this->assertEquals(123, $result['vanillaUid']);
123  $this->assertEquals('edit', $result['command']);
124  }
125 
130  {
131  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
132  $result = $arguments[0];
133  $result['databaseRow'] = 'newData';
134  return $result;
135  });
136  $result = $this->subject->compile([]);
137  $this->assertEquals('newData', $result['databaseRow']);
138  }
139 
144  {
145  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn(null);
146  $this->expectException(\UnexpectedValueException::class);
147  $this->expectExceptionCode(1446664764);
148  $this->subject->compile([]);
149  }
150 
155  {
156  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn([
157  'renderData' => [ 'foo' ],
158  ]);
159  $this->expectException(\RuntimeException::class);
160  $this->expectExceptionCode(1485201279);
161  $this->subject->compile([]);
162  }
163 
168  {
169  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
170  $result = $arguments[0];
171  unset($result['tableName']);
172  return $result;
173  });
174  $this->expectException(\UnexpectedValueException::class);
175  $this->expectExceptionCode(1438079402);
176  $this->subject->compile([]);
177  }
178 
183  {
184  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
185  $result = $arguments[0];
186  $result['newKey'] = 'newData';
187  return $result;
188  });
189  $this->expectException(\UnexpectedValueException::class);
190  $this->expectExceptionCode(1438079402);
191  $this->subject->compile([]);
192  }
193 }