MDL-45813 Fix variable name in scheduled task
authorDavid Mudrák <david@moodle.com>
Tue, 3 Jun 2014 11:16:44 +0000 (13:16 +0200)
committerDavid Mudrák <david@moodle.com>
Mon, 9 Jun 2014 07:46:13 +0000 (09:46 +0200)
lib/classes/task/scheduled_task.php
lib/tests/scheduled_task_test.php

index f7fb050..47e93c7 100644 (file)
@@ -340,7 +340,7 @@ abstract class scheduled_task extends task_base {
         // otherwise - choose the soonest (see man 5 cron).
         if ($this->dayofweek == '*') {
             $daysincrement = $daysincrementbymonth;
-        } else if ($this->dayofmonth == '*') {
+        } else if ($this->day == '*') {
             $daysincrement = $daysincrementbyweek;
         } else {
             // Take the smaller increment of days by month or week.
index e60b99a..c29e7f8 100644 (file)
@@ -90,6 +90,28 @@ class core_scheduled_task_testcase extends advanced_testcase {
         $testclass->set_disabled(true);
         $nexttime = $testclass->get_next_scheduled_time();
         $this->assertEquals($nexttenminutes, $nexttime, 'Next scheduled time is in 10 minutes.');
+
+        // Test hourly job executed on Sundays only.
+        $testclass = new \core\task\scheduled_test_task();
+        $testclass->set_minute('0');
+        $testclass->set_day_of_week('7');
+
+        $nexttime = $testclass->get_next_scheduled_time();
+
+        $this->assertEquals(7, date('N', $nexttime));
+        $this->assertEquals(0, date('i', $nexttime));
+
+        // Test monthly job
+        $testclass = new \core\task\scheduled_test_task();
+        $testclass->set_minute('32');
+        $testclass->set_hour('0');
+        $testclass->set_day('1');
+
+        $nexttime = $testclass->get_next_scheduled_time();
+
+        $this->assertEquals(32, date('i', $nexttime));
+        $this->assertEquals(0, date('G', $nexttime));
+        $this->assertEquals(1, date('j', $nexttime));
     }
 
     public function test_timezones() {