[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/calendar/tests/ -> lib_test.php (source)

   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 <dan@moodle.com>
  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 <dan@moodle.com>
  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          // ICal URL from external test repo.
  82          $subscriptionurl = $this->getExternalTestFileUrl('/ical.ics');
  83  
  84          $subscription = new stdClass();
  85          $subscription->eventtype = 'site';
  86          $subscription->name = 'test';
  87          $subscription->url = $subscriptionurl;
  88          $subscription->pollinterval = 86400;
  89          $subscription->lastupdated = 0;
  90          calendar_add_subscription($subscription);
  91  
  92          $this->expectOutputRegex('/Events imported: .* Events updated:/');
  93          calendar_cron();
  94      }
  95  
  96      /**
  97       * Test calendar cron with a broken subscription URL.
  98       */
  99      public function test_calendar_cron_broken_url() {
 100          global $CFG;
 101          require_once($CFG->dirroot . '/lib/cronlib.php');
 102  
 103          $subscription = new stdClass();
 104          $subscription->eventtype = 'site';
 105          $subscription->name = 'test';
 106          $subscription->url = 'brokenurl';
 107          $subscription->pollinterval = 86400;
 108          $subscription->lastupdated = 0;
 109          calendar_add_subscription($subscription);
 110  
 111          $this->expectOutputRegex('/Error updating calendar subscription: The given iCal URL is invalid/');
 112          calendar_cron();
 113      }
 114  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1