1 |
efrain |
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 |
namespace filter_displayh5p;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
global $CFG;
|
|
|
22 |
require_once($CFG->dirroot . '/filter/displayh5p/db/upgradelib.php');
|
|
|
23 |
require_once("$CFG->libdir/filterlib.php");
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Unit tests for the upgradelib of the Display H5P filter.
|
|
|
27 |
*
|
|
|
28 |
* @package filter_displayh5p
|
|
|
29 |
* @category test
|
|
|
30 |
* @copyright 2019 Carlos Escobedo <carlos@moodle.com>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
1441 |
ariadna |
33 |
final class upgradelib_test extends \advanced_testcase {
|
1 |
efrain |
34 |
|
|
|
35 |
/**
|
|
|
36 |
* test_filter_displayh5p_reorder
|
|
|
37 |
*/
|
11 |
efrain |
38 |
public function test_filter_displayh5p_reorder(): void {
|
1 |
efrain |
39 |
$this->resetAfterTest(true);
|
|
|
40 |
$this->setAdminUser();
|
|
|
41 |
|
|
|
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);
|
|
|
51 |
|
|
|
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;
|
|
|
57 |
|
|
|
58 |
// Make sure that activitynames and urltolink are over the displayh5p.
|
|
|
59 |
$this->assertLessThan($displayh5ppos, $activitynamespos);
|
|
|
60 |
$this->assertLessThan($displayh5ppos, $urltolinkpos);
|
|
|
61 |
|
|
|
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);
|
|
|
72 |
|
|
|
73 |
// Make sure that displayh5p is enabled.
|
|
|
74 |
$this->assertEquals(TEXTFILTER_ON, $states['displayh5p']->active);
|
|
|
75 |
}
|
|
|
76 |
}
|