コード例 #1
0
 /**
  * Test that ValidationException can be created with both a ValidationResult
  * and a custom message
  */
 public function testCreateWithComplexValidationResultAndMessage()
 {
     $result = new ValidationResult();
     $result->error('A spork is not a knife')->error('A knife is not a back scratcher');
     $exception = new ValidationException($result, 'An error has occurred', E_USER_WARNING);
     $this->assertEquals(E_USER_WARNING, $exception->getCode());
     $this->assertEquals('An error has occurred', $exception->getMessage());
     $this->assertEquals(false, $exception->getResult()->valid());
     $this->assertEquals('A spork is not a knife; A knife is not a back scratcher', $exception->getResult()->message());
 }
コード例 #2
0
 /**
  * Generate a response object for a form validation error
  *
  * @param Form $form The source form
  * @param ValidationException $e The validation error message
  * @return SS_HTTPResponse
  * @throws SS_HTTPResponse_Exception
  */
 protected function generateValidationResponse($form, $e)
 {
     $controller = $this->getToplevelController();
     $form->sessionMessage($e->getResult()->message(), 'bad', false);
     $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) {
         return $form->forTemplate();
     }, 'default' => function () use(&$controller) {
         return $controller->redirectBack();
     }));
     if ($controller->getRequest()->isAjax()) {
         $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm');
     }
     return $responseNegotiator->respond($controller->getRequest());
 }