2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Skype icons filter phpunit tests
20 * @package filter_emoticon
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
26 defined('MOODLE_INTERNAL') || die();
29 require_once($CFG->dirroot . '/filter/emoticon/filter.php'); // Include the code to test.
32 * Skype icons filter testcase.
34 class filter_emoticon_testcase extends advanced_testcase {
37 * Verify configured target formats are observed. Just that.
39 public function test_filter_emoticon_formats() {
41 $this->resetAfterTest(true); // We are modifying the config.
43 $filter = new testable_filter_emoticon();
45 // Verify texts not matching target formats aren't filtered.
47 $options = array('originalformat' => FORMAT_MOODLE); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
48 $this->assertEquals($expected, $filter->filter('(grr)', $options));
50 $options = array('originalformat' => FORMAT_MARKDOWN); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
51 $this->assertEquals($expected, $filter->filter('(grr)', $options));
53 $options = array('originalformat' => FORMAT_PLAIN); // Only FORMAT_HTML is filtered, see {@link testable_filter_emoticon}.
54 $this->assertEquals($expected, $filter->filter('(grr)', $options));
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/standard/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));
65 * Subclass for easier testing.
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)), get_class($this));