コード例 #1
0
 /**
  * @covers W3C\Validation\Result::addError
  * @covers W3C\Validation\Result::getErrors
  */
 public function testAddErrors()
 {
     $violation1 = new Violation();
     $violation2 = new Violation();
     $this->result->addError($violation1);
     $this->result->addError($violation2);
     $this->assertSame(array($violation1, $violation2), $this->result->getErrors());
 }
コード例 #2
0
ファイル: ResultTest.php プロジェクト: SysBind/saml2
 /**
  * @group response-validation
  * @test
  */
 public function the_result_correctly_reports_whether_or_not_it_is_valid()
 {
     $result = new Result();
     $this->assertTrue($result->isValid());
     $this->assertCount(0, $result->getErrors());
     $result->addError('Oh noooos!');
     $this->assertFalse($result->isValid());
     $this->assertCount(1, $result->getErrors());
 }
コード例 #3
0
 /**
  * Returns a result that represents the combination of the two given results.
  * In particular, this means:
  *
  * If $a->getErrors() is empty and $a->isValid() is true, $b is returned.
  * If $b->getErrors() is empty and $b->isValid() is true, $a is returned.
  *
  * Otherwise, a new Result is constructed that contains
  * all errors from $a and $b, and is considered valid
  * if both $a and $b were valid.
  *
  * @since 0.1
  *
  * @param Result $a
  * @param Result $b
  *
  * @return Result
  */
 public static function merge(Result $a, Result $b)
 {
     $aErrors = $a->getErrors();
     $bErrors = $b->getErrors();
     if ($a->isValid() && empty($aErrors)) {
         return $b;
     } elseif ($b->isValid() && empty($bErrors)) {
         return $a;
     } else {
         $errors = array_merge($aErrors, $bErrors);
         $valid = $a->isValid() && $b->isValid();
         return new Result($valid, $errors);
     }
 }
コード例 #4
0
ファイル: Output.php プロジェクト: mbrodala/PHP-Parallel-Lint
 /**
  * @param Result $result
  * @param ErrorFormatter $errorFormatter
  * @param bool $ignoreFails
  */
 public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
 {
     if ($this->checkedFiles % $this->filesPerLine !== 0) {
         $rest = $this->filesPerLine - $this->checkedFiles % $this->filesPerLine;
         $this->write(str_repeat(' ', $rest));
         $this->writeProgress();
     }
     $this->writeNewLine(2);
     $testTime = round($result->getTestTime(), 1);
     $message = "Checked {$result->getCheckedFilesCount()} files in {$testTime} ";
     $message .= $testTime == 1 ? 'second' : 'seconds';
     if ($result->getSkippedFilesCount() > 0) {
         $message .= ", skipped {$result->getSkippedFilesCount()} ";
         $message .= $result->getSkippedFilesCount() === 1 ? 'file' : 'files';
     }
     $this->writeLine($message);
     if (!$result->hasSyntaxError()) {
         $message = "No syntax error found";
     } else {
         $message = "Syntax error found in {$result->getFilesWithSyntaxErrorCount()} ";
         $message .= $result->getFilesWithSyntaxErrorCount() === 1 ? 'file' : 'files';
     }
     if ($result->hasFilesWithFail()) {
         $message .= ", failed to check {$result->getFilesWithFailCount()} ";
         $message .= $result->getFilesWithFailCount() === 1 ? 'file' : 'files';
         if ($ignoreFails) {
             $message .= ' (ignored)';
         }
     }
     $hasError = $ignoreFails ? $result->hasSyntaxError() : $result->hasError();
     $this->writeLine($message, $hasError ? self::TYPE_ERROR : self::TYPE_OK);
     if ($result->hasError()) {
         $this->writeNewLine();
         foreach ($result->getErrors() as $error) {
             $this->writeLine(str_repeat('-', 60));
             $this->writeLine($errorFormatter->format($error));
         }
     }
 }
コード例 #5
0
ファイル: Interpreter.php プロジェクト: g4z/poop
 /**
  * Handle output based on Environment and Options
  * @param Result $result Object derived from Result
  * @return Interpreter
  */
 public function doOutput(Result $result)
 {
     $this->debug(__METHOD__, __LINE__);
     if ($this->environment->isWeb()) {
         $json = json_encode($result->toArray());
         $this->stdout($json);
     } else {
         if ($result->hasErrors()) {
             foreach ($result->getErrors() as $error) {
                 $errstr = $this->outputFormatErrorMessage($error);
                 $this->stderr($errstr);
             }
             if ($result->isFail()) {
                 return;
             }
         }
         if ($buffer = trim($result->getOutput())) {
             $this->stdout($buffer . PHP_EOL);
         }
     }
 }
コード例 #6
0
 public function actionSave($id)
 {
     // Получаем куки для опроса
     /*
             define('COOKIE_NAME', 'poll_genplanmos_ru');
             $isCookie = isset(Yii::app()->request->cookies[COOKIE_NAME]->value);
             
             $pollCookie = $isCookie ? 
            Yii::app()->request->cookies[COOKIE_NAME] :  
            new CHttpCookie(COOKIE_NAME, ''); 
            
             $pollCookieValue = $isCookie? CJSON::decode($pollCookie->value) : array();
     * 
     */
     // Авторизован ли пользователь
     if (Yii::app()->user->isAuthenticated() === false) {
         $this->redirect(Yii::app()->user->loginUrl);
     }
     if (($user = Yii::app()->user->getProfile()) === null) {
         Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'User not found.'));
         Yii::app()->user->logout();
         $this->redirect((array) '/user/account/login');
     }
     $poll = Poll::model()->active()->with(array('questions' => array('scopes' => 'active')))->findByPK((int) $id);
     if (!$poll) {
         throw new CHttpException(404, Yii::t('PollModule.poll', 'Страница не найдена'));
     }
     // Поиск результата
     $result = Result::model()->find('t.user_id = :user_id AND t.poll_id = :poll_id', array(':user_id' => $user->id, ':poll_id' => $poll->id));
     if ($result !== null) {
         throw new CHttpException(403, Yii::t('PollModule.poll', 'Вы уже проходили данный опрос'));
     }
     $result = new Result();
     $result->user_id = $user->id;
     $result->poll_id = $poll->id;
     // Обработка результата
     if (($data = Yii::app()->getRequest()->getPost('question')) !== null) {
         // Формирование списка ответов
         $answers = array();
         foreach ($poll->questions as $question) {
             $formValue = isset($data[$question->id]) ? $data[$question->id] : null;
             switch ($question->type) {
                 case Question::TYPE_VARIANT:
                     $answer = new Answer();
                     $answer->question_id = $question->id;
                     $answer->variant_id = $formValue !== null ? (int) $formValue : $formValue;
                     $answers[] = $answer;
                     break;
                 case Question::TYPE_MULTIPLE:
                     // Просматриваем полученные ответы
                     if (!isset($formValue) || !is_array($formValue)) {
                         break;
                     }
                     foreach ($formValue as $value) {
                         $answer = new Answer();
                         $answer->question_id = $question->id;
                         $answer->variant_id = (int) $value;
                         $answers[] = $answer;
                     }
                     break;
                 default:
                     $answer = new Answer();
                     $answer->question_id = $question->id;
                     $answer->value = $formValue !== null ? $formValue : '';
                     $answers[] = $answer;
                     break;
             }
             $result->answers = $answers;
         }
         if ($result->validate()) {
             $result->save();
             Yii::app()->ajax->success(array('html' => $this->widget('application.modules.poll.widgets.PollWidget', array('model_id' => $poll->id), true)));
         } else {
             Yii::app()->ajax->failure(array('message' => '', 'errors' => $result->getErrors()));
         }
     }
 }