Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 27... Línea 27...
27
class htmlpurifier_test extends \basic_testcase {
27
class htmlpurifier_test extends \basic_testcase {
Línea 28... Línea 28...
28
 
28
 
29
    /**
29
    /**
30
     * Verify _blank target is allowed.
30
     * Verify _blank target is allowed.
31
     */
31
     */
32
    public function test_allow_blank_target() {
32
    public function test_allow_blank_target(): void {
33
        // See MDL-52651 for an explanation as to why the rel="noreferrer" attribute is expected here.
33
        // See MDL-52651 for an explanation as to why the rel="noreferrer" attribute is expected here.
34
        // Also note we do not need to test links with an existing rel attribute as the HTML Purifier is configured to remove
34
        // Also note we do not need to test links with an existing rel attribute as the HTML Purifier is configured to remove
35
        // the rel attribute.
35
        // the rel attribute.
36
        $text = '<a href="http://moodle.org" target="_blank">Some link</a>';
36
        $text = '<a href="http://moodle.org" target="_blank">Some link</a>';
Línea 43... Línea 43...
43
    }
43
    }
Línea 44... Línea 44...
44
 
44
 
45
    /**
45
    /**
46
     * Verify our nolink tag accepted.
46
     * Verify our nolink tag accepted.
47
     */
47
     */
48
    public function test_nolink() {
48
    public function test_nolink(): void {
49
        // We can not use format text because nolink changes result.
49
        // We can not use format text because nolink changes result.
50
        $text = '<nolink><div>no filters</div></nolink>';
50
        $text = '<nolink><div>no filters</div></nolink>';
51
        $result = purify_html($text, array());
51
        $result = purify_html($text, array());
Línea 62... Línea 62...
62
    }
62
    }
Línea 63... Línea 63...
63
 
63
 
64
    /**
64
    /**
65
     * Verify our tex tag accepted.
65
     * Verify our tex tag accepted.
66
     */
66
     */
67
    public function test_tex() {
67
    public function test_tex(): void {
68
        $text = '<tex>a+b=c</tex>';
68
        $text = '<tex>a+b=c</tex>';
69
        $result = purify_html($text, array());
69
        $result = purify_html($text, array());
70
        $this->assertSame($text, $result);
70
        $this->assertSame($text, $result);
Línea 71... Línea 71...
71
    }
71
    }
72
 
72
 
73
    /**
73
    /**
74
     * Verify our algebra tag accepted.
74
     * Verify our algebra tag accepted.
75
     */
75
     */
76
    public function test_algebra() {
76
    public function test_algebra(): void {
77
        $text = '<algebra>a+b=c</algebra>';
77
        $text = '<algebra>a+b=c</algebra>';
78
        $result = purify_html($text, array());
78
        $result = purify_html($text, array());
Línea 79... Línea 79...
79
        $this->assertSame($text, $result);
79
        $this->assertSame($text, $result);
80
    }
80
    }
81
 
81
 
82
    /**
82
    /**
83
     * Verify our hacky multilang works.
83
     * Verify our hacky multilang works.
84
     */
84
     */
85
    public function test_multilang() {
85
    public function test_multilang(): void {
Línea 86... Línea 86...
86
        $text = '<lang lang="en">hmmm</lang><lang lang="anything">hm</lang>';
86
        $text = '<lang lang="en">hmmm</lang><lang lang="anything">hm</lang>';
Línea 107... Línea 107...
107
    }
107
    }
Línea 108... Línea 108...
108
 
108
 
109
    /**
109
    /**
110
     * Tests the 'allowid' option for format_text.
110
     * Tests the 'allowid' option for format_text.
111
     */
111
     */
112
    public function test_format_text_allowid() {
112
    public function test_format_text_allowid(): void {
113
        // Start off by not allowing ids (default).
113
        // Start off by not allowing ids (default).
114
        $options = [
114
        $options = [
115
            'allowid' => false,
115
            'allowid' => false,
116
        ];
116
        ];
Línea 121... Línea 121...
121
        $options['allowid'] = true;
121
        $options['allowid'] = true;
122
        $result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
122
        $result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
123
        $this->assertSame('<div id="example">Frog</div>', $result);
123
        $this->assertSame('<div id="example">Frog</div>', $result);
124
    }
124
    }
Línea 125... Línea 125...
125
 
125
 
126
    public function test_allowobjectembed() {
126
    public function test_allowobjectembed(): void {
Línea 127... Línea 127...
127
        global $CFG;
127
        global $CFG;
Línea 128... Línea 128...
128
 
128
 
Línea 155... Línea 155...
155
    }
155
    }
Línea 156... Línea 156...
156
 
156
 
157
    /**
157
    /**
158
     * Test if linebreaks kept unchanged.
158
     * Test if linebreaks kept unchanged.
159
     */
159
     */
160
    public function test_line_breaking() {
160
    public function test_line_breaking(): void {
161
        $text = "\n\raa\rsss\nsss\r";
161
        $text = "\n\raa\rsss\nsss\r";
162
        $this->assertSame($text, purify_html($text));
162
        $this->assertSame($text, purify_html($text));
Línea 163... Línea 163...
163
    }
163
    }
164
 
164
 
165
    /**
165
    /**
166
     * Test fixing of strict problems.
166
     * Test fixing of strict problems.
167
     */
167
     */
168
    public function test_tidy() {
168
    public function test_tidy(): void {
Línea 169... Línea 169...
169
        $text = "<p>xx";
169
        $text = "<p>xx";
170
        $this->assertSame('<p>xx</p>', purify_html($text));
170
        $this->assertSame('<p>xx</p>', purify_html($text));
Línea 177... Línea 177...
177
    }
177
    }
Línea 178... Línea 178...
178
 
178
 
179
    /**
179
    /**
180
     * Test nesting - this used to cause problems in earlier versions.
180
     * Test nesting - this used to cause problems in earlier versions.
181
     */
181
     */
182
    public function test_nested_lists() {
182
    public function test_nested_lists(): void {
183
        $text = "<ul><li>One<ul><li>Two</li></ul></li><li>Three</li></ul>";
183
        $text = "<ul><li>One<ul><li>Two</li></ul></li><li>Three</li></ul>";
184
        $this->assertSame($text, purify_html($text));
184
        $this->assertSame($text, purify_html($text));
Línea 185... Línea 185...
185
    }
185
    }
186
 
186
 
187
    /**
187
    /**
188
     * Test that XSS protection works, complete smoke tests are in htmlpurifier itself.
188
     * Test that XSS protection works, complete smoke tests are in htmlpurifier itself.
189
     */
189
     */
190
    public function test_cleaning_nastiness() {
190
    public function test_cleaning_nastiness(): void {
Línea 191... Línea 191...
191
        $text = "x<SCRIPT>alert('XSS')</SCRIPT>x";
191
        $text = "x<SCRIPT>alert('XSS')</SCRIPT>x";
192
        $this->assertSame('xx', purify_html($text));
192
        $this->assertSame('xx', purify_html($text));
Línea 211... Línea 211...
211
    }
211
    }
Línea 212... Línea 212...
212
 
212
 
213
    /**
213
    /**
214
     * Test internal function used for clean_text() speedup.
214
     * Test internal function used for clean_text() speedup.
215
     */
215
     */
216
    public function test_is_purify_html_necessary() {
216
    public function test_is_purify_html_necessary(): void {
217
        // First our shortcuts.
217
        // First our shortcuts.
218
        $text = "";
218
        $text = "";
219
        $this->assertFalse(is_purify_html_necessary($text));
219
        $this->assertFalse(is_purify_html_necessary($text));
Línea 265... Línea 265...
265
 
265
 
266
        $text = "<p>abc";
266
        $text = "<p>abc";
267
        $this->assertTrue(is_purify_html_necessary($text));
267
        $this->assertTrue(is_purify_html_necessary($text));
Línea 268... Línea 268...
268
    }
268
    }
269
 
269
 
270
    public function test_allowed_schemes() {
270
    public function test_allowed_schemes(): void {
271
        // First standard schemas.
271
        // First standard schemas.
Línea 272... Línea 272...
272
        $text = '<a href="http://www.example.com/course/view.php?id=5">link</a>';
272
        $text = '<a href="http://www.example.com/course/view.php?id=5">link</a>';
Línea 315... Línea 315...
315
    }
315
    }
Línea 316... Línea 316...
316
 
316
 
317
    /**
317
    /**
318
     * Test non-ascii domain names
318
     * Test non-ascii domain names
319
     */
319
     */
Línea 320... Línea 320...
320
    public function test_idn() {
320
    public function test_idn(): void {
321
 
321
 
322
        // Example of domain that gives the same result in IDNA2003 and IDNA2008 .
322
        // Example of domain that gives the same result in IDNA2003 and IDNA2008 .
323
        $text = '<a href="http://правительство.рф">правительство.рф</a>';
323
        $text = '<a href="http://правительство.рф">правительство.рф</a>';
Línea 343... Línea 343...
343
     *
343
     *
344
     * @dataProvider media_tags_provider
344
     * @dataProvider media_tags_provider
345
     * @param string $mediatag HTML media tag
345
     * @param string $mediatag HTML media tag
346
     * @param string $expected expected result
346
     * @param string $expected expected result
347
     */
347
     */
348
    public function test_media_tags($mediatag, $expected) {
348
    public function test_media_tags($mediatag, $expected): void {
349
        $actual = format_text($mediatag, FORMAT_MOODLE, ['filter' => false]);
349
        $actual = format_text($mediatag, FORMAT_MOODLE, ['filter' => false]);
350
        $this->assertEquals($expected, $actual);
350
        $this->assertEquals($expected, $actual);
351
    }
351
    }
Línea 352... Línea 352...
352
 
352