weekly release 4.5dev
[moodle.git] / lib / tests / markdown_test.php
blob5e3c053c2c408f3b78942c9906339e3511b1ea85
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
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/>.
17 namespace core;
19 /**
20 * Test markdown text format.
22 * This is not a complete markdown test, it just validates
23 * Moodle integration works.
25 * See http://daringfireball.net/projects/markdown/basics
26 * for more format information.
28 * @package core
29 * @category test
30 * @copyright 2012 Petr Skoda {@link http://skodak.org}
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class markdown_test extends \basic_testcase {
35 public function test_paragraphs(): void {
36 $text = "one\n\ntwo";
37 $result = "<p>one</p>\n\n<p>two</p>\n";
38 $this->assertSame($result, markdown_to_html($text));
41 public function test_headings(): void {
42 $text = "Header 1\n====================\n\n## Header 2";
43 $result = "<h1>Header 1</h1>\n\n<h2>Header 2</h2>\n";
44 $this->assertSame($result, markdown_to_html($text));
47 public function test_lists(): void {
48 $text = "* one\n* two\n* three\n";
49 $result = "<ul>\n<li>one</li>\n<li>two</li>\n<li>three</li>\n</ul>\n";
50 $this->assertSame($result, markdown_to_html($text));
53 public function test_links(): void {
54 $text = "some [example link](http://example.com/)";
55 $result = "<p>some <a href=\"http://example.com/\">example link</a></p>\n";
56 $this->assertSame($result, markdown_to_html($text));
59 public function test_tabs(): void {
60 $text = "a\tbb\tccc\tя\tюэ\t\tabcd\tabcde\tabcdef";
61 $result = "<p>a bb ccc я юэ 水 abcd abcde abcdef</p>\n";
62 $this->assertSame($result, markdown_to_html($text));