MDL-58454 badges: Fix some minor errors for Open Badges v2
[moodle.git] / lib / tests / calendar_cron_task_test.php
blobf17ab150eced1ff048aa08572e4b9908d97f4512
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.
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/>.
17 /**
18 * Contains the class containing unit tests for the calendar cron task.
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
25 defined('MOODLE_INTERNAL') || die();
27 global $CFG;
28 require_once($CFG->dirroot . '/calendar/lib.php');
30 /**
31 * Class containing unit tests for the calendar cron task.
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
37 class core_calendar_cron_task_testcase extends advanced_testcase {
39 /**
40 * Tests set up
42 protected function setUp() {
43 $this->resetAfterTest();
46 /**
47 * Test calendar cron task with a working subscription URL.
49 public function test_cron_working_url() {
50 // ICal URL from external test repo.
51 $subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
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);
61 $this->expectOutputRegex('/Events imported: .* Events updated:/');
62 $task = new \core\task\calendar_cron_task();
63 $task->execute();
66 /**
67 * Test calendar cron task with a broken subscription URL.
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);
78 $this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/');
79 $task = new \core\task\calendar_cron_task();
80 $task->execute();