Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace filter_mathjaxloader;
17
namespace filter_mathjaxloader;
18
 
-
 
19
use filter_mathjaxloader;
-
 
20
 
-
 
21
defined('MOODLE_INTERNAL') || die();
-
 
Línea 22... Línea 18...
22
global $CFG;
18
 
23
require_once($CFG->dirroot.'/filter/mathjaxloader/filter.php');
19
use core\context\system as context_system;
24
 
20
 
25
/**
21
/**
26
 * Unit tests for the MathJax loader filter.
22
 * Unit tests for the MathJax loader filter.
27
 *
23
 *
28
 * @package   filter_mathjaxloader
24
 * @package   filter_mathjaxloader
-
 
25
 * @category  test
29
 * @category  test
26
 * @copyright 2018 Markku Riekkinen
30
 * @copyright 2018 Markku Riekkinen
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
32
 */
28
 * @covers \filter_mathjaxloader\text_filter
33
class filtermath_test extends \advanced_testcase {
29
 */
34
 
30
final class filtermath_test extends \advanced_testcase {
35
    /**
31
    /**
36
     * Test the functionality of {@link filter_mathjaxloader::filter()}.
32
     * Test the functionality of {@see text_filter::filter()}.
37
     *
-
 
38
     * @param string $inputtext The text given by the user.
33
     *
39
     * @param string $expected The expected output after filtering.
34
     * @param string $inputtext The text given by the user.
40
     *
35
     * @param string $expected The expected output after filtering.
41
     * @dataProvider math_filtering_inputs
36
     * @dataProvider math_filtering_inputs
42
     */
37
     */
43
    public function test_math_filtering($inputtext, $expected): void {
38
    public function test_math_filtering($inputtext, $expected): void {
Línea 44... Línea 39...
44
        $filter = new filter_mathjaxloader(\context_system::instance(), []);
39
        $filter = new text_filter(context_system::instance(), []);
45
        $this->assertEquals($expected, $filter->filter($inputtext));
40
        $this->assertEquals($expected, $filter->filter($inputtext));
46
    }
41
    }
47
 
42
 
48
    /**
43
    /**
49
     * Data provider for {@link self::test_math_filtering()}.
44
     * Data provider for {@link self::test_math_filtering()}.
-
 
45
     *
50
     *
46
     * @return array of [inputtext, expectedoutput] tuples.
51
     * @return array of [inputtext, expectedoutput] tuples.
47
     */
-
 
48
    public static function math_filtering_inputs(): array {
52
     */
49
        // phpcs:disable moodle.Files.LineLength.TooLong
53
    public function math_filtering_inputs() {
50
        return [
-
 
51
            // One inline formula.
Línea 54... Línea 52...
54
        return [
52
            [
-
 
53
                'Some inline math \\( y = x^2 \\).',
55
            // One inline formula.
54
                '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>',
56
            ['Some inline math \\( y = x^2 \\).',
55
            ],
57
            '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>'],
56
 
-
 
57
            // One inline and one display.
Línea 58... Línea 58...
58
 
58
            [
-
 
59
                'Some inline math \\( y = x^2 \\) and display formula \\[ S = \\sum_{n=1}^{\\infty} 2^n \\]',
59
            // One inline and one display.
60
                '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span> and '
60
            ['Some inline math \\( y = x^2 \\) and display formula \\[ S = \\sum_{n=1}^{\\infty} 2^n \\]',
61
                    . 'display formula <span class="nolink">\\[ S = \\sum_{n=1}^{\\infty} 2^n \\]</span></span>',
61
            '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span> and '
62
            ],
-
 
63
 
Línea 62... Línea 64...
62
                . 'display formula <span class="nolink">\\[ S = \\sum_{n=1}^{\\infty} 2^n \\]</span></span>'],
64
            // One display and one inline.
-
 
65
            [
63
 
66
                'Display formula \\[ S = \\sum_{n=1}^{\\infty} 2^n \\] and some inline math \\( y = x^2 \\).',
64
            // One display and one inline.
67
                '<span class="filter_mathjaxloader_equation">Display formula <span class="nolink">\\[ S = \\sum_{n=1}^{\\infty} 2^n \\]</span> and '
65
            ['Display formula \\[ S = \\sum_{n=1}^{\\infty} 2^n \\] and some inline math \\( y = x^2 \\).',
68
                    . 'some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>',
-
 
69
            ],
Línea 66... Línea 70...
66
            '<span class="filter_mathjaxloader_equation">Display formula <span class="nolink">\\[ S = \\sum_{n=1}^{\\infty} 2^n \\]</span> and '
70
 
-
 
71
            // One inline and one display (with dollars).
67
                . 'some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>'],
72
            [
68
 
73
                'Some inline math \\( y = x^2 \\) and display formula $$ S = \\sum_{n=1}^{\\infty} 2^n $$',
69
            // One inline and one display (with dollars).
74
                '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span> and '
-
 
75
                    . 'display formula <span class="nolink">$$ S = \\sum_{n=1}^{\\infty} 2^n $$</span></span>',
Línea 70... Línea 76...
70
            ['Some inline math \\( y = x^2 \\) and display formula $$ S = \\sum_{n=1}^{\\infty} 2^n $$',
76
            ],
-
 
77
 
71
            '<span class="filter_mathjaxloader_equation">Some inline math <span class="nolink">\\( y = x^2 \\)</span> and '
78
            // One display (with dollars) and one inline.
72
                . 'display formula <span class="nolink">$$ S = \\sum_{n=1}^{\\infty} 2^n $$</span></span>'],
79
            [
73
 
80
                'Display formula $$ S = \\sum_{n=1}^{\\infty} 2^n $$ and some inline math \\( y = x^2 \\).',
74
            // One display (with dollars) and one inline.
81
                '<span class="filter_mathjaxloader_equation">Display formula <span class="nolink">$$ S = \\sum_{n=1}^{\\infty} 2^n $$</span> and '
75
            ['Display formula $$ S = \\sum_{n=1}^{\\infty} 2^n $$ and some inline math \\( y = x^2 \\).',
82
                    . 'some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>',
-
 
83
            ],
Línea 76... Línea 84...
76
            '<span class="filter_mathjaxloader_equation">Display formula <span class="nolink">$$ S = \\sum_{n=1}^{\\infty} 2^n $$</span> and '
84
 
-
 
85
            // Inline math environment nested inside display environment (using a custom LaTex macro).
77
                . 'some inline math <span class="nolink">\\( y = x^2 \\)</span>.</span>'],
86
            [
78
 
87
                '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\] '
79
            // Inline math environment nested inside display environment (using a custom LaTex macro).
88
                    . 'Text with inline formula using the custom LaTex macro \\( a = \\NullF \\).',
80
            ['\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\] '
89
                '<span class="filter_mathjaxloader_equation"><span class="nolink">'
81
                . 'Text with inline formula using the custom LaTex macro \\( a = \\NullF \\).',
90
                    . '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\]</span> '
82
            '<span class="filter_mathjaxloader_equation"><span class="nolink">'
91
                    . 'Text with inline formula using the custom LaTex macro <span class="nolink">\\( a = \\NullF \\)</span>.</span>',
83
                . '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\]</span> '
92
            ],
-
 
93
 
Línea 84... Línea 94...
84
                . 'Text with inline formula using the custom LaTex macro <span class="nolink">\\( a = \\NullF \\)</span>.</span>'],
94
            // Nested environments and some more content.
-
 
95
            [
85
 
96
                '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\] '
86
            // Nested environments and some more content.
97
                    . 'Text with inline formula using the custom LaTex macro \\( a = \\NullF \\). Finally, a display formula '
87
            ['\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\] '
98
                    . '$$ b = \\NullF $$',
88
                . 'Text with inline formula using the custom LaTex macro \\( a = \\NullF \\). Finally, a display formula '
99
                '<span class="filter_mathjaxloader_equation"><span class="nolink">'
-
 
100
                    . '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\]</span> '
89
                . '$$ b = \\NullF $$',
101
                    . 'Text with inline formula using the custom LaTex macro <span class="nolink">\\( a = \\NullF \\)</span>. '
90
            '<span class="filter_mathjaxloader_equation"><span class="nolink">'
102
                    . 'Finally, a display formula <span class="nolink">$$ b = \\NullF $$</span></span>',
91
                . '\\[ \\newcommand{\\False}{\\mathsf{F}} \\newcommand{\\NullF}{\\fbox{\\(\\False\\)}} \\]</span> '
103
            ],