Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [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_stats 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_stats; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Class report_stats_lib_testcase 30 * 31 * @package report_stats 32 * @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. 34 */ 35 class lib_test extends \advanced_testcase { 36 37 /** 38 * @var stdClass The user. 39 */ 40 private $user; 41 42 /** 43 * @var stdClass The course. 44 */ 45 private $course; 46 47 /** 48 * @var \core_user\output\myprofile\tree The navigation tree. 49 */ 50 private $tree; 51 52 public function setUp(): void { 53 $this->user = $this->getDataGenerator()->create_user(); 54 $this->course = $this->getDataGenerator()->create_course(); 55 $this->tree = new \core_user\output\myprofile\tree(); 56 $this->resetAfterTest(); 57 } 58 59 /** 60 * Test report_log_supports_logstore. 61 */ 62 public function test_report_participation_supports_logstore() { 63 $logmanager = get_log_manager(); 64 $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); 65 66 $supportedstores = array( 67 'logstore_standard' => '\logstore_standard\log\store' 68 ); 69 70 // Make sure all supported stores are installed. 71 $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); 72 $stores = $logmanager->get_supported_logstores('report_stats'); 73 $stores = array_keys($stores); 74 foreach ($expectedstores as $expectedstore) { 75 $this->assertContains($expectedstore, $stores); 76 } 77 } 78 79 /** 80 * Tests the report_stats_myprofile_navigation() function. 81 */ 82 public function test_report_stats_myprofile_navigation() { 83 $this->setAdminUser(); 84 $iscurrentuser = false; 85 86 // Enable stats. 87 set_config('enablestats', true); 88 89 report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 90 $reflector = new \ReflectionObject($this->tree); 91 $nodes = $reflector->getProperty('nodes'); 92 $nodes->setAccessible(true); 93 $this->assertArrayHasKey('stats', $nodes->getValue($this->tree)); 94 } 95 96 /** 97 * Tests the report_stats_myprofile_navigation() function when stats are disabled. 98 */ 99 public function test_report_stats_myprofile_navigation_stats_disabled() { 100 $this->setAdminUser(); 101 $iscurrentuser = false; 102 103 // Disable stats. 104 set_config('enablestats', false); 105 106 report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 107 $reflector = new \ReflectionObject($this->tree); 108 $nodes = $reflector->getProperty('nodes'); 109 $nodes->setAccessible(true); 110 $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree)); 111 } 112 113 /** 114 * Tests the report_stats_myprofile_navigation() function without permission. 115 */ 116 public function test_report_stats_myprofile_navigation_without_permission() { 117 // Try to see as a user without permission. 118 $this->setUser($this->user); 119 $iscurrentuser = true; 120 121 // Enable stats. 122 set_config('enablestats', true); 123 124 report_stats_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 125 $reflector = new \ReflectionObject($this->tree); 126 $nodes = $reflector->getProperty('nodes'); 127 $nodes->setAccessible(true); 128 $this->assertArrayNotHasKey('stats', $nodes->getValue($this->tree)); 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body