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   * Unit tests for the upgradelib of the Display H5P filter.
  19   *
  20   * @package    filter_displayh5p
  21   * @category   test
  22   * @copyright  2019 Carlos Escobedo <carlos@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  require_once($CFG->dirroot . '/filter/displayh5p/db/upgradelib.php');
  30  require_once("$CFG->libdir/filterlib.php");
  31  
  32  /**
  33   * Unit tests for the upgradelib of the Display H5P filter.
  34   *
  35   * @copyright 2019 Carlos Escobedo <carlos@moodle.com>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class filter_displayh5p_upgradelib_testcase extends advanced_testcase {
  39  
  40      /**
  41       * test_filter_displayh5p_reorder
  42       */
  43      public function test_filter_displayh5p_reorder() {
  44          $this->resetAfterTest(true);
  45          $this->setAdminUser();
  46  
  47          // We disable the three filters involved to reorder.
  48          // To do this, we will enable them in order and so they will be placed sorted.
  49          filter_set_global_state('displayh5p', TEXTFILTER_DISABLED);
  50          filter_set_global_state('activitynames', TEXTFILTER_DISABLED);
  51          filter_set_global_state('urltolink', TEXTFILTER_DISABLED);
  52          // First, we enabled activitynames and urltolink.
  53          // So, displayh5p will be below them.
  54          filter_set_global_state('activitynames', TEXTFILTER_ON);
  55          filter_set_global_state('urltolink', TEXTFILTER_ON);
  56  
  57          // We get the new order of the filter.
  58          $states = filter_get_global_states();
  59          $displayh5ppos = $states['displayh5p']->sortorder;
  60          $activitynamespos = $states['activitynames']->sortorder;
  61          $urltolinkpos = $states['urltolink']->sortorder;
  62  
  63          // Make sure that activitynames and urltolink are over the displayh5p.
  64          $this->assertLessThan($displayh5ppos, $activitynamespos);
  65          $this->assertLessThan($displayh5ppos, $urltolinkpos);
  66  
  67          // Call the function to reorder displayh5p.
  68          filter_displayh5p_reorder();
  69          // Get the new orders.
  70          $states = filter_get_global_states();
  71          $displayh5ppos = $states['displayh5p']->sortorder;
  72          $activitynamespos = $states['activitynames']->sortorder;
  73          $urltolinkpos = $states['urltolink']->sortorder;
  74          // Make sure that displayh5p are over activitynames and urltolink.
  75          $this->assertLessThan($activitynamespos, $displayh5ppos);
  76          $this->assertLessThan($urltolinkpos, $displayh5ppos);
  77  
  78          // Make sure that displayh5p is enabled.
  79          $this->assertEquals(TEXTFILTER_ON, $states['displayh5p']->active);
  80      }
  81  }