[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 * Calendar lib unit tests 19 * 20 * @package core_calendar 21 * @copyright 2013 Dan Poltawski <[email protected]> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 global $CFG; 27 require_once($CFG->dirroot . '/calendar/lib.php'); 28 29 /** 30 * Unit tests for calendar lib 31 * 32 * @package core_calendar 33 * @copyright 2013 Dan Poltawski <[email protected]> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class core_calendar_lib_testcase extends advanced_testcase { 37 38 protected function setUp() { 39 $this->resetAfterTest(true); 40 } 41 42 public function test_calendar_get_course_cached() { 43 // Setup some test courses. 44 $course1 = $this->getDataGenerator()->create_course(); 45 $course2 = $this->getDataGenerator()->create_course(); 46 $course3 = $this->getDataGenerator()->create_course(); 47 48 // Load courses into cache. 49 $coursecache = null; 50 calendar_get_course_cached($coursecache, $course1->id); 51 calendar_get_course_cached($coursecache, $course2->id); 52 calendar_get_course_cached($coursecache, $course3->id); 53 54 // Verify the cache. 55 $this->assertArrayHasKey($course1->id, $coursecache); 56 $cachedcourse1 = $coursecache[$course1->id]; 57 $this->assertEquals($course1->id, $cachedcourse1->id); 58 $this->assertEquals($course1->shortname, $cachedcourse1->shortname); 59 $this->assertEquals($course1->fullname, $cachedcourse1->fullname); 60 61 $this->assertArrayHasKey($course2->id, $coursecache); 62 $cachedcourse2 = $coursecache[$course2->id]; 63 $this->assertEquals($course2->id, $cachedcourse2->id); 64 $this->assertEquals($course2->shortname, $cachedcourse2->shortname); 65 $this->assertEquals($course2->fullname, $cachedcourse2->fullname); 66 67 $this->assertArrayHasKey($course3->id, $coursecache); 68 $cachedcourse3 = $coursecache[$course3->id]; 69 $this->assertEquals($course3->id, $cachedcourse3->id); 70 $this->assertEquals($course3->shortname, $cachedcourse3->shortname); 71 $this->assertEquals($course3->fullname, $cachedcourse3->fullname); 72 } 73 74 /** 75 * Test calendar cron with a working subscription URL. 76 */ 77 public function test_calendar_cron_working_url() { 78 global $CFG; 79 require_once($CFG->dirroot . '/lib/cronlib.php'); 80 81 // Moodle ICal URL (moodle.org events). 82 $presetwhat = 'all'; 83 $presettime = 'recentupcoming'; 84 $userid = 1; 85 $authtoken = 'a8bcfee2fb868a05357f650bd65dc0699b026524'; 86 $subscriptionurl = 'https://moodle.org/calendar/export_execute.php' 87 . '?preset_what='.$presetwhat.'&preset_time='.$presettime.'&userid='.$userid.'&authtoken='.$authtoken; 88 89 $subscription = new stdClass(); 90 $subscription->eventtype = 'site'; 91 $subscription->name = 'test'; 92 $subscription->url = $subscriptionurl; 93 $subscription->pollinterval = 86400; 94 $subscription->lastupdated = 0; 95 calendar_add_subscription($subscription); 96 97 $this->expectOutputRegex('/Events imported: .* Events updated:/'); 98 calendar_cron(); 99 } 100 101 /** 102 * Test calendar cron with a broken subscription URL. 103 */ 104 public function test_calendar_cron_broken_url() { 105 global $CFG; 106 require_once($CFG->dirroot . '/lib/cronlib.php'); 107 108 $subscription = new stdClass(); 109 $subscription->eventtype = 'site'; 110 $subscription->name = 'test'; 111 $subscription->url = 'brokenurl'; 112 $subscription->pollinterval = 86400; 113 $subscription->lastupdated = 0; 114 calendar_add_subscription($subscription); 115 116 $this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/'); 117 calendar_cron(); 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |