Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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_outline 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 25 defined('MOODLE_INTERNAL') || die(); 26 27 global $CFG; 28 29 /** 30 * Class report_outline_lib_testcase 31 * 32 * @package report_outline 33 * @copyright 2014 onwards Ankit agarwal <ankit.agrr@gmail.com> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. 35 */ 36 class report_outline_lib_testcase extends advanced_testcase { 37 38 /** 39 * @var stdClass The user. 40 */ 41 private $user; 42 43 /** 44 * @var stdClass The course. 45 */ 46 private $course; 47 48 /** 49 * @var context_course Course context. 50 */ 51 private $coursecontext; 52 53 /** 54 * @var \core_user\output\myprofile\tree The navigation tree. 55 */ 56 private $tree; 57 58 /** 59 * @var int Dummy role for testing. 60 */ 61 private $roleid; 62 63 public function setUp(): void { 64 $this->user = $this->getDataGenerator()->create_user(); 65 $this->user2 = $this->getDataGenerator()->create_user(); 66 $this->course = $this->getDataGenerator()->create_course(); 67 $this->tree = new \core_user\output\myprofile\tree(); 68 $this->coursecontext = context_course::instance($this->course->id); 69 $this->roleid = create_role('Dummy role', 'dummyrole', 'dummy role description'); 70 $this->resetAfterTest(); 71 } 72 73 /** 74 * Test report_log_supports_logstore. 75 */ 76 public function test_report_participation_supports_logstore() { 77 $logmanager = get_log_manager(); 78 $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); 79 80 $supportedstores = array( 81 'logstore_legacy' => '\logstore_legacy\log\store', 82 'logstore_standard' => '\logstore_standard\log\store' 83 ); 84 85 // Make sure all supported stores are installed. 86 $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); 87 $stores = $logmanager->get_supported_logstores('report_outline'); 88 $stores = array_keys($stores); 89 foreach ($expectedstores as $expectedstore) { 90 $this->assertContains($expectedstore, $stores); 91 } 92 } 93 94 /** 95 * Tests the report_outline_myprofile_navigation() function as an admin user. 96 */ 97 public function test_report_outline_myprofile_navigation() { 98 $this->setAdminUser(); 99 $iscurrentuser = false; 100 101 report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 102 $reflector = new ReflectionObject($this->tree); 103 $nodes = $reflector->getProperty('nodes'); 104 $nodes->setAccessible(true); 105 $this->assertArrayHasKey('outline', $nodes->getValue($this->tree)); 106 $this->assertArrayHasKey('complete', $nodes->getValue($this->tree)); 107 } 108 109 /** 110 * Tests the report_outline_myprofile_navigation() function as a user without permission. 111 */ 112 public function test_report_outline_myprofile_navigation_without_permission() { 113 $this->setUser($this->user); 114 $iscurrentuser = true; 115 116 report_outline_myprofile_navigation($this->tree, $this->user, $iscurrentuser, $this->course); 117 $reflector = new ReflectionObject($this->tree); 118 $nodes = $reflector->getProperty('nodes'); 119 $nodes->setAccessible(true); 120 $this->assertArrayNotHasKey('outline', $nodes->getValue($this->tree)); 121 $this->assertArrayNotHasKey('complete', $nodes->getValue($this->tree)); 122 } 123 124 /** 125 * Test that the current user can not access user report without report/outline:viewuserreport permission. 126 */ 127 public function test_report_outline_can_not_access_user_report_without_viewuserreport_permission() { 128 $this->getDataGenerator()->role_assign($this->roleid, $this->user->id, $this->coursecontext->id); 129 $this->setUser($this->user); 130 131 $this->assertFalse(report_outline_can_access_user_report($this->user, $this->course)); 132 } 133 134 /** 135 * Test that the current user can access user report with report/outline:viewuserreport permission. 136 */ 137 public function test_report_outline_can_access_user_report_with_viewuserreport_permission() { 138 assign_capability('report/outline:viewuserreport', CAP_ALLOW, $this->roleid, $this->coursecontext->id, true); 139 $this->getDataGenerator()->role_assign($this->roleid, $this->user->id, $this->coursecontext->id); 140 $this->setUser($this->user); 141 142 $this->assertTrue(report_outline_can_access_user_report($this->user, $this->course)); 143 } 144 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body