Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 * Fixture for mocking callbacks used in \core_course_category 19 * 20 * @package core_course 21 * @category test 22 * @copyright 2020 Ruslan Kabalin 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace tests\core_course { 27 28 /** 29 * Class mock_hooks 30 * 31 * @package core_course 32 * @category test 33 * @copyright 2020 Ruslan Kabalin 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class mock_hooks { 37 /** @var bool $cancoursecategorydelete */ 38 private static $cancoursecategorydelete = true; 39 40 /** @var bool $cancoursecategorydeletemove */ 41 private static $cancoursecategorydeletemove = true; 42 43 /** @var string $getcoursecategorycontents */ 44 private static $getcoursecategorycontents = ''; 45 46 /** @var array $callingarguments */ 47 private static $callingarguments = []; 48 49 /** 50 * Set calling arguments. 51 * 52 * This is supposed to be used in the callbacks to store arguments passed to callback. 53 * 54 * @param array $callingarguments 55 */ 56 public static function set_calling_arguments($callingarguments) { 57 self::$callingarguments = $callingarguments; 58 } 59 60 /** 61 * Get calling arguments. 62 * 63 * This is supposed to be used in the test to verify arguments passed to callback. 64 * This method also reset stored calling arguments. 65 * 66 * @return array $callingarguments 67 */ 68 public static function get_calling_arguments() { 69 $callingarguments = self::$callingarguments; 70 self::$callingarguments = []; 71 return $callingarguments; 72 } 73 74 /** 75 * Get can_course_category_delete callback return. 76 * 77 * @return bool 78 */ 79 public static function get_can_course_category_delete_return() : bool { 80 return self::$cancoursecategorydelete; 81 } 82 83 /** 84 * Sets can_course_category_delete callback return. 85 * 86 * @param bool $return 87 */ 88 public static function set_can_course_category_delete_return(bool $return) { 89 self::$cancoursecategorydelete = $return; 90 } 91 92 /** 93 * Get can_course_category_delete_move callback return. 94 * 95 * @return bool 96 */ 97 public static function get_can_course_category_delete_move_return() : bool { 98 return self::$cancoursecategorydeletemove; 99 } 100 101 /** 102 * Sets can_course_category_delete_move callback return. 103 * 104 * @param bool $return 105 */ 106 public static function set_can_course_category_delete_move_return(bool $return) { 107 self::$cancoursecategorydeletemove = $return; 108 } 109 110 /** 111 * Get get_course_category_contents callback return. 112 * 113 * @return string 114 */ 115 public static function get_get_course_category_contents_return() : string { 116 return self::$getcoursecategorycontents; 117 } 118 119 /** 120 * Sets get_course_category_contents callback return. 121 * 122 * @param string $return 123 */ 124 public static function set_get_course_category_contents_return(string $return) { 125 self::$getcoursecategorycontents = $return; 126 } 127 } 128 } 129 130 namespace { 131 132 /** 133 * Test pre_course_category_delete callback. 134 * 135 * @param object $category 136 */ 137 function tool_unittest_pre_course_category_delete(object $category) { 138 \tests\core_course\mock_hooks::set_calling_arguments(func_get_args()); 139 } 140 141 /** 142 * Test pre_course_category_delete_move callback. 143 * 144 * @param core_course_category $category 145 * @param core_course_category $newcategory 146 */ 147 function tool_unittest_pre_course_category_delete_move(core_course_category $category, core_course_category $newcategory) { 148 \tests\core_course\mock_hooks::set_calling_arguments(func_get_args()); 149 } 150 151 /** 152 * Test can_course_category_delete callback. 153 * 154 * @param core_course_category $category 155 * @return bool 156 */ 157 function tool_unittest_can_course_category_delete(core_course_category $category) { 158 \tests\core_course\mock_hooks::set_calling_arguments(func_get_args()); 159 return \tests\core_course\mock_hooks::get_can_course_category_delete_return(); 160 } 161 162 /** 163 * Test can_course_category_delete_move callback. 164 * 165 * @param core_course_category $category 166 * @param core_course_category $newcategory 167 * @return bool 168 */ 169 function tool_unittest_can_course_category_delete_move(core_course_category $category, core_course_category $newcategory) { 170 \tests\core_course\mock_hooks::set_calling_arguments(func_get_args()); 171 return \tests\core_course\mock_hooks::get_can_course_category_delete_move_return(); 172 } 173 174 /** 175 * Test get_course_category_contents callback. 176 * 177 * @param core_course_category $category 178 * @return string 179 */ 180 function tool_unittest_get_course_category_contents(core_course_category $category) { 181 \tests\core_course\mock_hooks::set_calling_arguments(func_get_args()); 182 return \tests\core_course\mock_hooks::get_get_course_category_contents_return(); 183 } 184 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body