コード例 #1
0
ファイル: rule_test.php プロジェクト: EmmanuelYupit/educursos
 public function test_close_date_with_overdue()
 {
     $quiz = new stdClass();
     $quiz->timeopen = 0;
     $quiz->timeclose = 20000;
     $quiz->overduehandling = 'graceperiod';
     $quiz->graceperiod = 1000;
     $quiz->questions = '';
     $cm = new stdClass();
     $cm->id = 0;
     $quizobj = new quiz($quiz, $cm, null);
     $attempt = new stdClass();
     $attempt->preview = 0;
     $rule = new quizaccess_openclosedate($quizobj, 20000);
     $this->assertFalse($rule->prevent_access());
     $rule = new quizaccess_openclosedate($quizobj, 20001);
     $this->assertFalse($rule->prevent_access());
     $rule = new quizaccess_openclosedate($quizobj, 21000);
     $this->assertFalse($rule->prevent_access());
     $rule = new quizaccess_openclosedate($quizobj, 21001);
     $this->assertEquals($rule->prevent_access(), get_string('notavailable', 'quizaccess_openclosedate'));
 }
コード例 #2
0
ファイル: testrule.php プロジェクト: nutanrajmalanai/moodle
    public function test_both_dates() {
        $quiz = new stdClass();
        $quiz->timeopen = 10000;
        $quiz->timeclose = 20000;
        $quiz->questions = '';
        $cm = new stdClass();
        $cm->id = 0;
        $quizobj = new quiz($quiz, $cm, null);
        $attempt = new stdClass();
        $attempt->preview = 0;

        $rule = new quizaccess_openclosedate($quizobj, 9999);
        $this->assertEqual($rule->description(),
                array(get_string('quiznotavailable', 'quizaccess_openclosedate', userdate(10000))));
        $this->assertEqual($rule->prevent_access(),
                get_string('notavailable', 'quizaccess_openclosedate'));
        $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
        $this->assertFalse($rule->is_finished(0, $attempt));

        $rule = new quizaccess_openclosedate($quizobj, 10000);
        $this->assertEqual($rule->description(),
                array(get_string('quizopenedon', 'quiz', userdate(10000)),
                get_string('quizcloseson', 'quiz', userdate(20000))));
        $this->assertFalse($rule->prevent_access());
        $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
        $this->assertFalse($rule->is_finished(0, $attempt));

        $rule = new quizaccess_openclosedate($quizobj, 20000);
        $this->assertEqual($rule->description(),
                array(get_string('quizopenedon', 'quiz', userdate(10000)),
                get_string('quizcloseson', 'quiz', userdate(20000))));
        $this->assertFalse($rule->prevent_access());
        $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
        $this->assertFalse($rule->is_finished(0, $attempt));

        $rule = new quizaccess_openclosedate($quizobj, 20001);
        $this->assertEqual($rule->description(),
                array(get_string('quizclosed', 'quiz', userdate(20000))));
        $this->assertEqual($rule->prevent_access(),
                get_string('notavailable', 'quizaccess_openclosedate'));
        $this->assertFalse($rule->prevent_new_attempt(0, $attempt));
        $this->assertTrue($rule->is_finished(0, $attempt));

        $this->assertFalse($rule->time_left($attempt, 20000 - QUIZ_SHOW_TIME_BEFORE_DEADLINE));
        $this->assertEqual($rule->time_left($attempt, 19900), 100);
        $this->assertEqual($rule->time_left($attempt, 20000), 0);
        $this->assertEqual($rule->time_left($attempt, 20100), -100);
    }