TYPO3 CMS  TYPO3_7-6
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 
22 
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->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1440601540);
53  $this->subject->compile($input);
54  }
55 
60  {
61  $input = [
62  'command' => 'unknownCommand',
63  ];
64  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437653136);
65  $this->subject->compile($input);
66  }
67 
72  {
73  $input = [
74  'tableName' => '',
75  ];
76  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654409);
77  $this->subject->compile($input);
78  }
79 
84  {
85  $input = [
86  'vanillaUid' => 'foo123',
87  ];
88  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654247);
89  $this->subject->compile($input);
90  }
91 
96  {
97  $input = [
98  'command' => 'edit',
99  'vanillaUid' => -100,
100  ];
101  $this->setExpectedException(\InvalidArgumentException::class, $this->anything(), 1437654332);
102  $this->subject->compile($input);
103  }
104 
109  {
110  $input = [
111  'tableName' => 'pages',
112  'vanillaUid' => 123,
113  'command' => 'edit',
114  ];
115  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturnArgument(0);
116  $result = $this->subject->compile($input);
117  $this->assertEquals('pages', $result['tableName']);
118  $this->assertEquals(123, $result['vanillaUid']);
119  $this->assertEquals('edit', $result['command']);
120  }
121 
126  {
127  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
128  $result = $arguments[0];
129  $result['databaseRow'] = 'newData';
130  return $result;
131  });
132  $result = $this->subject->compile([]);
133  $this->assertEquals('newData', $result['databaseRow']);
134  }
135 
140  {
141  $this->formDataGroupProphecy->compile(Argument::cetera())->willReturn(null);
142  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1446664764);
143  $this->subject->compile([]);
144  }
145 
150  {
151  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
152  $result = $arguments[0];
153  unset($result['tableName']);
154  return $result;
155  });
156  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
157  $this->subject->compile([]);
158  }
159 
164  {
165  $this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
166  $result = $arguments[0];
167  $result['newKey'] = 'newData';
168  return $result;
169  });
170  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438079402);
171  $this->subject->compile([]);
172  }
173 }