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
 * @license   http://www.gnu.org/copyleft/gpl.html GNU Public License
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU Public License
28
 * @covers ::format_text
28
 * @covers ::format_text
29
 */
29
 */
30
class weblib_format_text_test extends \advanced_testcase {
30
class weblib_format_text_test extends \advanced_testcase {
Línea 31... Línea 31...
31
 
31
 
32
    public function test_format_text_format_html() {
32
    public function test_format_text_format_html(): void {
33
        $this->resetAfterTest();
33
        $this->resetAfterTest();
34
        filter_set_global_state('emoticon', TEXTFILTER_ON);
34
        filter_set_global_state('emoticon', TEXTFILTER_ON);
35
        $this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" title="smile" ' .
35
        $this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" title="smile" ' .
36
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" /></p>$~',
36
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" /></p>$~',
37
                format_text('<p>:-)</p>', FORMAT_HTML));
37
                format_text('<p>:-)</p>', FORMAT_HTML));
Línea 38... Línea 38...
38
    }
38
    }
39
 
39
 
40
    public function test_format_text_format_html_no_filters() {
40
    public function test_format_text_format_html_no_filters(): void {
41
        $this->resetAfterTest();
41
        $this->resetAfterTest();
42
        filter_set_global_state('emoticon', TEXTFILTER_ON);
42
        filter_set_global_state('emoticon', TEXTFILTER_ON);
43
        $this->assertEquals('<p>:-)</p>',
43
        $this->assertEquals('<p>:-)</p>',
Línea 44... Línea 44...
44
                format_text('<p>:-)</p>', FORMAT_HTML, array('filter' => false)));
44
                format_text('<p>:-)</p>', FORMAT_HTML, array('filter' => false)));
45
    }
45
    }
46
 
46
 
47
    public function test_format_text_format_plain() {
47
    public function test_format_text_format_plain(): void {
48
        // Note FORMAT_PLAIN does not filter ever, no matter we ask for filtering.
48
        // Note FORMAT_PLAIN does not filter ever, no matter we ask for filtering.
49
        $this->resetAfterTest();
49
        $this->resetAfterTest();
50
        filter_set_global_state('emoticon', TEXTFILTER_ON);
50
        filter_set_global_state('emoticon', TEXTFILTER_ON);
Línea 51... Línea 51...
51
        $this->assertEquals(':-)',
51
        $this->assertEquals(':-)',
52
                format_text(':-)', FORMAT_PLAIN));
52
                format_text(':-)', FORMAT_PLAIN));
53
    }
53
    }
54
 
54
 
55
    public function test_format_text_format_plain_no_filters() {
55
    public function test_format_text_format_plain_no_filters(): void {
56
        $this->resetAfterTest();
56
        $this->resetAfterTest();
Línea 57... Línea 57...
57
        filter_set_global_state('emoticon', TEXTFILTER_ON);
57
        filter_set_global_state('emoticon', TEXTFILTER_ON);
58
        $this->assertEquals(':-)',
58
        $this->assertEquals(':-)',
59
                format_text(':-)', FORMAT_PLAIN, array('filter' => false)));
59
                format_text(':-)', FORMAT_PLAIN, array('filter' => false)));
60
    }
60
    }
61
 
61
 
62
    public function test_format_text_format_markdown() {
62
    public function test_format_text_format_markdown(): void {
63
        $this->resetAfterTest();
63
        $this->resetAfterTest();
64
        filter_set_global_state('emoticon', TEXTFILTER_ON);
64
        filter_set_global_state('emoticon', TEXTFILTER_ON);
Línea 65... Línea 65...
65
        $this->assertMatchesRegularExpression('~^<p><em><img class="icon emoticon" alt="smile" title="smile" ' .
65
        $this->assertMatchesRegularExpression('~^<p><em><img class="icon emoticon" alt="smile" title="smile" ' .
66
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" />' .
66
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" />' .
67
                '</em></p>\n$~',
67
                '</em></p>\n$~',
68
                format_text('*:-)*', FORMAT_MARKDOWN));
68
                format_text('*:-)*', FORMAT_MARKDOWN));
69
    }
69
    }
70
 
70
 
Línea 71... Línea 71...
71
    public function test_format_text_format_markdown_nofilter() {
71
    public function test_format_text_format_markdown_nofilter(): void {
72
        $this->resetAfterTest();
72
        $this->resetAfterTest();
73
        filter_set_global_state('emoticon', TEXTFILTER_ON);
73
        filter_set_global_state('emoticon', TEXTFILTER_ON);
74
        $this->assertEquals("<p><em>:-)</em></p>\n",
74
        $this->assertEquals("<p><em>:-)</em></p>\n",
75
                format_text('*:-)*', FORMAT_MARKDOWN, array('filter' => false)));
75
                format_text('*:-)*', FORMAT_MARKDOWN, array('filter' => false)));
76
    }
76
    }
77
 
77
 
78
    public function test_format_text_format_moodle() {
78
    public function test_format_text_format_moodle(): void {
Línea 79... Línea 79...
79
        $this->resetAfterTest();
79
        $this->resetAfterTest();
80
        filter_set_global_state('emoticon', TEXTFILTER_ON);
80
        filter_set_global_state('emoticon', TEXTFILTER_ON);
81
        $this->assertMatchesRegularExpression('~^<div class="text_to_html"><p>' .
81
        $this->assertMatchesRegularExpression('~^<div class="text_to_html"><p>' .
82
                '<img class="icon emoticon" alt="smile" title="smile" ' .
82
                '<img class="icon emoticon" alt="smile" title="smile" ' .
83
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" /></p></div>$~',
83
                'src="https://www.example.com/moodle/theme/image.php/boost/core/1/s/smiley" /></p></div>$~',
84
                format_text('<p>:-)</p>', FORMAT_MOODLE));
84
                format_text('<p>:-)</p>', FORMAT_MOODLE));
Línea 85... Línea 85...
85
    }
85
    }
86
 
86
 
87
    public function test_format_text_format_moodle_no_filters() {
87
    public function test_format_text_format_moodle_no_filters(): void {
88
        $this->resetAfterTest();
88
        $this->resetAfterTest();
89
        filter_set_global_state('emoticon', TEXTFILTER_ON);
89
        filter_set_global_state('emoticon', TEXTFILTER_ON);
90
        $this->assertEquals('<div class="text_to_html"><p>:-)</p></div>',
90
        $this->assertEquals('<div class="text_to_html"><p>:-)</p></div>',
91
                format_text('<p>:-)</p>', FORMAT_MOODLE, array('filter' => false)));
91
                format_text('<p>:-)</p>', FORMAT_MOODLE, array('filter' => false)));
Línea 92... Línea 92...
92
    }
92
    }
Línea 125... Línea 125...
125
        $this->assertSame(
125
        $this->assertSame(
126
            '<p><span class="nolink">Read Test 1.</span></p>',
126
            '<p><span class="nolink">Read Test 1.</span></p>',
127
            format_text('<p><span class="nolink">Read Test 1.</span></p>', FORMAT_HTML, ['context' => $context]));
127
            format_text('<p><span class="nolink">Read Test 1.</span></p>', FORMAT_HTML, ['context' => $context]));
128
    }
128
    }
Línea 129... Línea 129...
129
 
129
 
130
    public function test_format_text_overflowdiv() {
130
    public function test_format_text_overflowdiv(): void {
131
        $this->assertEquals('<div class="no-overflow"><p>Hello world</p></div>',
131
        $this->assertEquals('<div class="no-overflow"><p>Hello world</p></div>',
132
                format_text('<p>Hello world</p>', FORMAT_HTML, array('overflowdiv' => true)));
132
                format_text('<p>Hello world</p>', FORMAT_HTML, array('overflowdiv' => true)));
Línea 133... Línea 133...
133
    }
133
    }
Línea 137... Línea 137...
137
     *
137
     *
138
     * @dataProvider format_text_blanktarget_testcases
138
     * @dataProvider format_text_blanktarget_testcases
139
     * @param string $link The link to add target="_blank" to
139
     * @param string $link The link to add target="_blank" to
140
     * @param string $expected The expected filter value
140
     * @param string $expected The expected filter value
141
     */
141
     */
142
    public function test_format_text_blanktarget($link, $expected) {
142
    public function test_format_text_blanktarget($link, $expected): void {
143
        $actual = format_text($link, FORMAT_MOODLE, array('blanktarget' => true, 'filter' => false, 'noclean' => true));
143
        $actual = format_text($link, FORMAT_MOODLE, array('blanktarget' => true, 'filter' => false, 'noclean' => true));
144
        $this->assertEquals($expected, $actual);
144
        $this->assertEquals($expected, $actual);
145
    }
145
    }
Línea 146... Línea 146...
146
 
146
 
Línea 202... Línea 202...
202
     *
202
     *
203
     * @param string $input Input text
203
     * @param string $input Input text
204
     * @param string $nocleaned Expected output of format_text() with noclean=true
204
     * @param string $nocleaned Expected output of format_text() with noclean=true
205
     * @param string $cleaned Expected output of format_text() with noclean=false
205
     * @param string $cleaned Expected output of format_text() with noclean=false
206
     */
206
     */
207
    public function test_format_text_cleaning($input, $nocleaned, $cleaned) {
207
    public function test_format_text_cleaning($input, $nocleaned, $cleaned): void {
208
        global $CFG;
208
        global $CFG;
209
        $this->resetAfterTest();
209
        $this->resetAfterTest();
Línea 210... Línea 210...
210
 
210
 
211
        $CFG->forceclean = false;
211
        $CFG->forceclean = false;