Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 29... Línea 29...
29
class html2text_test extends \basic_testcase {
29
class html2text_test extends \basic_testcase {
Línea 30... Línea 30...
30
 
30
 
31
    /**
31
    /**
32
     * ALT as image replacements.
32
     * ALT as image replacements.
33
     */
33
     */
34
    public function test_images() {
34
    public function test_images(): void {
Línea 35... Línea 35...
35
        $this->assertSame('[edit]', html_to_text('<img src="edit.png" alt="edit" />'));
35
        $this->assertSame('[edit]', html_to_text('<img src="edit.png" alt="edit" />'));
36
 
36
 
37
        $text = 'xx<img src="gif.gif" alt="some gif" />xx';
37
        $text = 'xx<img src="gif.gif" alt="some gif" />xx';
38
        $result = html_to_text($text, null, false, false);
38
        $result = html_to_text($text, null, false, false);
Línea 39... Línea 39...
39
        $this->assertSame($result, 'xx[some gif]xx');
39
        $this->assertSame($result, 'xx[some gif]xx');
40
    }
40
    }
41
 
41
 
42
    /**
42
    /**
43
     * No magic quotes messing.
43
     * No magic quotes messing.
Línea 44... Línea 44...
44
     */
44
     */
45
    public function test_no_strip_slashes() {
45
    public function test_no_strip_slashes(): void {
46
        $this->assertSame('[\edit]', html_to_text('<img src="edit.png" alt="\edit" />'));
46
        $this->assertSame('[\edit]', html_to_text('<img src="edit.png" alt="\edit" />'));
47
 
47
 
Línea 48... Línea 48...
48
        $text = '\\magic\\quotes\\are\\\\horrible';
48
        $text = '\\magic\\quotes\\are\\\\horrible';
49
        $result = html_to_text($text, null, false, false);
49
        $result = html_to_text($text, null, false, false);
50
        $this->assertSame($result, $text);
50
        $this->assertSame($result, $text);
51
    }
51
    }
52
 
52
 
53
    /**
53
    /**
54
     * core_text integration.
54
     * core_text integration.
55
     */
55
     */
Línea 56... Línea 56...
56
    public function test_core_text() {
56
    public function test_core_text(): void {
57
        $text = '<strong>Žluťoučký koníček</strong>';
57
        $text = '<strong>Žluťoučký koníček</strong>';
58
        $result = html_to_text($text, null, false, false);
58
        $result = html_to_text($text, null, false, false);
59
        $this->assertSame($result, 'ŽLUŤOUČKÝ KONÍČEK');
59
        $this->assertSame($result, 'ŽLUŤOUČKÝ KONÍČEK');
60
    }
60
    }
61
 
61
 
62
    /**
62
    /**
Línea 63... Línea 63...
63
     * Protect 0.
63
     * Protect 0.
64
     */
64
     */
Línea 65... Línea 65...
65
    public function test_zero() {
65
    public function test_zero(): void {
66
        $text = '0';
66
        $text = '0';
67
        $result = html_to_text($text, null, false, false);
67
        $result = html_to_text($text, null, false, false);
68
        $this->assertSame($result, $text);
68
        $this->assertSame($result, $text);
Línea 69... Línea 69...
69
 
69
 
70
        $this->assertSame('0', html_to_text('0'));
70
        $this->assertSame('0', html_to_text('0'));
71
    }
71
    }
72
 
72
 
Línea 110... Línea 110...
110
    }
110
    }
Línea 111... Línea 111...
111
 
111
 
112
    /**
112
    /**
113
     * Various invalid HTML typed by users that ignore html strict.
113
     * Various invalid HTML typed by users that ignore html strict.
114
     **/
114
     **/
115
    public function test_invalid_html() {
115
    public function test_invalid_html(): void {
116
        $text = 'Gin & Tonic';
116
        $text = 'Gin & Tonic';
117
        $result = html_to_text($text, null, false, false);
117
        $result = html_to_text($text, null, false, false);
Línea 118... Línea 118...
118
        $this->assertSame($result, $text);
118
        $this->assertSame($result, $text);
Línea 127... Línea 127...
127
    }
127
    }
Línea 128... Línea 128...
128
 
128
 
129
    /**
129
    /**
130
     * Basic text formatting.
130
     * Basic text formatting.
131
     */
131
     */
132
    public function test_simple() {
132
    public function test_simple(): void {
133
        $this->assertSame("_Hello_ WORLD!\n", html_to_text('<p><i>Hello</i> <b>world</b>!</p>'));
133
        $this->assertSame("_Hello_ WORLD!\n", html_to_text('<p><i>Hello</i> <b>world</b>!</p>'));
134
        $this->assertSame("All the WORLD’S a stage.\n\n-- William Shakespeare\n", html_to_text('<p>All the <strong>world’s</strong> a stage.</p><p>-- William Shakespeare</p>'));
134
        $this->assertSame("All the WORLD’S a stage.\n\n-- William Shakespeare\n", html_to_text('<p>All the <strong>world’s</strong> a stage.</p><p>-- William Shakespeare</p>'));
135
        $this->assertSame("HELLO WORLD!\n\n", html_to_text('<h1>Hello world!</h1>'));
135
        $this->assertSame("HELLO WORLD!\n\n", html_to_text('<h1>Hello world!</h1>'));
136
        $this->assertSame("Hello\nworld!", html_to_text('Hello<br />world!'));
136
        $this->assertSame("Hello\nworld!", html_to_text('Hello<br />world!'));
Línea 137... Línea 137...
137
    }
137
    }
138
 
138
 
139
    /**
139
    /**
140
     * Test line wrapping.
140
     * Test line wrapping.
141
     */
141
     */
142
    public function test_text_nowrap() {
142
    public function test_text_nowrap(): void {
143
        $long = "Here is a long string, more than 75 characters long, since by default html_to_text wraps text at 75 chars.";
143
        $long = "Here is a long string, more than 75 characters long, since by default html_to_text wraps text at 75 chars.";
144
        $wrapped = "Here is a long string, more than 75 characters long, since by default\nhtml_to_text wraps text at 75 chars.";
144
        $wrapped = "Here is a long string, more than 75 characters long, since by default\nhtml_to_text wraps text at 75 chars.";
145
        $this->assertSame($long, html_to_text($long, 0));
145
        $this->assertSame($long, html_to_text($long, 0));
Línea 146... Línea 146...
146
        $this->assertSame($wrapped, html_to_text($long));
146
        $this->assertSame($wrapped, html_to_text($long));
147
    }
147
    }
148
 
148
 
149
    /**
149
    /**
150
     * Whitespace removal.
150
     * Whitespace removal.
151
     */
151
     */
Línea 152... Línea 152...
152
    public function test_trailing_whitespace() {
152
    public function test_trailing_whitespace(): void {
153
        $this->assertSame('With trailing whitespace and some more text', html_to_text("With trailing whitespace   \nand some   more text", 0));
153
        $this->assertSame('With trailing whitespace and some more text', html_to_text("With trailing whitespace   \nand some   more text", 0));
154
    }
154
    }
155
 
155
 
156
    /**
156
    /**
157
     * PRE parsing.
157
     * PRE parsing.
158
     */
158
     */
Línea 159... Línea 159...
159
    public function test_html_to_text_pre_parsing_problem() {
159
    public function test_html_to_text_pre_parsing_problem(): void {
Línea 179... Línea 179...
179
    }
179
    }
Línea 180... Línea 180...
180
 
180
 
181
    /**
181
    /**
182
     * Scripts should be stripped.
182
     * Scripts should be stripped.
183
     */
183
     */
184
    public function test_strip_scripts() {
184
    public function test_strip_scripts(): void {
185
        $this->assertSame('Interesting text',
185
        $this->assertSame('Interesting text',
186
                html_to_text('Interesting <script type="text/javascript">var what_a_mess = "Yuck!";</script> text', 0));
186
                html_to_text('Interesting <script type="text/javascript">var what_a_mess = "Yuck!";</script> text', 0));
187
    }
187
    }