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();
|
||||
@@ -377,6 +395,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();
|
||||
@@ -419,6 +439,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();
|
||||
@@ -445,6 +467,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();
|
||||
|
||||
@@ -500,6 +525,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();
|
||||
@@ -516,6 +544,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();
|
||||
@@ -533,6 +564,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();
|
||||
@@ -608,6 +642,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;
|
||||
@@ -674,6 +709,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;
|
||||
@@ -744,6 +781,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();
|
||||
@@ -808,6 +848,9 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$c->internal_set_data($cm, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::get_progress_all
|
||||
*/
|
||||
public function test_get_progress_all_few() {
|
||||
global $DB;
|
||||
$this->mock_setup();
|
||||
@@ -842,6 +885,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();
|
||||
@@ -897,6 +943,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();
|
||||
|
||||
@@ -965,6 +1014,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();
|
||||
|
||||
@@ -1007,6 +1059,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();
|
||||
@@ -1048,6 +1103,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();
|
||||
@@ -1073,7 +1131,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;
|
||||
@@ -1110,6 +1169,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;
|
||||
@@ -1147,6 +1208,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;
|
||||
@@ -1176,6 +1239,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();
|
||||
@@ -1202,6 +1267,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();
|
||||
@@ -1228,6 +1295,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();
|
||||
|
||||
@@ -1263,6 +1333,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) {
|
||||
@@ -1295,6 +1366,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;
|
||||
|
||||
Reference in New Issue
Block a user