MDL-72246 core_completion: Test coverage improvements for completion
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?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/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Coverage information for the core_completion.
|
||||
*
|
||||
* @package core
|
||||
* @category phpunit
|
||||
* @copyright 2022 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Coverage information for the core subsystem.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
return new class extends phpunit_coverage_info {
|
||||
/** @var array The list of folders relative to the plugin root to include in coverage generation. */
|
||||
protected $includelistfolders = [
|
||||
'criteria',
|
||||
];
|
||||
|
||||
/** @var array The list of files relative to the plugin root to include in coverage generation. */
|
||||
protected $includelistfiles = [
|
||||
'completion_aggregation.php',
|
||||
'completion_completion.php',
|
||||
'completion_criteria_completion.php',
|
||||
'data_object.php'
|
||||
];
|
||||
};
|
||||
@@ -29,7 +29,17 @@ defined('MOODLE_INTERNAL') || die();
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
class core_completionlib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Completion tests.
|
||||
*
|
||||
* @package core_completion
|
||||
* @category phpunit
|
||||
* @copyright 2008 Sam Marshall
|
||||
* @copyright 2013 Frédéric Massart
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \completion_info
|
||||
*/
|
||||
class completionlib_test extends advanced_testcase {
|
||||
protected $course;
|
||||
protected $user;
|
||||
protected $module1;
|
||||
@@ -90,6 +100,10 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::is_enabled_for_site
|
||||
* @covers ::is_enabled
|
||||
*/
|
||||
public function test_is_enabled() {
|
||||
global $CFG;
|
||||
$this->mock_setup();
|
||||
@@ -125,6 +139,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(COMPLETION_TRACKING_AUTOMATIC, $c->is_enabled($cm));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::update_state
|
||||
*/
|
||||
public function test_update_state() {
|
||||
$this->mock_setup();
|
||||
|
||||
@@ -348,6 +365,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* @param int $completionusegrade
|
||||
* @param string $unsetfield
|
||||
* @param int $expectedstate
|
||||
* @covers ::internal_get_state
|
||||
*/
|
||||
public function test_internal_get_state(int $completionview, int $completionusegrade, string $unsetfield, int $expectedstate) {
|
||||
$this->setup_data();
|
||||
@@ -379,6 +397,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* Provider for the test_internal_get_state_with_grade_criteria.
|
||||
*
|
||||
* @return array
|
||||
* @covers ::internal_get_state
|
||||
*/
|
||||
public function test_internal_get_state_with_grade_criteria_provider() {
|
||||
return [
|
||||
@@ -432,6 +451,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* @param array $completioncriteria The completion criteria to use
|
||||
* @param int|null $studentgrade Grade to assign to student
|
||||
* @param int $expectedstate Expected completion state
|
||||
* @covers ::internal_get_state
|
||||
*/
|
||||
public function test_internal_get_state_with_grade_criteria(array $completioncriteria, ?int $studentgrade, int $expectedstate) {
|
||||
$this->setup_data();
|
||||
@@ -472,6 +492,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Covers the case where internal_get_state() is being called for a user different from the logged in user.
|
||||
*
|
||||
* @covers ::internal_get_state
|
||||
*/
|
||||
public function test_internal_get_state_with_different_user() {
|
||||
$this->setup_data();
|
||||
@@ -514,6 +536,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for internal_get_state() for an activity that supports custom completion.
|
||||
*
|
||||
* @covers ::internal_get_state
|
||||
*/
|
||||
public function test_internal_get_state_with_custom_completion() {
|
||||
$this->setup_data();
|
||||
@@ -540,6 +564,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(COMPLETION_COMPLETE, $completion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::set_module_viewed
|
||||
*/
|
||||
public function test_set_module_viewed() {
|
||||
$this->mock_setup();
|
||||
|
||||
@@ -595,6 +622,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$c->set_module_viewed($cm, 1337);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::count_user_data
|
||||
*/
|
||||
public function test_count_user_data() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -611,6 +641,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(666, $c->count_user_data($cm));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::delete_all_state
|
||||
*/
|
||||
public function test_delete_all_state() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -628,6 +661,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$c->delete_all_state($cm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::reset_all_state
|
||||
*/
|
||||
public function test_reset_all_state() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -703,6 +739,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* @param bool $sameuser Whether the user calling get_data() is the user itself.
|
||||
* @param bool $hasrecord Whether to create a course_modules_completion record.
|
||||
* @param int $completion The completion state expected.
|
||||
* @covers ::get_data
|
||||
*/
|
||||
public function test_get_data(bool $wholecourse, bool $sameuser, bool $hasrecord, int $completion) {
|
||||
global $DB;
|
||||
@@ -769,6 +806,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Tests for completion_info::get_other_cm_completion_data().
|
||||
*
|
||||
* @covers ::get_other_cm_completion_data
|
||||
*/
|
||||
public function test_get_other_cm_completion_data() {
|
||||
global $DB;
|
||||
@@ -842,6 +881,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEmpty($choice2completiondata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::internal_set_data
|
||||
*/
|
||||
public function test_internal_set_data() {
|
||||
global $DB;
|
||||
$this->setup_data();
|
||||
@@ -938,6 +980,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals($this->user->id, reset($actual)->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_progress_all
|
||||
*/
|
||||
public function test_get_progress_all_few() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -972,6 +1017,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
), $c->get_progress_all(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_progress_all
|
||||
*/
|
||||
public function test_get_progress_all_lots() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -1027,6 +1075,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertCount(count($tracked), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::inform_grade_changed
|
||||
*/
|
||||
public function test_inform_grade_changed() {
|
||||
$this->mock_setup();
|
||||
|
||||
@@ -1095,6 +1146,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$c->inform_grade_changed($cm, $item, $grade, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::internal_get_grade_state
|
||||
*/
|
||||
public function test_internal_get_grade_state() {
|
||||
$this->mock_setup();
|
||||
|
||||
@@ -1137,6 +1191,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
completion_info::internal_get_grade_state($item, $grade));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test ::get_activities
|
||||
*/
|
||||
public function test_get_activities() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
@@ -1178,6 +1235,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertFalse(isset($activities[$data2->cmid]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test ::has_activities
|
||||
*/
|
||||
public function test_has_activities() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
@@ -1203,7 +1263,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test that data is cleaned up when we delete courses that are set as completion criteria for other courses
|
||||
*
|
||||
* @return void
|
||||
* @covers ::delete_course_completion_data
|
||||
* @covers ::delete_all_completion_data
|
||||
*/
|
||||
public function test_course_delete_prerequisite() {
|
||||
global $DB;
|
||||
@@ -1240,6 +1301,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test course module completion update event.
|
||||
*
|
||||
* @covers \core\event\course_module_completion_updated
|
||||
*/
|
||||
public function test_course_module_completion_updated_event() {
|
||||
global $USER, $CFG;
|
||||
@@ -1277,6 +1340,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test course completed event.
|
||||
*
|
||||
* @covers \core\event\course_completed
|
||||
*/
|
||||
public function test_course_completed_event() {
|
||||
global $USER;
|
||||
@@ -1306,6 +1371,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test course completed message.
|
||||
*
|
||||
* @covers \core\event\course_completed
|
||||
*/
|
||||
public function test_course_completed_message() {
|
||||
$this->setup_data();
|
||||
@@ -1332,6 +1399,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test course completed event.
|
||||
*
|
||||
* @covers \core\event\course_completion_updated
|
||||
*/
|
||||
public function test_course_completion_updated_event() {
|
||||
$this->setup_data();
|
||||
@@ -1358,6 +1427,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertEventLegacyLogData($expectedlegacylog, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \completion_can_view_data
|
||||
*/
|
||||
public function test_completion_can_view_data() {
|
||||
$this->setup_data();
|
||||
|
||||
@@ -1393,6 +1465,7 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
* @param int|null $passinggrade Passing grade to set for the test activity.
|
||||
* @param string|null $expectedexception Expected exception.
|
||||
* @param int|null $expectedresult The expected completion status.
|
||||
* @covers ::get_grade_completion
|
||||
*/
|
||||
public function test_get_grade_completion(bool $completionusegrade, bool $hasgrade, ?int $passinggrade,
|
||||
?string $expectedexception, ?int $expectedresult) {
|
||||
@@ -1425,6 +1498,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the return value for cases when the activity module does not have associated grade_item.
|
||||
*
|
||||
* @covers ::get_grade_completion
|
||||
*/
|
||||
public function test_get_grade_completion_without_grade_item() {
|
||||
global $DB;
|
||||
@@ -1463,6 +1538,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for aggregate_completions().
|
||||
*
|
||||
* @covers \aggregate_completions
|
||||
*/
|
||||
public function test_aggregate_completions() {
|
||||
global $DB;
|
||||
@@ -1557,6 +1634,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for completion_completion::_save().
|
||||
*
|
||||
* @covers \completion_completion::_save
|
||||
*/
|
||||
public function test_save() {
|
||||
global $DB;
|
||||
@@ -1601,6 +1680,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for completion_completion::mark_enrolled().
|
||||
*
|
||||
* @covers \completion_completion::mark_enrolled
|
||||
*/
|
||||
public function test_mark_enrolled() {
|
||||
global $DB;
|
||||
@@ -1642,6 +1723,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for completion_completion::mark_inprogress().
|
||||
*
|
||||
* @covers \completion_completion::mark_inprogress
|
||||
*/
|
||||
public function test_mark_inprogress() {
|
||||
global $DB;
|
||||
@@ -1683,6 +1766,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for completion_completion::mark_complete().
|
||||
*
|
||||
* @covers \completion_completion::mark_complete
|
||||
*/
|
||||
public function test_mark_complete() {
|
||||
global $DB;
|
||||
@@ -1723,6 +1808,8 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test for completion_criteria_completion::mark_complete().
|
||||
*
|
||||
* @covers \completion_criteria_completion::mark_complete
|
||||
*/
|
||||
public function test_criteria_mark_complete() {
|
||||
global $DB;
|
||||
|
||||
Reference in New Issue
Block a user