Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310]

   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   * Contains the class containing unit tests for the calendar cron task.
  19   *
  20   * @package   core
  21   * @copyright 2017 Mark Nelson <markn@moodle.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  require_once($CFG->dirroot . '/calendar/lib.php');
  29  
  30  /**
  31   * Class containing unit tests for the calendar cron task.
  32   *
  33   * @package core
  34   * @copyright 2017 Mark Nelson <markn@moodle.com>
  35   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class core_calendar_cron_task_testcase extends advanced_testcase {
  38  
  39      /**
  40       * Tests set up
  41       */
  42      protected function setUp(): void {
  43          $this->resetAfterTest();
  44      }
  45  
  46      /**
  47       * Test calendar cron task with a working subscription URL.
  48       */
  49      public function test_cron_working_url() {
  50          // ICal URL from external test repo.
  51          $subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
  52  
  53          $subscription = new stdClass();
  54          $subscription->eventtype = 'site';
  55          $subscription->name = 'test';
  56          $subscription->url = $subscriptionurl;
  57          $subscription->pollinterval = 86400;
  58          $subscription->lastupdated = 0;
  59          calendar_add_subscription($subscription);
  60  
  61          $this->expectOutputRegex('/Events imported: .* Events skipped: .* Events updated:/');
  62          $task = new \core\task\calendar_cron_task();
  63          $task->execute();
  64      }
  65  
  66      /**
  67       * Test calendar cron task with a broken subscription URL.
  68       */
  69      public function test_cron_broken_url() {
  70          $subscription = new stdClass();
  71          $subscription->eventtype = 'site';
  72          $subscription->name = 'test';
  73          $subscription->url = 'brokenurl';
  74          $subscription->pollinterval = 86400;
  75          $subscription->lastupdated = 0;
  76          calendar_add_subscription($subscription);
  77  
  78          $this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/');
  79          $task = new \core\task\calendar_cron_task();
  80          $task->execute();
  81      }
  82  }