Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 34... Línea 34...
34
 *
34
 *
35
 * @package   mod_lesson
35
 * @package   mod_lesson
36
 * @copyright 2021 Michael Hawkins <michaelh@moodle.com>
36
 * @copyright 2021 Michael Hawkins <michaelh@moodle.com>
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
38
 */
39
class custom_completion_test extends advanced_testcase {
39
final class custom_completion_test extends advanced_testcase {
Línea 40... Línea 40...
40
 
40
 
41
    /**
41
    /**
42
     * Data provider for get_state().
42
     * Data provider for get_state().
43
     *
43
     *
44
     * @return array[]
44
     * @return array[]
45
     */
45
     */
46
    public function get_state_provider(): array {
46
    public static function get_state_provider(): array {
47
        return [
47
        return [
48
            'Undefined completion requirement' => [
48
            'Undefined completion requirement' => [
49
                'somenonexistentrule', COMPLETION_ENABLED, 3, null, coding_exception::class
49
                'somenonexistentrule', COMPLETION_ENABLED, 3, null, coding_exception::class
50
            ],
50
            ],
Línea 64... Línea 64...
64
                'completiontimespent', 30, 40, COMPLETION_COMPLETE, null
64
                'completiontimespent', 30, 40, COMPLETION_COMPLETE, null
65
            ],
65
            ],
66
            'User must reach end of lesson, has not met completion requirement' => [
66
            'User must reach end of lesson, has not met completion requirement' => [
67
                'completionendreached', 1, false, COMPLETION_INCOMPLETE, null
67
                'completionendreached', 1, false, COMPLETION_INCOMPLETE, null
68
            ],
68
            ],
69
            'User must reach end of lesson, has not met completion requirement' => [
69
            'User must reach end of lesson, has met completion requirement' => [
70
                'completionendreached', 1, true, COMPLETION_COMPLETE, null
70
                'completionendreached', 1, true, COMPLETION_COMPLETE, null
71
            ],
71
            ],
72
        ];
72
        ];
73
    }
73
    }
Línea 80... Línea 80...
80
     * @param int $rulevalue The custom completion rule value.
80
     * @param int $rulevalue The custom completion rule value.
81
     * @param mixed $uservalue The database value returned when checking the rule for the user.
81
     * @param mixed $uservalue The database value returned when checking the rule for the user.
82
     * @param int|null $status Expected completion status for the rule.
82
     * @param int|null $status Expected completion status for the rule.
83
     * @param string|null $exception Expected exception.
83
     * @param string|null $exception Expected exception.
84
     */
84
     */
85
    public function test_get_state(string $rule, int $rulevalue, $uservalue, ?int $status, ?string $exception) {
85
    public function test_get_state(string $rule, int $rulevalue, $uservalue, ?int $status, ?string $exception): void {
86
        global $DB;
86
        global $DB;
Línea 87... Línea 87...
87
 
87
 
88
        if (!is_null($exception)) {
88
        if (!is_null($exception)) {
89
            $this->expectException($exception);
89
            $this->expectException($exception);
Línea 131... Línea 131...
131
    }
131
    }
Línea 132... Línea 132...
132
 
132
 
133
    /**
133
    /**
134
     * Test for get_defined_custom_rules().
134
     * Test for get_defined_custom_rules().
135
     */
135
     */
136
    public function test_get_defined_custom_rules() {
136
    public function test_get_defined_custom_rules(): void {
137
        $expectedrules = [
137
        $expectedrules = [
138
            'completiontimespent',
138
            'completiontimespent',
139
            'completionendreached',
139
            'completionendreached',
Línea 148... Línea 148...
148
    }
148
    }
Línea 149... Línea 149...
149
 
149
 
150
    /**
150
    /**
151
     * Test for get_defined_custom_rule_descriptions().
151
     * Test for get_defined_custom_rule_descriptions().
152
     */
152
     */
153
    public function test_get_custom_rule_descriptions() {
153
    public function test_get_custom_rule_descriptions(): void {
154
        // Get defined custom rules.
154
        // Get defined custom rules.
Línea 155... Línea 155...
155
        $rules = custom_completion::get_defined_custom_rules();
155
        $rules = custom_completion::get_defined_custom_rules();
156
 
156
 
Línea 174... Línea 174...
174
    }
174
    }
Línea 175... Línea 175...
175
 
175
 
176
    /**
176
    /**
177
     * Test for is_defined().
177
     * Test for is_defined().
178
     */
178
     */
179
    public function test_is_defined() {
179
    public function test_is_defined(): void {
180
        // Build a mock cm_info instance.
180
        // Build a mock cm_info instance.
181
        $mockcminfo = $this->getMockBuilder(cm_info::class)
181
        $mockcminfo = $this->getMockBuilder(cm_info::class)
182
            ->disableOriginalConstructor()
182
            ->disableOriginalConstructor()
Línea 195... Línea 195...
195
    /**
195
    /**
196
     * Data provider for test_get_available_custom_rules().
196
     * Data provider for test_get_available_custom_rules().
197
     *
197
     *
198
     * @return array[]
198
     * @return array[]
199
     */
199
     */
200
    public function get_available_custom_rules_provider(): array {
200
    public static function get_available_custom_rules_provider(): array {
201
        return [
201
        return [
202
            'No completion conditions enabled' => [
202
            'No completion conditions enabled' => [
203
                [
203
                [
204
                    'completiontimespent' => COMPLETION_DISABLED,
204
                    'completiontimespent' => COMPLETION_DISABLED,
205
                    'completionendreached' => COMPLETION_DISABLED,
205
                    'completionendreached' => COMPLETION_DISABLED,
Línea 235... Línea 235...
235
     *
235
     *
236
     * @dataProvider get_available_custom_rules_provider
236
     * @dataProvider get_available_custom_rules_provider
237
     * @param array $completionrulesvalues
237
     * @param array $completionrulesvalues
238
     * @param array $expected
238
     * @param array $expected
239
     */
239
     */
240
    public function test_get_available_custom_rules(array $completionrulesvalues, array $expected) {
240
    public function test_get_available_custom_rules(array $completionrulesvalues, array $expected): void {
241
        $customcompletionrules = [
241
        $customcompletionrules = [
242
            'customcompletionrules' => $completionrulesvalues,
242
            'customcompletionrules' => $completionrulesvalues,
243
        ];
243
        ];
Línea 244... Línea 244...
244
 
244