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,26 @@
@report @report_loglive
Feature: In a course administration page, navigate through report page, test for report live log page
In order to navigate through report page
As an admin
Go to the course administration -> reports -> live logs
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| admin | C1 | editingteacher |
| student1 | C1 | student |
@javascript
Scenario: Selector should be available in live logs page
Given I log in as "admin"
And I am on "Course 1" course homepage
When I navigate to "Reports" in current page administration
And I click on "Live logs" "link"
Then "Report" "field" should exist in the "tertiary-navigation" "region"
And I should see "Live logs" in the "tertiary-navigation" "region"
@@ -0,0 +1,61 @@
@report @report_loglive
Feature: In a report, admin can see loglive data
In order see loglive data
As an admin
I need to view loglive report and see if the live update feature works
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber | middlename | alternatename | firstnamephonetic | lastnamephonetic |
| student1 | Grainne | Beauchamp | student1@example.com | s1 | Ann | Jill | Gronya | Beecham |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And the following config values are set as admin:
| fullnamedisplay | firstname |
| alternativefullnameformat | middlename, alternatename, firstname, lastname |
And I log in as "admin"
And I add a data activity to course "Course 1" section "3" and I fill the form with:
| Name | Test name |
| Description | Test database description |
@javascript
Scenario: Check loglive report entries and make sure the report works for standard reader
Given I navigate to "Reports > Live logs" in site administration
When I should see "Course module created"
Then I should see "Test name"
@javascript @_switch_window
Scenario: Check loglive report entries and make sure the pause/resume button works for standard reader along with ajax calls
Given I am on site homepage
When I navigate to "Reports > Live logs" in site administration
And I should not see "Test name2"
And I press "Pause live updates"
And I follow "Course module created"
And I switch to "action" window
And I am on "Course 1" course homepage
And I change window size to "large"
And I reload the page
And I add a data activity to course "Course 1" section "3" and I fill the form with:
| Name | Test name2 |
| Description | Test database description |
And I switch to the main window
And I wait "8" seconds
Then I should not see "Test name2"
And I press "Resume live updates"
And I wait "8" seconds
And I should see "Test name2"
@javascript
Scenario: Check course loglive report entries for a user
Given I log out
And I am on the "Test name" "data activity" page logged in as student1
And I log out
And I am on the "Course 1" Course page logged in as admin
When I navigate to "Reports > Live logs" in site administration
Then I should see "Course module viewed"
And I should see "Test name"
And I should see "Ann, Jill, Grainne, Beauchamp"
@@ -0,0 +1,70 @@
<?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/>.
/**
* Tests for report log live events.
*
* @package report_loglive
* @copyright 2014 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace report_loglive\event;
/**
* Class report_loglive_events_testcase
*
* Class for tests related to log live events.
*
* @package report_loglive
* @copyright 2014 Rajesh Taneja <rajesh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class events_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
$this->setAdminUser();
$this->resetAfterTest();
}
/**
* Test the report viewed event.
*
* It's not possible to use the moodle API to simulate the viewing of log report, so here we
* simply create the event and trigger it.
*/
public function test_report_viewed(): void {
$course = $this->getDataGenerator()->create_course();
$context = \context_course::instance($course->id);
// Trigger event for loglive report viewed.
$event = \report_loglive\event\report_viewed::create(array('context' => $context));
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\report_loglive\event\report_viewed', $event);
$this->assertEquals($context, $event->get_context());
$this->assertEventContextNotUsed($event);
$url = new \moodle_url('/report/loglive/index.php', array('id' => $course->id));
$this->assertEquals($url, $event->get_url());
}
}
+94
View File
@@ -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/>.
/**
* Tests for report library functions.
*
* @package report_loglive
* @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace report_loglive;
defined('MOODLE_INTERNAL') || die();
/**
* Class report_loglive_lib_testcase
*
* @package report_loglive
* @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class lib_test extends \advanced_testcase {
/**
* Test report_log_supports_logstore.
*/
public function test_report_participation_supports_logstore(): void {
$logmanager = get_log_manager();
$allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store');
$supportedstores = array(
'logstore_standard' => '\logstore_standard\log\store'
);
// Make sure all supported stores are installed.
$expectedstores = array_keys(array_intersect($allstores, $supportedstores));
$stores = $logmanager->get_supported_logstores('report_loglive');
$stores = array_keys($stores);
foreach ($expectedstores as $expectedstore) {
$this->assertContains($expectedstore, $stores);
}
}
/**
* Test the latest record timestamp of the report data set.
*
* @covers ::get_until()
*/
public function test_report_get_until(): void {
global $DB;
$this->resetAfterTest();
$this->preventResetByRollback();
$now = time();
// Configure log store.
set_config('enabled_stores', 'logstore_standard', 'tool_log');
$manager = get_log_manager();
$stores = $manager->get_readers();
$store = $stores['logstore_standard'];
$DB->delete_records('logstore_standard_log');
// Build the report.
$url = new \moodle_url("/report/loglive/index.php");
$renderable = new \report_loglive_renderable('logstore_standard', 0, $url);
$table = $renderable->get_table();
$table->query_db(100);
$until = $table->get_until();
// There is no record in the log table at this stage so until date is supposed to be equal to CUTOFF date.
$this->assertLessThanOrEqual(time() - \report_loglive_renderable::CUTOFF, $until);
// Create a user, store the event and re-build the report.
$this->getDataGenerator()->create_user();
$store->flush();
$table->query_db(100);
$until = $table->get_until();
// Assert that until date reflects user creation event date (now).
$this->assertGreaterThanOrEqual($now, $until);
}
}
+320
View File
@@ -0,0 +1,320 @@
<?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 report_loglive;
use advanced_testcase;
use context_course;
use core_user;
/**
* Tests for table log and groups.
*
* @package report_loglive
* @copyright 2024 onwards Laurent David <laurent.david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class table_log_test extends advanced_testcase {
/**
* @var int The course with separate groups.
*/
const COURSE_SEPARATE_GROUP = 0;
/**
* @var int The course with separate groups.
*/
const COURSE_VISIBLE_GROUP = 1;
/**
* @var int The course with separate groups.
*/
const COURSE_NO_GROUP = 2;
/**
* @var array The setup of users.
*/
const SETUP_USER_DEFS = [
// Make student2 also member of group1.
'student' => [
'student0' => ['group0'],
'student1' => ['group1'],
'student2' => ['group0', 'group1'],
'student3' => [],
],
// Make teacher2 also member of group1.
'teacher' => [
'teacher0' => ['group0'],
'teacher1' => ['group1'],
'teacher2' => ['group0', 'group1'],
'teacher3' => [],
],
// Make editingteacher also member of group1.
'editingteacher' => [
'editingteacher0' => ['group0'],
'editingteacher1' => ['group1'],
'editingteacher2' => ['group0', 'group1'],
],
];
/**
* @var array|\stdClass all users indexed by username.
*/
private $users = [];
/**
* @var array The groups by courses (array of array).
*/
private $groupsbycourse = [];
/**
* @var array The courses.
*/
private $courses;
/**
* Data provider for test_get_table_logs.
*
* @return array
*/
public static function get_report_logs_provider(): array {
return [
'separategroups: student 0' => [
self::COURSE_SEPARATE_GROUP,
'student0',
// All users in group 0.
[
'student0', 'student2',
'teacher0', 'teacher2',
'editingteacher0', 'editingteacher2',
],
],
'separategroups: student 1' => [
self::COURSE_SEPARATE_GROUP,
'student1',
// All users in group1.
[
'student1', 'student2',
'teacher1', 'teacher2',
'editingteacher1', 'editingteacher2',
],
],
'separategroups: student 2' => [
self::COURSE_SEPARATE_GROUP,
'student2',
// All users in group0 and group1.
[
'student0', 'student1', 'student2',
'teacher0', 'teacher1', 'teacher2',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'separategroups: student3' => [
self::COURSE_SEPARATE_GROUP,
'student3',
// Student 3 is not in any group so should only see user without a group.
[
'student3',
'teacher3',
],
],
'separategroups: editing teacher 0' => [
self::COURSE_SEPARATE_GROUP,
'editingteacher0',
// All users including student 3 as we can see all users (event the one not in a group).
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'separategroups: teacher 0' => [
self::COURSE_SEPARATE_GROUP,
'teacher0',
// All users in group 0.
[
'student0', 'student2',
'teacher0', 'teacher2',
'editingteacher0', 'editingteacher2',
],
],
'separategroups: teacher 2' => [
self::COURSE_SEPARATE_GROUP,
'teacher2',
// All users in group0 and group1.
[
'student0', 'student1', 'student2',
'teacher0', 'teacher1', 'teacher2',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'separategroups: teacher 3' => [
self::COURSE_SEPARATE_GROUP,
'teacher3',
// Teacher 3 is not in any group so should only see user without a group.
[
'student3',
'teacher3',
],
],
'visiblegroup: editing teacher' => [
self::COURSE_VISIBLE_GROUP,
'editingteacher0',
// All users.
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'visiblegroup: student' => [
self::COURSE_VISIBLE_GROUP,
'student0',
// All users.
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'nogroup: teacher 0' => [
self::COURSE_VISIBLE_GROUP,
'teacher2',
// All users.
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'nogroup: editing teacher 0' => [
self::COURSE_VISIBLE_GROUP,
'editingteacher0',
// All users.
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
'nogroup: student' => [
self::COURSE_VISIBLE_GROUP,
'student0',
// All users.
[
'student0', 'student1', 'student2', 'student3',
'teacher0', 'teacher1', 'teacher2', 'teacher3',
'editingteacher0', 'editingteacher1', 'editingteacher2',
],
],
];
}
/**
* Set up a course with two groups, three students being each in one of the groups,
* two teachers each in either group while the second teacher is also member of the other group.
*
* @return void
* @throws \coding_exception
*/
public function setUp(): void {
global $DB;
$this->resetAfterTest();
$this->preventResetByRollback(); // This is to ensure that we can actually trigger event and record them in the log store.
$this->courses[self::COURSE_SEPARATE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS]);
$this->courses[self::COURSE_VISIBLE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => VISIBLEGROUPS]);
$this->courses[self::COURSE_NO_GROUP] = $this->getDataGenerator()->create_course();
foreach ($this->courses as $coursetype => $course) {
if ($coursetype == self::COURSE_NO_GROUP) {
continue;
}
$this->groupsbycourse[$coursetype] = [];
$this->groupsbycourse[$coursetype]['group0'] =
$this->getDataGenerator()->create_group(['courseid' => $course->id, 'name' => 'group0']);
$this->groupsbycourse[$coursetype]['group1'] =
$this->getDataGenerator()->create_group(['courseid' => $course->id, 'name' => 'group1']);
}
foreach (self::SETUP_USER_DEFS as $role => $userdefs) {
foreach ($userdefs as $username => $groups) {
$user = $this->getDataGenerator()->create_user(
[
'username' => $username,
'firstname' => "FN{$role}{$username}",
'lastname' => "LN{$role}{$username}",
]);
foreach ($this->courses as $coursetype => $course) {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role);
foreach ($groups as $groupname) {
if ($coursetype == self::COURSE_NO_GROUP) {
continue;
}
$this->getDataGenerator()->create_group_member([
'groupid' => $this->groupsbycourse[$coursetype][$groupname]->id,
'userid' => $user->id,
]);
}
}
$this->users[$username] = $user;
}
}
// Configure log store.
set_config('enabled_stores', 'logstore_standard', 'tool_log');
get_log_manager(true);
$DB->delete_records('logstore_standard_log');
foreach ($this->courses as $course) {
foreach ($this->users as $user) {
$eventdata = [
'context' => context_course::instance($course->id),
'userid' => $user->id,
];
$event = \core\event\course_viewed::create($eventdata);
$event->trigger();
}
}
}
/**
* Test table_log
*
* @param int $courseindex
* @param string $username
* @param array $expectedusers
* @covers \report_log_renderable::get_user_list
* @dataProvider get_report_logs_provider
* @return void
*/
public function test_get_table_logs(int $courseindex, string $username, array $expectedusers): void {
$manager = get_log_manager();
$stores = $manager->get_readers();
$store = $stores['logstore_standard'];
// Build the report.
$url = new \moodle_url("/report/loglive/index.php");
$renderable = new \report_loglive_renderable('logstore_standard', $this->courses[$courseindex], $url);
$table = $renderable->get_table();
$currentuser = $this->users[$username];
$this->setUser($currentuser->id);
$store->flush();
$table->query_db(100);
$filteredevents =
array_filter(
$table->rawdata, fn($event) => get_class($event) === \core\event\course_viewed::class
);
$usernames = array_map(
function($event) {
$user = core_user::get_user($event->userid, '*', MUST_EXIST);
return $user->username;
},
$filteredevents);
sort($expectedusers);
sort($usernames);
$this->assertEquals($expectedusers, $usernames);
}
}