[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 Ical unit tests 19 * 20 * @package core_calendar 21 * @copyright 2013 Ankit Agarwal 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 29 30 /** 31 * Unit tests for ical APIs. 32 * 33 * @package core_calendar 34 * @copyright 2013 Ankit Agarwal 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 * @since Moodle 2.5 37 */ 38 class core_calendar_ical_testcase extends advanced_testcase { 39 40 /** 41 * Tests set up 42 */ 43 protected function setUp() { 44 global $CFG; 45 require_once($CFG->dirroot . '/calendar/lib.php'); 46 } 47 48 /** 49 * @expectedException coding_exception 50 */ 51 public function test_calendar_update_subscription() { 52 $this->resetAfterTest(true); 53 54 $subscription = new stdClass(); 55 $subscription->eventtype = 'site'; 56 $subscription->name = 'test'; 57 $id = calendar_add_subscription($subscription); 58 59 $subscription = new stdClass(); 60 $subscription = calendar_get_subscription($id); 61 $subscription->name = 'awesome'; 62 calendar_update_subscription($subscription); 63 $sub = calendar_get_subscription($id); 64 $this->assertEquals($subscription->name, $sub->name); 65 66 $subscription = new stdClass(); 67 $subscription = calendar_get_subscription($id); 68 $subscription->name = 'awesome2'; 69 $subscription->pollinterval = 604800; 70 calendar_update_subscription($subscription); 71 $sub = calendar_get_subscription($id); 72 $this->assertEquals($subscription->name, $sub->name); 73 $this->assertEquals($subscription->pollinterval, $sub->pollinterval); 74 75 $subscription = new stdClass(); 76 $subscription->name = 'awesome4'; 77 calendar_update_subscription($subscription); 78 } 79 80 public function test_calendar_add_subscription() { 81 global $DB, $CFG; 82 83 require_once($CFG->dirroot . '/lib/bennu/bennu.inc.php'); 84 85 $this->resetAfterTest(true); 86 87 // Test for Microsoft Outlook 2010. 88 $subscription = new stdClass(); 89 $subscription->name = 'Microsoft Outlook 2010'; 90 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; 91 $subscription->eventtype = 'site'; 92 $id = calendar_add_subscription($subscription); 93 94 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics'); 95 $ical = new iCalendar(); 96 $ical->unserialize($calendar); 97 $this->assertEquals($ical->parser_errors, array()); 98 99 $sub = calendar_get_subscription($id); 100 $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); 101 $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); 102 $this->assertEquals($count, 1); 103 104 // Test for OSX Yosemite. 105 $subscription = new stdClass(); 106 $subscription->name = 'OSX Yosemite'; 107 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; 108 $subscription->eventtype = 'site'; 109 $id = calendar_add_subscription($subscription); 110 111 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics'); 112 $ical = new iCalendar(); 113 $ical->unserialize($calendar); 114 $this->assertEquals($ical->parser_errors, array()); 115 116 $sub = calendar_get_subscription($id); 117 $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); 118 $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); 119 $this->assertEquals($count, 1); 120 121 // Test for Google Gmail. 122 $subscription = new stdClass(); 123 $subscription->name = 'Google Gmail'; 124 $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE; 125 $subscription->eventtype = 'site'; 126 $id = calendar_add_subscription($subscription); 127 128 $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics'); 129 $ical = new iCalendar(); 130 $ical->unserialize($calendar); 131 $this->assertEquals($ical->parser_errors, array()); 132 133 $sub = calendar_get_subscription($id); 134 $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id); 135 $count = $DB->count_records('event', array('subscriptionid' => $sub->id)); 136 $this->assertEquals($count, 1); 137 } 138 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |