Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   * File containing the forum module local library function tests.
  19   *
  20   * @package    mod_forum
  21   * @category   test
  22   * @copyright  2018 Shamim Rezaie <shamim@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  
  30  require_once($CFG->dirroot . '/mod/forum/lib.php');
  31  
  32  /**
  33   * Class mod_forum_locallib_testcase.
  34   *
  35   * @copyright  2018 Shamim Rezaie <shamim@moodle.com>
  36   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class mod_forum_locallib_testcase extends advanced_testcase {
  39      public function test_forum_update_calendar() {
  40          global $DB;
  41  
  42          $this->resetAfterTest();
  43  
  44          $this->setAdminUser();
  45  
  46          // Create a course.
  47          $course = $this->getDataGenerator()->create_course();
  48  
  49          // Create a forum activity.
  50          $time = time();
  51          $forum = $this->getDataGenerator()->create_module('forum',
  52                  array(
  53                      'course' => $course->id,
  54                      'duedate' => $time
  55                  )
  56          );
  57  
  58          // Check that there is now an event in the database.
  59          $events = $DB->get_records('event');
  60          $this->assertCount(1, $events);
  61  
  62          // Get the event.
  63          $event = reset($events);
  64  
  65          // Confirm the event is correct.
  66          $this->assertEquals('forum', $event->modulename);
  67          $this->assertEquals($forum->id, $event->instance);
  68          $this->assertEquals(CALENDAR_EVENT_TYPE_ACTION, $event->type);
  69          $this->assertEquals(FORUM_EVENT_TYPE_DUE, $event->eventtype);
  70          $this->assertEquals($time, $event->timestart);
  71          $this->assertEquals($time, $event->timesort);
  72      }
  73  }