예제 #1
0
 /**
  * @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());
 }
 /**
  * @param Result $result
  * @return array
  */
 protected function getErrorMessages(Result $result)
 {
     $messages = array();
     /** @var Error $error */
     foreach ($result->getErrors() as $error) {
         $messages[] = htmlspecialchars(LocalizationUtility::translate('formError.' . $error->getCode(), 'BiMarketplace') ?: $error->getMessage());
     }
     return $messages;
 }
 /**
  * Add errors and set validstate to false
  *
  * @param Result $result
  * @return void
  */
 protected function addErrors(Result $result)
 {
     $errors = $result->getErrors();
     if (!empty($errors)) {
         /** @var Error $error */
         foreach ($errors as $error) {
             $this->addError($error->getMessage(), $error->getCode());
         }
         $this->setValidState(false);
     }
 }