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 * File containing tests for the mform class. 19 * 20 * @package tool_task 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 * Mform test class. 31 * 32 * @package tool_task 33 * @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late 35 */ 36 class tool_task_form_testcase extends advanced_testcase { 37 38 /** 39 * Test validations for minute field. 40 */ 41 public function test_validate_fields_minute() { 42 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '*'); 43 $this->assertTrue($valid); 44 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '1'); 45 $this->assertTrue($valid); 46 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '20'); 47 $this->assertTrue($valid); 48 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '65'); 49 $this->assertFalse($valid); 50 51 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '*/'); 52 $this->assertFalse($valid); 53 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '*/1'); 54 $this->assertTrue($valid); 55 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '*/20'); 56 $this->assertTrue($valid); 57 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '*/65'); 58 $this->assertFalse($valid); 59 60 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '1,2'); 61 $this->assertTrue($valid); 62 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '2,20'); 63 $this->assertTrue($valid); 64 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '20,30,45'); 65 $this->assertTrue($valid); 66 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '65,20,30'); 67 $this->assertFalse($valid); 68 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '25,75'); 69 $this->assertFalse($valid); 70 71 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '1-2'); 72 $this->assertTrue($valid); 73 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '2-20'); 74 $this->assertTrue($valid); 75 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '20-30'); 76 $this->assertTrue($valid); 77 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '65-20'); 78 $this->assertFalse($valid); 79 $valid = \tool_task_edit_scheduled_task_form::validate_fields('minute', '25-75'); 80 $this->assertFalse($valid); 81 } 82 83 /** 84 * Test validations for minute hour. 85 */ 86 public function test_validate_fields_hour() { 87 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '*'); 88 $this->assertTrue($valid); 89 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '1'); 90 $this->assertTrue($valid); 91 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '20'); 92 $this->assertTrue($valid); 93 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '65'); 94 $this->assertFalse($valid); 95 96 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '*/'); 97 $this->assertFalse($valid); 98 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '*/1'); 99 $this->assertTrue($valid); 100 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '*/20'); 101 $this->assertTrue($valid); 102 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '*/65'); 103 $this->assertFalse($valid); 104 105 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '1,2'); 106 $this->assertTrue($valid); 107 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '2,20'); 108 $this->assertTrue($valid); 109 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '20,30,45'); 110 $this->assertTrue($valid); 111 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '65,20,30'); 112 $this->assertFalse($valid); 113 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '25,75'); 114 $this->assertFalse($valid); 115 116 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '1-2'); 117 $this->assertTrue($valid); 118 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '2-20'); 119 $this->assertTrue($valid); 120 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '20-30'); 121 $this->assertTrue($valid); 122 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '65-20'); 123 $this->assertFalse($valid); 124 $valid = \tool_task_edit_scheduled_task_form::validate_fields('hour', '25-75'); 125 $this->assertFalse($valid); 126 } 127 128 /** 129 * Test validations for day field. 130 */ 131 public function test_validate_fields_day() { 132 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*'); 133 $this->assertTrue($valid); 134 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '1'); 135 $this->assertTrue($valid); 136 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '20'); 137 $this->assertTrue($valid); 138 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '65'); 139 $this->assertFalse($valid); 140 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '35'); 141 $this->assertFalse($valid); 142 143 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*/'); 144 $this->assertFalse($valid); 145 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*/1'); 146 $this->assertTrue($valid); 147 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*/20'); 148 $this->assertTrue($valid); 149 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*/65'); 150 $this->assertFalse($valid); 151 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '*/35'); 152 $this->assertFalse($valid); 153 154 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '1,2'); 155 $this->assertTrue($valid); 156 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '2,20'); 157 $this->assertTrue($valid); 158 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '20,30,25'); 159 $this->assertTrue($valid); 160 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '65,20,30'); 161 $this->assertFalse($valid); 162 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '25,35'); 163 $this->assertFalse($valid); 164 165 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '1-2'); 166 $this->assertTrue($valid); 167 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '2-20'); 168 $this->assertTrue($valid); 169 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '20-30'); 170 $this->assertTrue($valid); 171 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '65-20'); 172 $this->assertFalse($valid); 173 $valid = \tool_task_edit_scheduled_task_form::validate_fields('day', '25-35'); 174 $this->assertFalse($valid); 175 } 176 177 /** 178 * Test validations for month field. 179 */ 180 public function test_validate_fields_month() { 181 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*'); 182 $this->assertTrue($valid); 183 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '1'); 184 $this->assertTrue($valid); 185 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '10'); 186 $this->assertTrue($valid); 187 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '13'); 188 $this->assertFalse($valid); 189 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '35'); 190 $this->assertFalse($valid); 191 192 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*/'); 193 $this->assertFalse($valid); 194 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*/1'); 195 $this->assertTrue($valid); 196 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*/12'); 197 $this->assertTrue($valid); 198 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*/13'); 199 $this->assertFalse($valid); 200 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '*/35'); 201 $this->assertFalse($valid); 202 203 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '1,2'); 204 $this->assertTrue($valid); 205 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '2,11'); 206 $this->assertTrue($valid); 207 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '2,10,12'); 208 $this->assertTrue($valid); 209 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '65,2,13'); 210 $this->assertFalse($valid); 211 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '25,35'); 212 $this->assertFalse($valid); 213 214 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '1-2'); 215 $this->assertTrue($valid); 216 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '2-12'); 217 $this->assertTrue($valid); 218 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '3-6'); 219 $this->assertTrue($valid); 220 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '65-2'); 221 $this->assertFalse($valid); 222 $valid = \tool_task_edit_scheduled_task_form::validate_fields('month', '25-26'); 223 $this->assertFalse($valid); 224 } 225 226 /** 227 * Test validations for dayofweek field. 228 */ 229 public function test_validate_fields_dayofweek() { 230 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*'); 231 $this->assertTrue($valid); 232 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '0'); 233 $this->assertTrue($valid); 234 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '1'); 235 $this->assertTrue($valid); 236 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '6'); 237 $this->assertTrue($valid); 238 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '7'); 239 $this->assertFalse($valid); 240 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '20'); 241 $this->assertFalse($valid); 242 243 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*/'); 244 $this->assertFalse($valid); 245 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*/1'); 246 $this->assertTrue($valid); 247 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*/6'); 248 $this->assertTrue($valid); 249 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*/13'); 250 $this->assertFalse($valid); 251 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '*/35'); 252 $this->assertFalse($valid); 253 254 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '1,2'); 255 $this->assertTrue($valid); 256 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '2,6'); 257 $this->assertTrue($valid); 258 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '2,6,3'); 259 $this->assertTrue($valid); 260 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '65,2,13'); 261 $this->assertFalse($valid); 262 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '25,35'); 263 $this->assertFalse($valid); 264 265 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '1-2'); 266 $this->assertTrue($valid); 267 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '2-6'); 268 $this->assertTrue($valid); 269 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '65-2'); 270 $this->assertFalse($valid); 271 $valid = \tool_task_edit_scheduled_task_form::validate_fields('dayofweek', '3-7'); 272 $this->assertFalse($valid); 273 } 274 } 275
title
Description
Body
title
Description
Body
title
Description
Body
title
Body