/** * @test */ public function findFirstError() { /* * Root * - A * - B * - C (With Error) */ $rootResult = new \TYPO3\CMS\Extbase\Error\Result(); $rootResult->forProperty('A'); $rootResult->forProperty('B')->forProperty('C')->addError(new \TYPO3\CMS\Extbase\Error\Error('Fehler', 123456)); $foundError = $this->controller->_call('findFirstError', $rootResult); /** @var \TYPO3\CMS\Extbase\Error\Error $foundError */ $this->assertInstanceOf('\\TYPO3\\CMS\\Extbase\\Error\\Error', $foundError); $this->assertEquals(123456, $foundError->getCode()); }
/** * @test */ public function mergeShouldMergeTwoResults() { $notice1 = $this->getMockMessage('Notice'); $notice2 = $this->getMockMessage('Notice'); $notice3 = $this->getMockMessage('Notice'); $warning1 = $this->getMockMessage('Warning'); $warning2 = $this->getMockMessage('Warning'); $warning3 = $this->getMockMessage('Warning'); $error1 = $this->getMockMessage('Error'); $error2 = $this->getMockMessage('Error'); $error3 = $this->getMockMessage('Error'); $otherResult = new \TYPO3\CMS\Extbase\Error\Result(); $otherResult->addNotice($notice1); $otherResult->forProperty('foo.bar')->addNotice($notice2); $this->result->forProperty('foo')->addNotice($notice3); $otherResult->addWarning($warning1); $this->result->addWarning($warning2); $this->result->addWarning($warning3); $otherResult->forProperty('foo')->addError($error1); $otherResult->forProperty('foo')->addError($error2); $otherResult->addError($error3); $this->result->merge($otherResult); $this->assertSame(array($notice1), $this->result->getNotices(), 'Notices are not merged correctly without recursion'); $this->assertSame(array($notice3), $this->result->forProperty('foo')->getNotices(), 'Original sub-notices are overridden.'); $this->assertSame(array($notice2), $this->result->forProperty('foo')->forProperty('bar')->getNotices(), 'Sub-notices are not copied.'); $this->assertSame(array($warning2, $warning3, $warning1), $this->result->getWarnings()); $this->assertSame(array($error3), $this->result->getErrors()); $this->assertSame(array($error1, $error2), $this->result->forProperty('foo')->getErrors()); }
/** * Get all property mapping / validation errors * * @return \TYPO3\CMS\Extbase\Error\Result */ public function getValidationResults() { $results = new \TYPO3\CMS\Extbase\Error\Result(); /** @var Argument $argument */ foreach ($this as $argument) { $argumentValidationResults = $argument->getValidationResults(); if ($argumentValidationResults === null) { continue; } $results->forProperty($argument->getName())->merge($argumentValidationResults); } return $results; }
/** * Validate object * * @param mixed $object * * @throws \TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException * @throws \InvalidArgumentException * @return boolean|\TYPO3\CMS\Extbase\Error\Result */ public function validate($object) { $messages = new \TYPO3\CMS\Extbase\Error\Result(); if (self::$instancesCurrentlyUnderValidation === null) { self::$instancesCurrentlyUnderValidation = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); } if ($object === null) { return $messages; } if (!$this->canValidate($object)) { /** @var \TYPO3\CMS\Extbase\Error\Error $error */ $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Error\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notvalidatable', 'StoreFinder'), 1301599551); $messages->addError($error); return $messages; } if (self::$instancesCurrentlyUnderValidation->contains($object)) { return $messages; } else { self::$instancesCurrentlyUnderValidation->attach($object); } $this->model = $object; $propertyValidators = $this->getValidationRulesFromSettings(); foreach ($propertyValidators as $propertyName => $validatorsNames) { if (!property_exists($object, $propertyName)) { /** @var \TYPO3\CMS\Extbase\Error\Error $error */ $error = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Error\\Error', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('error_notexists', 'StoreFinder'), 1301599575); $messages->addError($error); } else { $this->currentPropertyName = $propertyName; $propertyValue = $this->getPropertyValue($object, $propertyName); $this->checkProperty($propertyValue, (array) $validatorsNames, $messages->forProperty($propertyName)); } } self::$instancesCurrentlyUnderValidation->detach($object); return $messages; }