Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 32]

       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      public function test_calendar_update_subscription() {
      49          $this->resetAfterTest(true);
      50  
      51          $subscription = new stdClass();
      52          $subscription->eventtype = 'site';
      53          $subscription->name = 'test';
      54          $id = calendar_add_subscription($subscription);
      55  
      56          $subscription = new stdClass();
      57          $subscription->id = $id;
      58          $subscription->name = 'awesome';
      59          calendar_update_subscription($subscription);
      60          $sub = calendar_get_subscription($id);
      61          $this->assertEquals($subscription->name, $sub->name);
      62  
      63          $subscription = new stdClass();
      64          $subscription->id = $id;
      65          $subscription->name = 'awesome2';
      66          $subscription->pollinterval = 604800;
      67          calendar_update_subscription($subscription);
      68          $sub = calendar_get_subscription($id);
      69          $this->assertEquals($subscription->name, $sub->name);
      70          $this->assertEquals($subscription->pollinterval, $sub->pollinterval);
      71  
      72          $subscription = new stdClass();
      73          $subscription->name = 'awesome4';
      74          $this->setExpectedException('coding_exception');
      75          calendar_update_subscription($subscription);
      76      }
      77  
      78      public function test_calendar_add_subscription() {
      79          global $DB, $CFG;
      80  
      81          require_once($CFG->dirroot . '/lib/bennu/bennu.inc.php');
      82  
      83          $this->resetAfterTest(true);
      84  
      85          // Test for Microsoft Outlook 2010.
      86          $subscription = new stdClass();
      87          $subscription->name = 'Microsoft Outlook 2010';
      88          $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
      89          $subscription->eventtype = 'site';
      90          $id = calendar_add_subscription($subscription);
      91  
      92          $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/ms_outlook_2010.ics');
      93          $ical = new iCalendar();
      94          $ical->unserialize($calendar);
      95          $this->assertEquals($ical->parser_errors, array());
      96  
      97          $sub = calendar_get_subscription($id);
      98          $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
      99          $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     100          $this->assertEquals($count, 1);
     101  
     102          // Test for OSX Yosemite.
     103          $subscription = new stdClass();
     104          $subscription->name = 'OSX Yosemite';
     105          $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
     106          $subscription->eventtype = 'site';
     107          $id = calendar_add_subscription($subscription);
     108  
     109          $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/osx_yosemite.ics');
     110          $ical = new iCalendar();
     111          $ical->unserialize($calendar);
     112          $this->assertEquals($ical->parser_errors, array());
     113  
     114          $sub = calendar_get_subscription($id);
     115          $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
     116          $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     117          $this->assertEquals($count, 1);
     118  
     119          // Test for Google Gmail.
     120          $subscription = new stdClass();
     121          $subscription->name = 'Google Gmail';
     122          $subscription->importfrom = CALENDAR_IMPORT_FROM_FILE;
     123          $subscription->eventtype = 'site';
     124          $id = calendar_add_subscription($subscription);
     125  
     126          $calendar = file_get_contents($CFG->dirroot . '/lib/tests/fixtures/google_gmail.ics');
     127          $ical = new iCalendar();
     128          $ical->unserialize($calendar);
     129          $this->assertEquals($ical->parser_errors, array());
     130  
     131          $sub = calendar_get_subscription($id);
     132          $result = calendar_import_icalendar_events($ical, $sub->courseid, $sub->id);
     133          $count = $DB->count_records('event', array('subscriptionid' => $sub->id));
     134          $this->assertEquals($count, 1);
     135      }
     136  }
    

    Search This Site: