Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 40... Línea 40...
40
 */
40
 */
41
class reopen_attempt_test extends externallib_advanced_testcase {
41
class reopen_attempt_test extends externallib_advanced_testcase {
42
    /** @var stdClass|null if we make a quiz attempt, we store the student object here. */
42
    /** @var stdClass|null if we make a quiz attempt, we store the student object here. */
43
    protected $student;
43
    protected $student;
Línea 44... Línea 44...
44
 
44
 
45
    public function test_reopen_attempt_service_works() {
45
    public function test_reopen_attempt_service_works(): void {
Línea 46... Línea 46...
46
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
46
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
Línea 47... Línea 47...
47
 
47
 
48
        reopen_attempt::execute($attemptid);
48
        reopen_attempt::execute($attemptid);
49
 
49
 
Línea 50... Línea 50...
50
        $attemptobj = quiz_attempt::create($attemptid);
50
        $attemptobj = quiz_attempt::create($attemptid);
51
        $this->assertEquals(quiz_attempt::IN_PROGRESS, $attemptobj->get_state());
51
        $this->assertEquals(quiz_attempt::IN_PROGRESS, $attemptobj->get_state());
Línea 52... Línea 52...
52
    }
52
    }
53
 
53
 
Línea 54... Línea 54...
54
    public function test_reopen_attempt_service_checks_permissions() {
54
    public function test_reopen_attempt_service_checks_permissions(): void {
55
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
55
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
56
 
56
 
Línea 57... Línea 57...
57
        $unprivilegeduser = $this->getDataGenerator()->create_user();
57
        $unprivilegeduser = $this->getDataGenerator()->create_user();
58
        $this->setUser($unprivilegeduser);
58
        $this->setUser($unprivilegeduser);
Línea 59... Línea 59...
59
 
59
 
60
        $this->expectException(required_capability_exception::class);
60
        $this->expectException(required_capability_exception::class);
61
        reopen_attempt::execute($attemptid);
61
        reopen_attempt::execute($attemptid);
Línea 62... Línea 62...
62
    }
62
    }
63
 
63
 
64
    public function test_reopen_attempt_service_checks_attempt_state() {
64
    public function test_reopen_attempt_service_checks_attempt_state(): void {
65
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question(quiz_attempt::IN_PROGRESS);
65
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question(quiz_attempt::IN_PROGRESS);
Línea 66... Línea 66...
66
 
66
 
Línea 78... Línea 78...
78
        $this->assertEquals('<p>This will reopen attempt 1 by ' . fullname($this->student) .
78
        $this->assertEquals('<p>This will reopen attempt 1 by ' . fullname($this->student) .
79
                '.</p><p>The attempt will remain open and can be continued.</p>',
79
                '.</p><p>The attempt will remain open and can be continued.</p>',
80
                $message);
80
                $message);
81
    }
81
    }
Línea 82... Línea 82...
82
 
82
 
83
    public function test_get_reopen_attempt_confirmation_staying_open_until() {
83
    public function test_get_reopen_attempt_confirmation_staying_open_until(): void {
84
        global $DB;
84
        global $DB;
85
        [$attemptid, $quizid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
85
        [$attemptid, $quizid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
86
        $timeclose = time() + HOURSECS;
86
        $timeclose = time() + HOURSECS;
Línea 92... Línea 92...
92
                '.</p><p>The attempt will remain open and can be continued until the quiz closes on ' .
92
                '.</p><p>The attempt will remain open and can be continued until the quiz closes on ' .
93
                userdate($timeclose) . '.</p>',
93
                userdate($timeclose) . '.</p>',
94
                $message);
94
                $message);
95
    }
95
    }
Línea 96... Línea 96...
96
 
96
 
97
    public function test_get_reopen_attempt_confirmation_submitting() {
97
    public function test_get_reopen_attempt_confirmation_submitting(): void {
98
        global $DB;
98
        global $DB;
99
        [$attemptid, $quizid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
99
        [$attemptid, $quizid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
100
        $timeclose = time() - HOURSECS;
100
        $timeclose = time() - HOURSECS;
Línea 105... Línea 105...
105
        $this->assertEquals('<p>This will reopen attempt 1 by ' . fullname($this->student) .
105
        $this->assertEquals('<p>This will reopen attempt 1 by ' . fullname($this->student) .
106
                '.</p><p>The attempt will be immediately submitted for grading.</p>',
106
                '.</p><p>The attempt will be immediately submitted for grading.</p>',
107
                $message);
107
                $message);
108
    }
108
    }
Línea 109... Línea 109...
109
 
109
 
110
    public function test_get_reopen_attempt_confirmation_service_checks_permissions() {
110
    public function test_get_reopen_attempt_confirmation_service_checks_permissions(): void {
Línea 111... Línea 111...
111
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
111
        [$attemptid] = $this->create_attempt_at_quiz_with_one_shortanswer_question();
112
 
112
 
Línea 113... Línea 113...
113
        $unprivilegeduser = $this->getDataGenerator()->create_user();
113
        $unprivilegeduser = $this->getDataGenerator()->create_user();
114
        $this->setUser($unprivilegeduser);
114
        $this->setUser($unprivilegeduser);
115
 
115
 
Línea 116... Línea 116...
116
        $this->expectException(required_capability_exception::class);
116
        $this->expectException(required_capability_exception::class);
117
        get_reopen_attempt_confirmation::execute($attemptid);
117
        get_reopen_attempt_confirmation::execute($attemptid);
Línea 118... Línea 118...
118
    }
118
    }
119
 
119
 
120
    public function test_get_reopen_attempt_confirmation_service_checks_attempt_state() {
120
    public function test_get_reopen_attempt_confirmation_service_checks_attempt_state(): void {