forked from moodleou/moodle-mod_ouwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsections_test.php
70 lines (61 loc) · 2.11 KB
/
sections_test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* OUWiki unit tests - test locallib functions
*
* @package mod_ouwiki
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
global $CFG;
require_once($CFG->dirroot . '/mod/ouwiki/locallib.php');
class ouwiki_test_sections extends advanced_testcase {
public $sample = '
<h1 id="ouw_s0_0">Start</h1>
x
x<h1>No section ID</h1>x
x<h1 id="ouw_sly">Invalid section ID</h1>x
x<h1 id="ouw_s13_x">Invalid section ID</h1>x
x<h1 id="ouw_s13_13">Non-match heading tags</h2>x
x<h1 id="ouw_s1_666">Valid section heading</h1>x
x<h2 id="ouw_s2_666">Test&</h2>x
x<h3 id="ouw_s3_666">Test<span class="frog">whatever</span></h3>x
x<h4 id="ouw_s4_666">
Test
spacing
and stuff
</h4>x
x<h5 id="ouw_s5_666">V5</h5>x
x<h6 id="ouw_s6_666">V6</h6>x
x
<h1 id="ouw_s0_1">End</h1>';
public function test_find_sections() {
$sections = ouwiki_find_sections($this->sample);
$this->assertEquals(array(
'0_0' => 'Start',
'1_666' => 'Valid section heading',
'2_666' => 'Test&',
'3_666' => 'Testwhatever',
'4_666' => 'Test spacing and stuff',
'5_666' => 'V5',
'6_666' => 'V6',
'0_1' => 'End'
), $sections);
}
}