17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 protected function setUp()
31 $this->result = new \TYPO3\CMS\Extbase\Error\Result();
41 [
'Warning',
'Warnings'],
52 return $this->createMock(
'TYPO3\\CMS\\Extbase\\Error\\' . $type);
64 $addMethodName =
'add' . $dataTypeInSingular;
65 $this->result->{$addMethodName}($message);
66 $getterMethodName =
'get' . $dataTypeInPlural;
67 $this->assertEquals([$message], $this->result->{$getterMethodName}());
76 public function getMessageShouldNotBeRecursive($dataTypeInSingular, $dataTypeInPlural)
78 $message = $this->getMockMessage($dataTypeInSingular);
79 $addMethodName =
'add' . $dataTypeInSingular;
80 $this->result->forProperty(
'foo')->{$addMethodName}($message);
81 $getterMethodName =
'get' . $dataTypeInPlural;
82 $this->assertEquals([], $this->result->{$getterMethodName}());
91 public function getFirstMessageShouldReturnFirstMessage($dataTypeInSingular, $dataTypeInPlural)
93 $message1 = $this->getMockMessage($dataTypeInSingular);
94 $message2 = $this->getMockMessage($dataTypeInSingular);
95 $addMethodName =
'add' . $dataTypeInSingular;
96 $this->result->{$addMethodName}($message1);
97 $this->result->{$addMethodName}($message2);
98 $getterMethodName =
'getFirst' . $dataTypeInSingular;
99 $this->assertSame($message1, $this->result->{$getterMethodName}());
105 public function forPropertyShouldReturnSubResult()
107 $container2 = $this->result->forProperty(
'foo.bar');
108 $this->assertInstanceOf(\
TYPO3\CMS\
Extbase\Error\Result::class, $container2);
109 $this->assertSame($container2, $this->result->forProperty(
'foo')->forProperty(
'bar'));
115 public function forPropertyWithEmptyStringShouldReturnSelf()
117 $container2 = $this->result->forProperty(
'');
118 $this->assertSame($container2, $this->result);
124 public function forPropertyWithNullShouldReturnSelf()
126 $container2 = $this->result->forProperty(
null);
127 $this->assertSame($container2, $this->result);
136 public function hasMessagesShouldReturnTrueIfTopLevelObjectHasMessages($dataTypeInSingular, $dataTypeInPlural)
138 $message = $this->getMockMessage($dataTypeInSingular);
139 $addMethodName =
'add' . $dataTypeInSingular;
140 $this->result->{$addMethodName}($message);
141 $methodName =
'has' . $dataTypeInPlural;
142 $this->assertTrue($this->result->{$methodName}());
151 public function hasMessagesShouldReturnTrueIfSubObjectHasErrors($dataTypeInSingular, $dataTypeInPlural)
153 $addMethodName =
'add' . $dataTypeInSingular;
154 $methodName =
'has' . $dataTypeInPlural;
155 $message = $this->getMockMessage($dataTypeInSingular);
156 $this->result->forProperty(
'foo.bar')->{$addMethodName}($message);
157 $this->assertTrue($this->result->{$methodName}());
166 public function hasMessagesShouldReturnFalseIfSubObjectHasNoErrors($dataTypeInSingular, $dataTypeInPlural)
168 $methodName =
'has' . $dataTypeInPlural;
169 $this->result->forProperty(
'foo.baz');
170 $this->result->forProperty(
'foo.bar');
171 $this->assertFalse($this->result->{$methodName}());
180 public function getFlattenedMessagesShouldReturnAllSubMessages($dataTypeInSingular, $dataTypeInPlural)
182 $message1 = $this->getMockMessage($dataTypeInSingular);
183 $message2 = $this->getMockMessage($dataTypeInSingular);
184 $message3 = $this->getMockMessage($dataTypeInSingular);
185 $message4 = $this->getMockMessage($dataTypeInSingular);
186 $message5 = $this->getMockMessage($dataTypeInSingular);
187 $addMethodName =
'add' . $dataTypeInSingular;
188 $this->result->forProperty(
'foo.bar')->{$addMethodName}($message1);
189 $this->result->forProperty(
'foo.baz')->{$addMethodName}($message2);
190 $this->result->forProperty(
'foo')->{$addMethodName}($message3);
191 $this->result->{$addMethodName}($message4);
192 $this->result->{$addMethodName}($message5);
193 $getMethodName =
'getFlattened' . $dataTypeInPlural;
195 '' => [$message4, $message5],
196 'foo' => [$message3],
197 'foo.bar' => [$message1],
198 'foo.baz' => [$message2]
200 $this->assertEquals($expected, $this->result->{$getMethodName}());
209 public function getFlattenedMessagesShouldNotContainEmptyResults($dataTypeInSingular, $dataTypeInPlural)
211 $message1 = $this->getMockMessage($dataTypeInSingular);
212 $message2 = $this->getMockMessage($dataTypeInSingular);
213 $addMethodName =
'add' . $dataTypeInSingular;
214 $this->result->forProperty(
'foo.bar')->{$addMethodName}($message1);
215 $this->result->forProperty(
'foo.baz')->{$addMethodName}($message2);
216 $getMethodName =
'getFlattened' . $dataTypeInPlural;
218 'foo.bar' => [$message1],
219 'foo.baz' => [$message2]
221 $this->assertEquals($expected, $this->result->{$getMethodName}());
227 public function mergeShouldMergeTwoResults()
229 $notice1 = $this->getMockMessage(
'Notice');
230 $notice2 = $this->getMockMessage(
'Notice');
231 $notice3 = $this->getMockMessage(
'Notice');
232 $warning1 = $this->getMockMessage(
'Warning');
233 $warning2 = $this->getMockMessage(
'Warning');
234 $warning3 = $this->getMockMessage(
'Warning');
235 $error1 = $this->getMockMessage(
'Error');
236 $error2 = $this->getMockMessage(
'Error');
237 $error3 = $this->getMockMessage(
'Error');
238 $otherResult = new \TYPO3\CMS\Extbase\Error\Result();
239 $otherResult->addNotice($notice1);
240 $otherResult->forProperty(
'foo.bar')->addNotice($notice2);
241 $this->result->forProperty(
'foo')->addNotice($notice3);
242 $otherResult->addWarning($warning1);
243 $this->result->addWarning($warning2);
244 $this->result->addWarning($warning3);
245 $otherResult->forProperty(
'foo')->addError($error1);
246 $otherResult->forProperty(
'foo')->addError($error2);
247 $otherResult->addError($error3);
248 $this->result->merge($otherResult);
249 $this->assertSame([$notice1], $this->result->getNotices(),
'Notices are not merged correctly without recursion');
250 $this->assertSame([$notice3], $this->result->forProperty(
'foo')->getNotices(),
'Original sub-notices are overridden.');
251 $this->assertSame([$notice2], $this->result->forProperty(
'foo')->forProperty(
'bar')->getNotices(),
'Sub-notices are not copied.');
252 $this->assertSame([$warning2, $warning3, $warning1], $this->result->getWarnings());
253 $this->assertSame([$error3], $this->result->getErrors());
254 $this->assertSame([$error1, $error2], $this->result->forProperty(
'foo')->getErrors());