| Línea 24... |
Línea 24... |
| 24 |
*
|
24 |
*
|
| 25 |
* @package report_log
|
25 |
* @package report_log
|
| 26 |
* @copyright 2023 Stephan Robotta <stephan.robotta@bfh.ch>
|
26 |
* @copyright 2023 Stephan Robotta <stephan.robotta@bfh.ch>
|
| 27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
|
| 28 |
*/
|
28 |
*/
|
| 29 |
class renderable_test extends \advanced_testcase {
|
29 |
final class renderable_test extends \advanced_testcase {
|
| 30 |
/**
|
30 |
/**
|
| 31 |
* @var int The course with separate groups.
|
31 |
* @var int The course with separate groups.
|
| 32 |
*/
|
32 |
*/
|
| 33 |
const COURSE_SEPARATE_GROUP = 0;
|
33 |
const COURSE_SEPARATE_GROUP = 0;
|
| 34 |
/**
|
34 |
/**
|
| Línea 263... |
Línea 263... |
| 263 |
*
|
263 |
*
|
| 264 |
* @return void
|
264 |
* @return void
|
| 265 |
* @throws \coding_exception
|
265 |
* @throws \coding_exception
|
| 266 |
*/
|
266 |
*/
|
| 267 |
public function setUp(): void {
|
267 |
public function setUp(): void {
|
| - |
|
268 |
parent::setUp();
|
| 268 |
$this->resetAfterTest();
|
269 |
$this->resetAfterTest();
|
| 269 |
$this->courses[self::COURSE_SEPARATE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS]);
|
270 |
$this->courses[self::COURSE_SEPARATE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => SEPARATEGROUPS]);
|
| 270 |
$this->courses[self::COURSE_VISIBLE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => VISIBLEGROUPS]);
|
271 |
$this->courses[self::COURSE_VISIBLE_GROUP] = $this->getDataGenerator()->create_course(['groupmode' => VISIBLEGROUPS]);
|
| 271 |
$this->courses[self::COURSE_NO_GROUP] = $this->getDataGenerator()->create_course();
|
272 |
$this->courses[self::COURSE_NO_GROUP] = $this->getDataGenerator()->create_course();
|
| Línea 316... |
Línea 317... |
| 316 |
* @covers \report_log_renderable::get_user_list
|
317 |
* @covers \report_log_renderable::get_user_list
|
| 317 |
* @dataProvider get_user_visibility_list_provider
|
318 |
* @dataProvider get_user_visibility_list_provider
|
| 318 |
* @return void
|
319 |
* @return void
|
| 319 |
*/
|
320 |
*/
|
| 320 |
public function test_get_user_list(int $courseindex, string $username, array $expectedusers,
|
321 |
public function test_get_user_list(int $courseindex, string $username, array $expectedusers,
|
| 321 |
string $groupname = null): void {
|
322 |
?string $groupname = null): void {
|
| 322 |
global $PAGE, $CFG;
|
323 |
global $PAGE, $CFG;
|
| 323 |
$currentcourse = $this->courses[$courseindex];
|
324 |
$currentcourse = $this->courses[$courseindex];
|
| 324 |
$PAGE->set_url('/report/log/index.php?id=' . $currentcourse->id);
|
325 |
$PAGE->set_url('/report/log/index.php?id=' . $currentcourse->id);
|
| 325 |
// Fetch all users of group 1 and the guest user.
|
326 |
// Fetch all users of group 1 and the guest user.
|
| 326 |
$currentuser = $this->users[$username];
|
327 |
$currentuser = $this->users[$username];
|
| Línea 434... |
Línea 435... |
| 434 |
}
|
435 |
}
|
| 435 |
sort($expectedusers);
|
436 |
sort($expectedusers);
|
| 436 |
sort($usernames);
|
437 |
sort($usernames);
|
| 437 |
$this->assertEquals($expectedusers, $usernames);
|
438 |
$this->assertEquals($expectedusers, $usernames);
|
| 438 |
}
|
439 |
}
|
| - |
|
440 |
|
| - |
|
441 |
/**
|
| - |
|
442 |
* Test getting logs for deleted courses.
|
| - |
|
443 |
*
|
| - |
|
444 |
* @covers \report_log_renderable::setup_table
|
| - |
|
445 |
* @return void
|
| - |
|
446 |
*/
|
| - |
|
447 |
public function test_get_deleted_course_logs(): void {
|
| - |
|
448 |
global $DB, $PAGE;
|
| - |
|
449 |
$this->preventResetByRollback(); // Ensure events can be recorded in log store.
|
| - |
|
450 |
|
| - |
|
451 |
// Configure log store and user.
|
| - |
|
452 |
set_config('enabled_stores', 'logstore_standard', 'tool_log');
|
| - |
|
453 |
$manager = get_log_manager(true);
|
| - |
|
454 |
$stores = $manager->get_readers();
|
| - |
|
455 |
$store = $stores['logstore_standard'];
|
| - |
|
456 |
$this->setUser(get_admin());
|
| - |
|
457 |
|
| - |
|
458 |
// Set and delete course.
|
| - |
|
459 |
$course = reset($this->courses);
|
| - |
|
460 |
$deletedcourseid = $course->id;
|
| - |
|
461 |
delete_course($course, false);
|
| - |
|
462 |
$this->assertFalse($DB->record_exists('course', ['id' => $deletedcourseid]));
|
| - |
|
463 |
|
| - |
|
464 |
// Test rendering.
|
| - |
|
465 |
$PAGE->set_url('/report/log/index.php?id=' . $deletedcourseid);
|
| - |
|
466 |
$renderable = new \report_log_renderable('', (int) $deletedcourseid);
|
| - |
|
467 |
$renderable->setup_table();
|
| - |
|
468 |
$store->flush();
|
| - |
|
469 |
$table = $renderable->tablelog;
|
| - |
|
470 |
$table->query_db(100);
|
| - |
|
471 |
|
| - |
|
472 |
// Confirm we have logs for the course deletion and that the filtering is correct.
|
| - |
|
473 |
$this->assertNotEmpty($table->totalrows);
|
| - |
|
474 |
$expectedrows = count($DB->get_records('logstore_standard_log', ['courseid' => $deletedcourseid]));
|
| - |
|
475 |
$this->assertEquals($expectedrows, $table->totalrows);
|
| - |
|
476 |
}
|
| 439 |
}
|
477 |
}
|