Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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  /**
  18   * Unit test for the filter_algebra
  19   *
  20   * @package    filter_algebra
  21   * @category   phpunit
  22   * @copyright  2012 Tim Hunt
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  require_once($CFG->dirroot . '/filter/algebra/filter.php');
  30  
  31  
  32  /**
  33   * Unit tests for filter_algebra.
  34   *
  35   * Note that this only tests some of the filter logic. It does not actually test
  36   * the normal case of the filter working, because I cannot make it work on my
  37   * test server, and if it does not work here, it probably does not also work
  38   * for other people. A failing test will be irritating noise.
  39   *
  40   * @copyright  2012 Tim Hunt
  41   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class filter_algebra_testcase extends basic_testcase {
  44  
  45      protected $filter;
  46  
  47      protected function setUp(): void {
  48          parent::setUp();
  49          $this->filter = new filter_algebra(context_system::instance(), array());
  50      }
  51  
  52      function test_algebra_filter_no_algebra() {
  53          $this->assertEquals('<p>Look no algebra!</p>',
  54                  $this->filter->filter('<p>Look no algebra!</p>'));
  55      }
  56  
  57  
  58      function test_algebra_filter_pluginfile() {
  59          $this->assertEquals('<img src="@@PLUGINFILE@@/photo.jpg">',
  60                  $this->filter->filter('<img src="@@PLUGINFILE@@/photo.jpg">'));
  61      }
  62  
  63      function test_algebra_filter_draftfile() {
  64          $this->assertEquals('<img src="@@DRAFTFILE@@/photo.jpg">',
  65                  $this->filter->filter('<img src="@@DRAFTFILE@@/photo.jpg">'));
  66      }
  67  
  68      function test_algebra_filter_unified_diff() {
  69          $diff = '
  70  diff -u -r1.1 Worksheet.php
  71  --- Worksheet.php   26 Sep 2003 04:18:02 -0000  1.1
  72  +++ Worksheet.php   18 Nov 2009 03:58:50 -0000
  73  @@ -1264,10 +1264,10 @@
  74           }
  75  
  76           // Strip the = or @ sign at the beginning of the formula string
  77  -        if (ereg("^=",$formula)) {
  78  +        if (preg_match("/^=/",$formula)) {
  79               $formula = preg_replace("/(^=)/","",$formula);
  80           }
  81  -        elseif(ereg("^@",$formula)) {
  82  +        elseif(preg_match("/^@/",$formula)) {
  83               $formula = preg_replace("/(^@)/","",$formula);
  84           }
  85           else {
  86  ';
  87          $this->assertEquals('<pre>' . $diff . '</pre>',
  88                  $this->filter->filter('<pre>' . $diff . '</pre>'));
  89      }
  90  }