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