Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

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