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