-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CTP-4028 Fix: get_type_name() null when formative
Previously assess_type::get_type_name() would return null for modules set to ASSESS_TYPE_FORMATIVE.
- Loading branch information
Showing
2 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace local_assess_type; | ||
|
||
/** | ||
* PHPUnit tests for local_assess_type. | ||
* | ||
* @package local_assess_type | ||
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Leon Stringer <[email protected]> | ||
*/ | ||
class assess_type_test extends \advanced_testcase { | ||
/** | ||
* Test strings returned by assess_type::get_type_name() are the expected | ||
* values. | ||
* @dataProvider assess_type_strings | ||
* @param int $assesstype ASSESS_TYPE_FORMATIVE, ASSESS_TYPE_SUMMATIVE, | ||
* etc. | ||
* @param string $name "Formative", "Summative", etc. | ||
*/ | ||
public final function test_get_type_name(int $assesstype, string $name) { | ||
$this->resetAfterTest(true); | ||
|
||
// Make a course. | ||
$course = $this->getDataGenerator()->create_course(); | ||
|
||
// Make a quiz and add it to the course. | ||
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz'); | ||
$quiz = $quizgenerator->create_instance(['course' => $course->id, 'questionsperpage' => 0, | ||
'grade' => 100.0, 'sumgrades' => 2, 'preferredbehaviour' => 'immediatefeedback']); | ||
|
||
$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id); | ||
assess_type::update_type($course->id, $assesstype, $cm->id); | ||
$this->assertEquals(assess_type::get_type_name($cm->id), $name); | ||
|
||
} | ||
|
||
/** | ||
* Data provider. | ||
*/ | ||
public static final function assess_type_strings(): array { | ||
return [ | ||
'formative' => [ | ||
'assess_type' => assess_type::ASSESS_TYPE_FORMATIVE, | ||
'name' => get_string('formative', 'local_assess_type'), | ||
], | ||
'summative' => [ | ||
'assess_type' => assess_type::ASSESS_TYPE_SUMMATIVE, | ||
'name' => get_string('summative', 'local_assess_type'), | ||
], | ||
'dummy' => [ | ||
'assess_type' => assess_type::ASSESS_TYPE_DUMMY, | ||
'name' => get_string('dummy', 'local_assess_type'), | ||
], | ||
]; | ||
} | ||
} |