Skip to content

Commit

Permalink
MDL-80866 phpunit: Fix failures after disabling Chat and Survey
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Mar 1, 2024
1 parent 0b3b739 commit b2e5f3e
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 11 deletions.
2 changes: 1 addition & 1 deletion admin/presets/tests/helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function change_default_preset_provider(): array {
],
'plugins' => [
'assign' => 1,
'chat' => 1,
'book' => 1,
'data' => 1,
'lesson' => 1,
],
Expand Down
10 changes: 5 additions & 5 deletions blocks/recentlyaccesseditems/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function test_get_recent_items() {
$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');

Expand All @@ -81,7 +81,7 @@ public function test_get_recent_items() {
$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();
Expand All @@ -90,7 +90,7 @@ public function test_get_recent_items() {

// 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;
Expand All @@ -101,11 +101,11 @@ public function test_get_recent_items() {
// 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);
}
}
5 changes: 5 additions & 0 deletions completion/tests/bulk_update_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function test_bulk_form_submit_single($modname, $submitdata, $validatedat
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);
Expand Down
20 changes: 18 additions & 2 deletions course/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3189,8 +3189,24 @@ public function test_check_updates() {

// 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) {
Expand Down
9 changes: 9 additions & 0 deletions lib/phpunit/classes/restore_date_testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ protected function backup_and_restore($course, $newdate = 0) {
* @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();
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/plugininfo/mod_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 9 additions & 0 deletions mod/chat/tests/dates_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
*/
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[]
Expand Down
9 changes: 9 additions & 0 deletions mod/chat/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
*/
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();
Expand Down
6 changes: 6 additions & 0 deletions mod/chat/tests/external/view_sessions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
9 changes: 9 additions & 0 deletions mod/chat/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
*/
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
*/
Expand Down
9 changes: 9 additions & 0 deletions mod/chat/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
*/
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();
Expand Down
4 changes: 4 additions & 0 deletions mod/chat/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down
4 changes: 4 additions & 0 deletions mod/chat/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function setUp(): void {
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() {
Expand Down
3 changes: 3 additions & 0 deletions mod/survey/tests/event/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions mod/survey/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function setUp(): void {
$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));
Expand Down
9 changes: 9 additions & 0 deletions mod/survey/tests/generator_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
*/
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();
Expand Down
9 changes: 9 additions & 0 deletions mod/survey/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public static function setUpBeforeClass(): void {
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
Expand Down
4 changes: 4 additions & 0 deletions mod/survey/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function setUp(): void {
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() {
Expand Down
9 changes: 9 additions & 0 deletions mod/survey/tests/search/search_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
*/
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
Expand Down

0 comments on commit b2e5f3e

Please sign in to comment.