See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 and 403]
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. 13 // 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/>. 16 17 /** 18 * Tests for report library functions. 19 * 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. 23 */ 24 namespace report_log; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 30 /** 31 * Class report_log_events_testcase. 32 * 33 * @package report_log 34 * @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com> 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. 36 */ 37 class lib_test extends \advanced_testcase { 38 39 /** 40 * @var stdClass The user. 41 */ 42 private $user; 43 44 /** 45 * @var stdClass The course. 46 */ 47 private $course; 48 49 /** 50 * @var \core_user\output\myprofile\tree The navigation tree. 51 */ 52 private $tree; 53 54 public function setUp(): void { 55 $this->user = $this->getDataGenerator()->create_user(); 56 $this->course = $this->getDataGenerator()->create_course(); 57 $this->tree = new \core_user\output\myprofile\tree(); 58 $this->resetAfterTest(); 59 } 60 61 /** 62 * Test report_log_supports_logstore. 63 */ 64 public function test_report_log_supports_logstore() { 65 $logmanager = get_log_manager(); 66 $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); 67 68 $supportedstores = array( 69 'logstore_database' => '\logstore_database\log\store', 70 'logstore_legacy' => '\logstore_legacy\log\store', 71 'logstore_standard' => '\logstore_standard\log\store' 72 ); 73 74 // Make sure all supported stores are installed. 75 $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); 76 $stores = $logmanager->get_supported_logstores('report_log'); 77 $stores = array_keys($stores); 78 foreach ($expectedstores as $expectedstore) { 79 $this->assertContains($expectedstore, $stores); 80 } 81 } 82 83 /** 84 * Tests the report_log_myprofile_navigation() function as an admin viewing the logs for a user. 85 */ 86 public function test_report_log_myprofile_navigation() { 87 // Set as the admin. 88 $this->setAdminUser(); 89 $iscurrentuser = false; 90 91 // Check the node tree is correct. 92 report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 93 $reflector = new \ReflectionObject($this->tree); 94 $nodes = $reflector->getProperty('nodes'); 95 $nodes->setAccessible(true); 96 $this->assertArrayHasKey('alllogs', $nodes->getValue($this->tree)); 97 $this->assertArrayHasKey('todayslogs', $nodes->getValue($this->tree)); 98 } 99 100 /** 101 * Tests the report_log_myprofile_navigation() function as a user without permission. 102 */ 103 public function test_report_log_myprofile_navigation_without_permission() { 104 // Set to the other user. 105 $this->setUser($this->user); 106 $iscurrentuser = true; 107 108 // Check the node tree is correct. 109 report_log_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 110 $reflector = new \ReflectionObject($this->tree); 111 $nodes = $reflector->getProperty('nodes'); 112 $nodes->setAccessible(true); 113 $this->assertArrayNotHasKey('alllogs', $nodes->getValue($this->tree)); 114 $this->assertArrayNotHasKey('todayslogs', $nodes->getValue($this->tree)); 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body