MDL-53425 blocklib: Perform deletion of block instances by chunk
[moodle.git] / report / log / tests / lib_test.php
blobd35bc04c792a34d8bc69b808a685e44e00774669
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Tests for report library functions.
20 * @package report_log
21 * @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
25 defined('MOODLE_INTERNAL') || die();
27 global $CFG;
29 /**
30 * Class report_log_events_testcase.
32 * @package report_log
33 * @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
36 class report_log_lib_testcase extends advanced_testcase {
38 /**
39 * @var stdClass The user.
41 private $user;
43 /**
44 * @var stdClass The course.
46 private $course;
48 /**
49 * @var \core_user\output\myprofile\tree The navigation tree.
51 private $tree;
53 public function setUp() {
54 $this->user = $this->getDataGenerator()->create_user();
55 $this->course = $this->getDataGenerator()->create_course();
56 $this->tree = new \core_user\output\myprofile\tree();
57 $this->resetAfterTest();
60 /**
61 * Test report_log_supports_logstore.
63 public function test_report_log_supports_logstore() {
64 $logmanager = get_log_manager();
65 $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store');
67 $supportedstores = array(
68 'logstore_database' => '\logstore_database\log\store',
69 'logstore_legacy' => '\logstore_legacy\log\store',
70 'logstore_standard' => '\logstore_standard\log\store'
73 // Make sure all supported stores are installed.
74 $expectedstores = array_keys(array_intersect($allstores, $supportedstores));
75 $stores = $logmanager->get_supported_logstores('report_log');
76 $stores = array_keys($stores);
77 foreach ($expectedstores as $expectedstore) {
78 $this->assertContains($expectedstore, $stores);
82 /**
83 * Tests the report_log_myprofile_navigation() function as an admin viewing the logs for a user.
85 public function test_report_log_myprofile_navigation() {
86 // Set as the admin.
87 $this->setAdminUser();
88 $iscurrentuser = false;
90 // Check the node tree is correct.
91 report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
92 $reflector = new ReflectionObject($this->tree);
93 $nodes = $reflector->getProperty('nodes');
94 $nodes->setAccessible(true);
95 $this->assertArrayHasKey('alllogs', $nodes->getValue($this->tree));
96 $this->assertArrayHasKey('todayslogs', $nodes->getValue($this->tree));
99 /**
100 * Tests the report_log_myprofile_navigation() function as a user without permission.
102 public function test_report_log_myprofile_navigation_without_permission() {
103 // Set to the other user.
104 $this->setUser($this->user);
105 $iscurrentuser = true;
107 // Check the node tree is correct.
108 report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course);
109 $reflector = new ReflectionObject($this->tree);
110 $nodes = $reflector->getProperty('nodes');
111 $nodes->setAccessible(true);
112 $this->assertArrayNotHasKey('alllogs', $nodes->getValue($this->tree));
113 $this->assertArrayNotHasKey('todayslogs', $nodes->getValue($this->tree));