Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Workshop activity-related unit tests for Completion Progress block.
19
 *
20
 * @package    block_completion_progress
21
 * @copyright  2020 Jonathon Fowler <fowlerj@usq.edu.au>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace block_completion_progress;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
global $CFG;
30
require_once($CFG->dirroot.'/mod/workshop/locallib.php');
31
require_once($CFG->dirroot.'/mod/workshop/tests/fixtures/testable.php');
32
 
33
use block_completion_progress\completion_progress;
34
use block_completion_progress\defaults;
35
 
36
/**
37
 * Workshop activity-related unit tests for Completion Progress block.
38
 *
39
 * @package    block_completion_progress
40
 * @copyright  2020 Jonathon Fowler <fowlerj@usq.edu.au>
41
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class workshop_completion_test extends \block_completion_progress\tests\completion_testcase {
44
    /**
45
     * Test completion determination in a Workshop activity with pass/fail enabled.
46
     * @covers \block_completion_progress\completion_progress
47
     */
48
    public function test_workshop_passfail() {
49
        $this->setAdminUser();
50
 
51
        $generator = $this->getDataGenerator();
52
 
53
        $instance = $generator->create_module('workshop', [
54
            'course' => $this->course->id,
55
            'grade' => 80,
56
            'gradinggrade' => 20,
57
            'completion' => COMPLETION_TRACKING_AUTOMATIC,
58
            'completionusegrade' => 1,      // The student must receive a grade to complete.
59
            'completionexpected' => time() - DAYSECS,
60
        ]);
61
        $cm = get_coursemodule_from_id('workshop', $instance->cmid);
62
 
63
        // Set the passing grades for submission and assessment.
64
        $item = \grade_item::fetch(['courseid' => $this->course->id, 'itemtype' => 'mod',
65
            'itemmodule' => 'workshop', 'iteminstance' => $instance->id, 'itemnumber' => 0,
66
            'outcomeid' => null]);
67
        $item->gradepass = 40;
68
        $item->update();
69
 
70
        $workshop = new \testable_workshop($instance, $cm, $this->course);
71
 
72
        // Student 1 submits to the activity and gets graded correct.
73
        $student1 = $generator->create_and_enrol($this->course, 'student');
74
        $this->assert_progress_completion($student1, $cm, COMPLETION_INCOMPLETE);
75
        $submission1 = $this->submit_for_student($student1, $workshop);
76
        $this->assert_progress_completion($student1, $cm, 'submitted');
77
        $this->grade_submission($submission1, $workshop, 75);      // Pass.
78
        $this->assert_progress_completion($student1, $cm, 'submitted');
79
        $workshop->switch_phase(\testable_workshop::PHASE_CLOSED);
80
        $this->assert_progress_completion($student1, $cm, COMPLETION_COMPLETE_PASS);
81
 
82
        // Student 2 submits to the activity and gets graded incorrect.
83
        $student2 = $generator->create_and_enrol($this->course, 'student');
84
        $this->assert_progress_completion($student2, $cm, COMPLETION_INCOMPLETE);
85
        $submission2 = $this->submit_for_student($student2, $workshop);
86
        $this->assert_progress_completion($student2, $cm, 'submitted');
87
        $this->grade_submission($submission2, $workshop, 25);      // Fail.
88
        $this->assert_progress_completion($student2, $cm, 'submitted');
89
        $workshop->switch_phase(\testable_workshop::PHASE_CLOSED);
90
        $this->assert_progress_completion($student2, $cm, COMPLETION_COMPLETE_FAIL);
91
    }
92
 
93
    /**
94
     * Test completion determination in an Workshop activity with basic completion.
95
     * @covers \block_completion_progress\completion_progress
96
     */
97
    public function test_workshop_basic() {
98
        $this->setAdminUser();
99
 
100
        $generator = $this->getDataGenerator();
101
 
102
        $instance = $generator->create_module('workshop', [
103
            'course' => $this->course->id,
104
            'grade' => 80,
105
            'gradinggrade' => 20,
106
            'completion' => COMPLETION_TRACKING_AUTOMATIC,
107
            'completionusegrade' => 1,      // The student must receive a grade to complete.
108
            'completionexpected' => time() - DAYSECS,
109
        ]);
110
        $cm = get_coursemodule_from_id('workshop', $instance->cmid);
111
 
112
        $workshop = new \testable_workshop($instance, $cm, $this->course);
113
 
114
        // Student 1 submits to the activity and gets graded correctly.
115
        $student1 = $generator->create_and_enrol($this->course, 'student');
116
        $this->assert_progress_completion($student1, $cm, COMPLETION_INCOMPLETE);
117
        $submission1 = $this->submit_for_student($student1, $workshop);
118
        $this->assert_progress_completion($student1, $cm, 'submitted');
119
        $this->grade_submission($submission1, $workshop, 75);      // Pass.
120
        $this->assert_progress_completion($student1, $cm, 'submitted');
121
        $workshop->switch_phase(\testable_workshop::PHASE_CLOSED);
122
        $this->assert_progress_completion($student1, $cm, COMPLETION_COMPLETE);
123
 
124
        // Student 2 submits to the activity and gets graded incorrectly.
125
        $student2 = $generator->create_and_enrol($this->course, 'student');
126
        $this->assert_progress_completion($student2, $cm, COMPLETION_INCOMPLETE);
127
        $submission2 = $this->submit_for_student($student2, $workshop);
128
        $this->assert_progress_completion($student2, $cm, 'submitted');
129
        $this->grade_submission($submission2, $workshop, 25);      // Fail.
130
        $this->assert_progress_completion($student2, $cm, 'submitted');
131
        $workshop->switch_phase(\testable_workshop::PHASE_CLOSED);
132
        $this->assert_progress_completion($student2, $cm, COMPLETION_COMPLETE);
133
    }
134
 
135
    /**
136
     * Make a submission for a student.
137
     *
138
     * @param object $student
139
     * @param object $workshop
140
     * @return object
141
     */
142
    protected function submit_for_student($student, $workshop) {
143
        global $DB;
144
 
145
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
146
 
147
        $id = $generator->create_submission($workshop->id, $student->id, array(
148
            'title' => 'Submission',
149
        ));
150
        return $DB->get_record('workshop_submissions', ['id' => $id]);
151
    }
152
 
153
    /**
154
     * Award a grade to a submission.
155
     *
156
     * @param object $submission
157
     * @param object $workshop
158
     * @param integer $grade
159
     * @return object
160
     */
161
    protected function grade_submission($submission, $workshop, $grade) {
162
        $workshop->aggregate_submission_grades_process([
163
            (object)['submissionid' => $submission->id, 'submissiongrade' => null,
164
                'weight' => 1, 'grade' => $grade],
165
        ]);
166
    }
167
}