forked from erikrose/mediawiki-parser
/
test_html_postprocessor.py
57 lines (45 loc) · 2.39 KB
/
test_html_postprocessor.py
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
# -*- coding: utf8 -*-
from mediawiki_parser.tests import PostprocessorTestCase
class HTMLBackendTests(PostprocessorTestCase):
def test_simple_title2(self):
source = '== A title ==\n'
result = "<h2> A title </h2>\n"
self.parsed_equal_string(source, result, 'wikitext', {}, 'html')
def test_simple_title6(self):
source = '====== Test! ======\n'
result = "<h6> Test! </h6>\n"
self.parsed_equal_string(source, result, 'wikitext', {}, 'html')
def test_simple_allowed_open_tag(self):
source = 'a<span>test'
result = 'a<span>test'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_complex_allowed_open_tag(self):
""" The postprocessor should remove the disallowed attributes. """
source = '<span class="wikitext" style="color:red" onclick="javascript:alert()">'
result = '<span class="wikitext" style="color:red">'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_simple_disallowed_open_tag(self):
source = 'another <a> test'
result = 'another <a> test'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_complex_disallowed_open_tag(self):
""" The postprocessor doesn't remove the disallowed attributes, but outputs everything as text. """
source = '<a href="test" class="test" style="color:red" anything="anything">'
result = '<a href="test" class="test" style="color:red" anything="anything">'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_simple_allowed_autoclose_tag(self):
source = 'a<br />test'
result = 'a<br />test'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_complex_allowed_autoclose_tag(self):
source = 'one more <br name="test" /> test'
result = 'one more <br name="test" /> test'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_simple_disallowed_autoclose_tag(self):
source = 'a<test />test'
result = 'a<test />test'
self.parsed_equal_string(source, result, 'inline', {}, 'html')
def test_complex_disallowed_autoclose_tag(self):
source = '<img src="file.png" />'
result = '<img src="file.png" />'
self.parsed_equal_string(source, result, 'inline', {}, 'html')