MDL-80866 phpunit: Fix failures after disabling Chat and Survey

This commit is contained in:
Sara Arjona 2024-02-26 16:59:50 +01:00
parent 0b3b739370
commit b2e5f3e746
No known key found for this signature in database
19 changed files with 129 additions and 11 deletions

View File

@ -344,7 +344,7 @@ class helper_test extends \advanced_testcase {
],
'plugins' => [
'assign' => 1,
'chat' => 1,
'book' => 1,
'data' => 1,
'lesson' => 1,
],

View File

@ -58,7 +58,7 @@ class externallib_test extends externallib_advanced_testcase {
$generator->enrol_user($student->id, $course->id, 'student');
$forum[] = $this->getDataGenerator()->create_module('forum', array('course' => $course));
$glossary[] = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
$chat[] = $this->getDataGenerator()->create_module('chat', array('course' => $course));
$assign[] = $this->getDataGenerator()->create_module('assign', ['course' => $course]);
}
$generator->enrol_user($teacher->id, $courses[0]->id, 'teacher');
@ -81,7 +81,7 @@ class externallib_test extends externallib_advanced_testcase {
$this->assertCount(count($forum), $result);
// Student access all assignments.
foreach ($chat as $module) {
foreach ($assign as $module) {
$event = \mod_chat\event\course_module_viewed::create(array('context' => \context_module::instance($module->cmid),
'objectid' => $module->id));
$event->trigger();
@ -90,7 +90,7 @@ class externallib_test extends externallib_advanced_testcase {
// Test that results are sorted by timeaccess DESC (default).
$result = \block_recentlyaccesseditems\external::get_recent_items();
$this->assertCount((count($forum) + count($chat)), $result);
$this->assertCount((count($forum) + count($assign)), $result);
foreach ($result as $key => $record) {
if ($key == 0) {
continue;
@ -101,11 +101,11 @@ class externallib_test extends externallib_advanced_testcase {
// Delete a course and confirm it's activities don't get returned.
delete_course($courses[0], false);
$result = \block_recentlyaccesseditems\external::get_recent_items();
$this->assertCount((count($forum) + count($chat)) - 2, $result);
$this->assertCount((count($forum) + count($assign)) - 2, $result);
// Delete a single course module should still return.
course_delete_module($forum[1]->cmid);
$result = \block_recentlyaccesseditems\external::get_recent_items();
$this->assertCount((count($forum) + count($chat)) - 3, $result);
$this->assertCount((count($forum) + count($assign)) - 3, $result);
}
}

View File

@ -158,6 +158,11 @@ class bulk_update_test extends \advanced_testcase {
protected function create_course_and_modules($modulenames) {
global $CFG, $PAGE;
// Chat and Survey modules are disabled by default, enable them for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
$manager::enable_plugin('survey', 1);
$CFG->enablecompletion = true;
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1], ['createsections' => true]);
$PAGE->set_course($course);

View File

@ -3189,8 +3189,24 @@ class externallib_test extends externallib_advanced_testcase {
// Create different types of activities.
$course = self::getDataGenerator()->create_course();
$tocreate = array('assign', 'book', 'choice', 'folder', 'forum', 'glossary', 'imscp', 'label', 'lti', 'page', 'quiz',
'resource', 'scorm', 'survey', 'url', 'wiki');
$tocreate = [
'assign',
'book',
'choice',
'folder',
'forum',
'glossary',
'imscp',
'label',
'lesson',
'lti',
'page',
'quiz',
'resource',
'scorm',
'url',
'wiki',
];
$modules = array();
foreach ($tocreate as $modname) {

View File

@ -115,6 +115,15 @@ abstract class restore_date_testcase extends advanced_testcase {
* @return array
*/
protected function create_course_and_module($modulename, $record = []) {
if ($modulename == 'chat') {
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
if ($modulename == 'survey') {
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
// Create a course with specific start date.
$record = (array)$record;
$generator = $this->getDataGenerator();

View File

@ -32,21 +32,21 @@ class mod_test extends advanced_testcase {
public function test_get_enabled_plugins(): void {
$this->resetAfterTest();
// The bigbluebuttonbn plugin is disabled by default.
// The bigbluebuttonbn and chat plugins are disabled by default.
// Check all default formats.
$plugins = mod::get_enabled_plugins();
$this->assertArrayHasKey('assign', $plugins);
$this->assertArrayHasKey('chat', $plugins);
$this->assertArrayHasKey('forum', $plugins);
$this->assertArrayNotHasKey('chat', $plugins);
$this->assertArrayNotHasKey('bigbluebuttonbn', $plugins);
// Disable assignment.
mod::enable_plugin('assign', 0);
$plugins = mod::get_enabled_plugins();
$this->assertArrayHasKey('chat', $plugins);
$this->assertArrayHasKey('forum', $plugins);
$this->assertArrayNotHasKey('assign', $plugins);
$this->assertArrayNotHasKey('chat', $plugins);
$this->assertArrayNotHasKey('bigbluebuttonbn', $plugins);
}
}

View File

@ -36,6 +36,15 @@ use core\activity_dates;
*/
class dates_test extends advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
/**
* Data provider for get_dates_for_module().
* @return array[]

View File

@ -38,6 +38,15 @@ require_once($CFG->dirroot . '/mod/chat/lib.php');
*/
class events_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
public function test_message_sent() {
global $DB;
$this->resetAfterTest();

View File

@ -54,7 +54,13 @@ class view_sessions_test extends externallib_advanced_testcase {
*/
private function prepare_test_data(): array {
global $DB;
$this->resetAfterTest(true);
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
$course = $this->getDataGenerator()->create_course();
$student1 = $this->getDataGenerator()->create_and_enrol($course);
$chat = $this->getDataGenerator()->create_module('chat', ['course' => $course->id]);

View File

@ -37,6 +37,15 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
*/
class externallib_test extends externallib_advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
/**
* Test login user
*/

View File

@ -25,6 +25,15 @@ namespace mod_chat;
*/
class generator_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
public function test_create_instance() {
global $DB;
$this->resetAfterTest();

View File

@ -38,6 +38,10 @@ class lib_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
/*

View File

@ -52,6 +52,10 @@ class provider_test extends provider_testcase {
global $PAGE;
$this->resetAfterTest();
$PAGE->get_renderer('core');
// Chat module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('chat', 1);
}
public function test_get_contexts_for_userid() {

View File

@ -38,6 +38,9 @@ class events_test extends \advanced_testcase {
*/
public function setUp(): void {
$this->resetAfterTest();
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
/**

View File

@ -70,6 +70,10 @@ class externallib_test extends externallib_advanced_testcase {
$this->resetAfterTest();
$this->setAdminUser();
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
// Setup test data.
$this->course = $this->getDataGenerator()->create_course();
$this->survey = $this->getDataGenerator()->create_module('survey', array('course' => $this->course->id));

View File

@ -26,6 +26,15 @@ namespace mod_survey;
*/
class generator_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
public function test_create_instance() {
global $DB;
$this->resetAfterTest();

View File

@ -48,6 +48,15 @@ class lib_test extends \advanced_testcase {
require_once($CFG->dirroot . '/mod/survey/lib.php');
}
/**
* Setup testcase.
*/
public function setUp(): void {
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
/**
* Test survey_view
* @return void

View File

@ -52,6 +52,10 @@ class provider_test extends provider_testcase {
global $PAGE;
$this->resetAfterTest();
$PAGE->get_renderer('core');
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
public function test_get_contexts_for_userid() {

View File

@ -39,6 +39,15 @@ namespace mod_survey\search;
*/
class search_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
// Survey module is disabled by default, enable it for testing.
$manager = \core_plugin_manager::resolve_plugininfo_class('mod');
$manager::enable_plugin('survey', 1);
}
/**
* Test survey_view
* @return void