[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/filter/emoticon/tests/ -> filter_test.php (source)

   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   * Skype icons filter phpunit tests
  19   *
  20   * @package    filter_emoticon
  21   * @category   test
  22   * @copyright  2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  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/emoticon/filter.php'); // Include the code to test.
  30  
  31  /**
  32   * Skype icons filter testcase.
  33   */
  34  class filter_emoticon_testcase extends advanced_testcase {
  35  
  36      /**
  37       * Verify configured target formats are observed. Just that.
  38       */
  39      public function test_filter_emoticon_formats() {
  40  
  41          $this->resetAfterTest(true); // We are modifying the config.
  42  
  43          $filter = new testable_filter_emoticon();
  44  
  45          // Verify texts not matching target formats aren't filtered.
  46          $expected = '(grr)';
  47          $options = array('originalformat' => FORMAT_MOODLE); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
  48          $this->assertEquals($expected, $filter->filter('(grr)', $options));
  49  
  50          $options = array('originalformat' => FORMAT_MARKDOWN); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
  51          $this->assertEquals($expected, $filter->filter('(grr)', $options));
  52  
  53          $options = array('originalformat' => FORMAT_PLAIN); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
  54          $this->assertEquals($expected, $filter->filter('(grr)', $options));
  55  
  56          // And texts matching target formats are filtered.
  57          $expected = '<img class="emoticon" alt="angry" title="angry"'.
  58                      ' src="http://www.example.com/moodle/theme/image.php/_s/clean/core/1/s/angry" />';
  59          $options = array('originalformat' => FORMAT_HTML); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
  60          $this->assertEquals($expected, $filter->filter('(grr)', $options));
  61      }
  62  }
  63  
  64  /**
  65   * Subclass for easier testing.
  66   */
  67  class testable_filter_emoticon extends filter_emoticon {
  68      public function __construct() {
  69          // Use this context for filtering.
  70          $this->context = context_system::instance();
  71          // Define FORMAT_HTML as only one filtering in DB.
  72          set_config('formats', implode(',', array(FORMAT_HTML)), 'filter_emoticon');
  73      }
  74  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1