示例#1
0
 public function testValidation()
 {
     $this->request->setParameter('str1', 'test');
     $this->request->setParameter('str2', 'てすとです。ほげほげ');
     $this->request->setActionMethod("doLogin");
     $this->actionChain->add('teeple_test_action');
     $this->actionChain->execute();
     $errors = $this->request->getAllErrorMessages();
     $this->assertEqual(2, count($errors));
     $this->assertEqual("値1は10文字以上5文字以下で入力してください。", $errors[0]);
     $this->assertEqual("文字列2の長さが間違ってるで。", $errors[1]);
     $this->assertEqual("result/validateError", $this->response->getView());
     // executeメソッドにはValidationは実行されない。
     $this->actionChain->clear();
     $this->actionChain->add('teeple_test_action');
     $this->request->setActionMethod('execute');
     $this->request->resetErrorMessages();
     $this->request->setFilterError(NULL);
     $this->actionChain->execute();
     $errors = $this->request->getAllErrorMessages();
     $this->assertEqual(0, count($errors));
     $this->assertEqual('result/execute', $this->response->getView());
 }
示例#2
0
 /**
  * バリデーションを実行します。
  *
  * @param Teeple_ActionBase $action
  * @param string $methodName
  */
 private function doValidation($action, $methodName)
 {
     $className = get_class($action);
     if (!defined($className . "::VALIDATION_CONFIG")) {
         return;
     }
     if (defined($className . "::VALIDATION_TARGET")) {
         $targets = explode(',', constant($className . "::VALIDATION_TARGET"));
         array_walk($targets, 'trim');
         if (!in_array($methodName, $targets)) {
             $this->log->info("メソッド{$methodName}はValidation対象ではありません。");
             return;
         }
     }
     $validationConfig = $this->validatorManager->parseYAML(constant($className . "::VALIDATION_CONFIG"));
     if (!$this->validatorManager->execute($action, $validationConfig)) {
         $this->request->setFilterError('Validate');
     }
     return;
 }