first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,240 @@
<?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/>.
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
*/
namespace mod_bigbluebuttonbn\local\helpers;
use context_course;
use context_module;
use context_system;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use stdClass;
use stored_file;
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
* @covers \mod_bigbluebuttonbn\local\helpers\files
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\files
*/
class files_test extends \advanced_testcase {
use testcase_helper_trait;
/** @var string Filename used for the presentation */
const PRESENTATION_FILENAME = 'bbpresentation.pptx';
/** @var string Filename used for the presentation */
const PRESENTATION_FILEPATH = '/mod/bigbluebuttonbn/tests/fixtures/bbpresentation.pptx';
/**
* Plugin valid test case
*/
public function test_pluginfile_valid(): void {
$this->resetAfterTest();
$this->assertFalse(files::pluginfile_valid(context_course::instance($this->get_course()->id), 'presentation'));
$this->assertTrue(files::pluginfile_valid(context_system::instance(), 'presentation'));
$this->assertFalse(files::pluginfile_valid(context_system::instance(), 'otherfilearea'));
}
/**
* Plugin file test case
*/
public function test_pluginfile_file(): void {
global $CFG;
$this->resetAfterTest();
list($user, $bbactivity) = $this->create_user_and_activity($CFG->dirroot . self::PRESENTATION_FILEPATH);
$this->setUser($user);
$instance = instance::get_from_instanceid($bbactivity->id);
$cm = $instance->get_cm();
$cmrecord = $cm->get_course_module_record();
/** @var stored_file $mediafile */
$mediafile =
files::pluginfile_file($this->get_course(), $cmrecord, $instance->get_context(),
'presentation', [self::PRESENTATION_FILENAME]);
$this->assertEquals(self::PRESENTATION_FILENAME, $mediafile->get_filename());
}
/**
* Get presentation file
*/
public function test_default_presentation_get_file(): void {
$this->resetAfterTest();
list($user, $bbactivity) = $this->create_user_and_activity();
$this->setUser($user);
$instance = instance::get_from_instanceid($bbactivity->id);
$cm = $instance->get_cm();
$cmrecord = $cm->get_course_module_record();
$mediafilename =
files::get_plugin_filename($this->get_course(), $cmrecord, $instance->get_context(), ['presentation.pptx']);
$this->assertEquals('presentation.pptx', $mediafilename);
}
/**
* Test that file is accessible only once.
*/
public function test_presentation_file_accessible_twice(): void {
global $CFG;
$this->resetAfterTest();
list($user, $bbactivity) = $this->create_user_and_activity($CFG->dirroot . self::PRESENTATION_FILEPATH);
$this->setUser($user);
$CFG->bigbluebuttonbn_preuploadpresentation_editable = true;
$instance = instance::get_from_instanceid($bbactivity->id);
$presentation = $instance->get_presentation_for_bigbluebutton_upload();
$fulldirset = explode('/', $presentation['url']);
$filename = array_pop($fulldirset);
$nonce = array_pop($fulldirset);
$cm = $instance->get_cm();
$cmrecord = $cm->get_course_module_record();
// The link should be valid twice.
for ($i = 0; $i < 2; $i++) {
$mediafile = files::pluginfile_file($this->get_course(), $cmrecord, $instance->get_context(), 'presentation',
[$nonce, $filename]);
$this->assertEquals($filename, $mediafile->get_filename());
}
// Third time is a charm, this should be false.
$mediafile = files::pluginfile_file($this->get_course(), $cmrecord, $instance->get_context(), 'presentation',
[$nonce, $filename]);
$this->assertFalse($mediafile);
}
/**
* Test that file is accessible only once.
*/
public function test_presentation_file_not_accessible_externally(): void {
global $CFG;
$this->resetAfterTest();
list($user, $bbactivity) = $this->create_user_and_activity($CFG->dirroot . self::PRESENTATION_FILEPATH);
$this->setUser($user);
$CFG->bigbluebuttonbn_preuploadpresentation_editable = true;
$instance = instance::get_from_instanceid($bbactivity->id);
$presentation = $instance->get_presentation();
$fulldirset = explode('/', $presentation['url']);
$filename = array_pop($fulldirset);
$this->setGuestUser();
$this->expectException(\require_login_exception::class);
$cm = $instance->get_cm();
$cmrecord = $cm->get_course_module_record();
files::pluginfile_file($this->get_course(), $cmrecord, $instance->get_context(), 'presentation', [$filename]);
$this->setUser($user);
$mediafile = files::pluginfile_file($this->get_course(), $cmrecord, $instance->get_context(), 'presentation', [$filename]);
$this->assertNotNull($mediafile);
}
/**
* Get filename test
*/
public function test_pluginfile_filename(): void {
global $CFG;
$this->resetAfterTest();
list($user, $bbactivity, $bbactivitycm, $bbactivitycontext) = $this->create_user_and_activity();
$this->setUser($user);
$this->create_sample_file(self::PRESENTATION_FILENAME, $bbactivitycontext->id);
$CFG->bigbluebuttonbn_preuploadpresentation_editable = true;
$presentationdef = files::get_presentation($bbactivitycontext, self::PRESENTATION_FILENAME, $bbactivity->id, true);
$pathparts = explode('/', $presentationdef['url']);
$filename = array_pop($pathparts);
$salt = array_pop($pathparts);
$filename = files::get_plugin_filename($this->get_course(), $bbactivitycm->get_course_module_record(), $bbactivitycontext,
[$salt, $filename]);
$this->assertEquals(self::PRESENTATION_FILENAME, $filename);
}
/**
* Get media files
*/
public function test_get_media_file(): void {
$this->resetAfterTest();
list($user, $bbactivity) = $this->create_user_and_activity();
$this->setUser($user);
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$mediafilepath = files::save_media_file($bbformdata);
$this->assertEmpty($mediafilepath);
// From test_delete_original_file_from_draft (lib/test/filelib_test.php)
// Create a bbb private file.
$this->create_sample_file(self::PRESENTATION_FILENAME, context_module::instance($bbformdata->coursemodule)->id);
file_prepare_draft_area($bbformdata->presentation,
context_module::instance($bbformdata->coursemodule)->id,
'mod_bigbluebuttonbn',
'presentation', 0);
$mediafilepath = files::save_media_file($bbformdata);
$this->assertEquals('/' . self::PRESENTATION_FILENAME, $mediafilepath);
}
/**
* Create a user and an activity
*
* @param string|null $presentationpath
* @param bool $closed
* @return array
*/
protected function create_user_and_activity($presentationpath = null, $closed = false): array {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$this->setAdminUser();
$activitydata = ['closingtime' => time() + ($closed ? -3600 : +3600)];
if (!empty($presentationpath)) {
$activitydata['presentation'] = $presentationpath;
}
list($bbactivitycontext, $bbactivitycm, $bbactivity) =
$this->create_instance(null, $activitydata);
$generator->enrol_user($user->id, $this->get_course()->id, 'editingteacher');
return [$user, $bbactivity, $bbactivitycm, $bbactivitycontext];
}
/**
* Helper to create sample file for tests
*
* @param string $filename
* @param int $contextid
* @return stored_file
*/
protected function create_sample_file($filename, $contextid) {
$bbbfilerecord = new stdClass;
$bbbfilerecord->contextid = $contextid;
$bbbfilerecord->component = 'mod_bigbluebuttonbn';
$bbbfilerecord->filearea = 'presentation';
$bbbfilerecord->itemid = 0;
$bbbfilerecord->filepath = '/';
$bbbfilerecord->filename = $filename;
$bbbfilerecord->source = 'test';
$fs = get_file_storage();
return $fs->create_file_from_string($bbbfilerecord, 'Presentation file content');
}
}
@@ -0,0 +1,222 @@
<?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/>.
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
*/
namespace mod_bigbluebuttonbn\local\helpers;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
* @covers \mod_bigbluebuttonbn\local\helpers\mod_helper
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\mod_helper
*/
class mod_helper_trait_test extends \advanced_testcase {
use testcase_helper_trait;
/**
* Presave test
*/
public function test_process_pre_save(): void {
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->participants = '<p>this -&gt; &quot;</p>\n';
$bbformdata->timemodified = time();
mod_helper::process_pre_save($bbformdata);
$this->assertTrue($bbformdata->timemodified != 0);
$this->assertEquals('<p>this -> "</p>\n', $bbformdata->participants);
}
/**
* Presave instance
*/
public function test_process_pre_save_instance(): void {
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->instance = 0;
$bbformdata->timemodified = time();
mod_helper::process_pre_save($bbformdata);
$this->assertTrue($bbformdata->timemodified == 0);
}
/**
* Presave checkboxes
*/
public function test_process_pre_save_checkboxes(): void {
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$bbformdata = $this->get_form_data_from_instance($bbactivity);
unset($bbformdata->wait);
unset($bbformdata->recordallfromstart);
mod_helper::process_pre_save($bbformdata);
$this->assertTrue(isset($bbformdata->wait));
$this->assertTrue(isset($bbformdata->recordallfromstart));
}
/**
* Presave common
*/
public function test_process_pre_save_common(): void {
global $CFG;
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) =
$this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->groupmode = '1';
mod_helper::process_pre_save($bbformdata);
$this->assertEquals(0, $bbformdata->groupmode);
}
/**
* Post save
*/
public function test_process_post_save(): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
list($bbactivitycontext, $bbactivitycm, $bbactivity) =
$this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
// Reset some static caches used by this test after enabling the plugin.
get_module_types_names(false, true);
$bbformdata = $this->get_form_data_from_instance($bbactivity);
// Enrol users in a course so he will receive the message.
$teacher = $generator->create_user(['role' => 'editingteacher']);
$generator->enrol_user($teacher->id, $this->get_course()->id);
// Mark the form to trigger notification.
$bbformdata->coursecontentnotification = true;
$bbformdata->update = false;
$messagesink = $this->redirectMessages();
mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron.
ob_start();
$this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count());
$firstmessage = $messagesink->get_messages()[0];
$this->assertStringContainsString('is new in', $firstmessage->smallmessage);
}
/**
* Post save notification
*/
public function test_process_post_save_with_add(): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
list($bbactivitycontext, $bbactivitycm, $bbactivity) =
$this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
// Reset some static caches used by this test after enabling the plugin.
get_module_types_names(false, true);
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->update = false;
$messagesink = $this->redirectMessages();
// Enrol users in a course so he will receive the message.
$teacher = $generator->create_user(['role' => 'editingteacher']);
$generator->enrol_user($teacher->id, $this->get_course()->id);
$bbformdata->coursecontentnotification = true;
mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron.
ob_start();
$this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test.
$messages = $messagesink->get_messages_by_component_and_type(
component: 'core',
type: 'coursecontentupdated',
);
$this->assertEquals(1, count($messages));
$firstmessage = reset($messages);
$this->assertStringContainsString('is new in', $firstmessage->smallmessage);
}
/**
* Post save
*
* There was an issue when both the opening time and completion were set
* and the form was saved twice.
*/
public function test_process_post_save_twice_with_completion(): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
list($bbactivitycontext, $bbactivitycm, $bbactivity) =
$this->create_instance(null, ['type' => instance::TYPE_RECORDING_ONLY]);
// Reset some static caches used by this test after enabling the plugin.
get_module_types_names(false, true);
$bbformdata = $this->get_form_data_from_instance($bbactivity);
$bbformdata->completionunlocked = 0;
$bbformdata->completion = COMPLETION_AGGREGATION_ANY;
$bbformdata->completionview = COMPLETION_VIEWED;
$bbformdata->completionexpected = time();
$bbformdata->openingtime = time() - 1000;
$bbformdata->closing = time() + 1000;
// Enrol users in a course so he will receive the message.
$teacher = $generator->create_user();
$generator->enrol_user($teacher->id, $this->get_course()->id, 'editingteacher');
$this->setUser($teacher);
// Mark the form to trigger notification.
$bbformdata->coursecontentnotification = true;
$bbformdata->update = false;
$messagesink = $this->redirectMessages();
mod_helper::process_post_save($bbformdata);
edit_module_post_actions($bbformdata, $this->course);
// Now run cron.
ob_start();
$this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count());
$firstmessage = $messagesink->get_messages()[0];
$this->assertStringContainsString('is new in', $firstmessage->smallmessage);
$messagesink->clear();
// Do it a again, so we check we still have one event.
mod_helper::process_post_save($bbformdata);
// Mark the form to trigger notification.
$bbformdata->update = true;
edit_module_post_actions($bbformdata, $this->course);
// Now run cron.
ob_start();
$this->runAdhocTasks();
ob_get_clean(); // Suppress output as it can fail the test.
$this->assertEquals(1, $messagesink->count());
$firstmessage = $messagesink->get_messages()[0];
$this->assertStringContainsString('has been changed', $firstmessage->smallmessage);
}
}
@@ -0,0 +1,128 @@
<?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/>.
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
*/
namespace mod_bigbluebuttonbn\local\helpers;
use core_tag_tag;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\reset
* @covers \mod_bigbluebuttonbn\local\helpers\reset
*/
class reset_test extends \advanced_testcase {
use testcase_helper_trait;
/**
* Reset course item test
*/
public function test_reset_course_items(): void {
global $CFG;
$this->resetAfterTest();
$CFG->bigbluebuttonbn_recordings_enabled = false;
$results = reset::reset_course_items();
$this->assertEquals(["events" => 0, "tags" => 0, "logs" => 0], $results);
$CFG->bigbluebuttonbn_recordings_enabled = true;
$results = reset::reset_course_items();
$this->assertEquals(["events" => 0, "tags" => 0, "logs" => 0, "recordings" => 0], $results);
}
/**
* Reset get_status test
*/
public function test_reset_getstatus(): void {
$this->resetAfterTest();
$result = reset::reset_getstatus('events');
$this->assertEquals([
'component' => 'BigBlueButton',
'item' => 'Deleted events',
'error' => false,
], $result);
}
/**
* Reset event test
*/
public function test_reset_events(): void {
global $DB;
$this->resetAfterTest();
$this->setAdminUser();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(
null,
['openingtime' => time()]
);
$formdata = $this->get_form_data_from_instance($bbactivity);
\mod_bigbluebuttonbn\local\helpers\mod_helper::process_post_save($formdata);
$this->assertEquals(1, $DB->count_records(
'event',
['modulename' => 'bigbluebuttonbn', 'courseid' => $this->get_course()->id]));
reset::reset_events($this->get_course()->id);
$this->assertEquals(0, $DB->count_records(
'event',
['modulename' => 'bigbluebuttonbn', 'courseid' => $this->get_course()->id]));
}
/**
* Reset tags test
*/
public function test_reset_tags(): void {
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(null,
['course' => $this->get_course()->id],
['visible' => true]
);
core_tag_tag::add_item_tag('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id, $bbactivitycontext, 'newtag');
$alltags = core_tag_tag::get_item_tags('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id);
$this->assertCount(1, $alltags);
reset::reset_tags($this->get_course()->id);
$alltags = core_tag_tag::get_item_tags('mod_bigbluebuttonbn', 'bbitem', $bbactivity->id);
$this->assertCount(0, $alltags);
}
/**
* Reset recordings test
*/
public function test_reset_recordings(): void {
$this->initialise_mock_server();
$this->resetAfterTest();
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(null,
['course' => $this->get_course()->id],
['visible' => true]
);
$instance = instance::get_from_instanceid($bbactivity->id);
$this->create_recordings_for_instance($instance, [
['name' => 'Recording 1'],
['name' => 'Recording 2'],
]);
$this->assertCount(2, $instance->get_recordings());
reset::reset_recordings($this->get_course()->id);
$this->assertCount(0, $instance->get_recordings());
}
}
@@ -0,0 +1,94 @@
<?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 mod_bigbluebuttonbn\local\helpers;
use context_course;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* BBB Library tests class.
*
* @package mod_bigbluebuttonbn
* @copyright 2018 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
* @covers \mod_bigbluebuttonbn\local\helpers\roles
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\roles
*/
class roles_test extends \advanced_testcase {
use testcase_helper_trait;
/**
* Test select separate group prevent all
*
*/
public function test_get_users_select_separate_groups_prevent_all(): void {
$this->resetAfterTest();
$numstudents = 12;
$numteachers = 3;
$groupsnum = 3;
list($course, $groups, $students, $teachers, $bbactivity, $roleids) =
$this->setup_course_students_teachers(
(object) ['enablecompletion' => true, 'groupmode' => strval(SEPARATEGROUPS), 'groupmodeforce' => 1],
$numstudents, $numteachers, $groupsnum);
$context = context_course::instance($course->id);
// Prevent access all groups.
role_change_permission($roleids['teacher'], $context, 'moodle/site:accessallgroups', CAP_PREVENT);
$this->setUser($teachers[0]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
$this->setUser($teachers[1]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
$this->setUser($teachers[2]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount(($numstudents + $numteachers) / $groupsnum, $users);
$course->groupmode = strval(SEPARATEGROUPS);
$course->groupmodeforce = "0";
update_course($course);
$this->setUser($teachers[2]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount($numstudents + $numteachers, $users);
}
/**
* Test select separate groups
*
*/
public function test_get_users_select_separate_groups(): void {
$this->resetAfterTest();
$numstudents = 12;
$numteachers = 3;
$groupsnum = 3;
list($course, $groups, $students, $teachers, $bbactivity, $roleids) =
$this->setup_course_students_teachers(
(object) ['enablecompletion' => true, 'groupmode' => strval(VISIBLEGROUPS), 'groupmodeforce' => 1],
$numstudents, $numteachers, $groupsnum);
$context = context_course::instance($course->id);
$this->setUser($teachers[0]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount($numstudents + $numteachers, $users);
$this->setUser($teachers[1]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount($numstudents + $numteachers, $users);
$this->setUser($teachers[1]);
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount($numstudents + $numteachers, $users);
}
}
@@ -0,0 +1,116 @@
<?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 mod_bigbluebuttonbn\local\helpers;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
* User information printing test
*
* @package mod_bigbluebuttonbn
* @copyright 2022 - present, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David (laurent@call-learning.fr)
* @covers \mod_bigbluebuttonbn\local\helpers\user_info
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\user_info
*/
class user_info_test extends \advanced_testcase {
use testcase_helper_trait;
/**
* Test user info outline
*
* @return void
*/
public function test_get_user_info_outline(): void {
$this->initialise_mock_server();
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$user = $generator->create_and_enrol($this->get_course());
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$this->setUser($user);
// Now create a couple of logs.
$instance = instance::get_from_instanceid($bbactivity->id);
$recordings = $this->create_recordings_for_instance($instance, [['name' => "Pre-Recording 1"]]);
logger::log_meeting_joined_event($instance, 0);
logger::log_recording_played_event($instance, $recordings[0]->id);
[$logjoins, $logtimes] = user_info::get_user_info_outline($this->get_course(), $user, $bbactivitycm);
$this->assertEquals([
'1 meeting(s)',
'1 recording(s) played'
], $logjoins);
$this->assertCount(2, $logtimes);
}
/**
* Test user info outline with several logs
*
* @return void
*/
public function test_get_user_info_outline_several_logs(): void {
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$user = $generator->create_and_enrol($this->get_course());
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance();
$this->setUser($user);
// Now create a couple of logs.
$instance = instance::get_from_instanceid($bbactivity->id);
logger::log_meeting_joined_event($instance, 0);
logger::log_meeting_joined_event($instance, 0);
[$logjoins, $logtimes] = user_info::get_user_info_outline($this->get_course(), $user, $bbactivitycm);
$this->assertEquals([
'2 meeting(s)',
], $logjoins);
$this->assertCount(1, $logtimes);
}
/**
* Test user info outline for view events
*
* @return void
*/
public function test_get_user_info_outline_view(): void {
$this->initialise_mock_server();
$this->resetAfterTest();
$generator = $this->getDataGenerator();
$user = $generator->create_and_enrol($this->get_course());
list($bbactivitycontext, $bbactivitycm, $bbactivity) = $this->create_instance(
null,
['completion' => 2, 'completionview' => 1]);
$this->setUser($user);
// Now create a couple of logs.
$instance = instance::get_from_instanceid($bbactivity->id);
// View it twice.
bigbluebuttonbn_view($instance->get_instance_data(), $instance->get_course(), $instance->get_cm(),
$instance->get_context());
bigbluebuttonbn_view($instance->get_instance_data(), $instance->get_course(), $instance->get_cm(),
$instance->get_context());
[$logjoins, $logtimes] = user_info::get_user_info_outline($this->get_course(), $user, $bbactivitycm);
$this->assertEquals([
'viewed',
], $logjoins);
$this->assertCount(1, $logtimes);
}
}