Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 39 and 402]

   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.
  13  //
  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/>.
  16  
  17  namespace core;
  18  
  19  /**
  20   * Test markdown text format.
  21   *
  22   * This is not a complete markdown test, it just validates
  23   * Moodle integration works.
  24   *
  25   * See http://daringfireball.net/projects/markdown/basics
  26   * for more format information.
  27   *
  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
  32   */
  33  class markdown_test extends \basic_testcase {
  34  
  35      public function test_paragraphs() {
  36          $text = "one\n\ntwo";
  37          $result = "<p>one</p>\n\n<p>two</p>\n";
  38          $this->assertSame($result, markdown_to_html($text));
  39      }
  40  
  41      public function test_headings() {
  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));
  45      }
  46  
  47      public function test_lists() {
  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));
  51      }
  52  
  53      public function test_links() {
  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));
  57      }
  58  
  59      public function test_tabs() {
  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));
  63      }
  64  }