. /** * Unit test for the filter_mediaplugin * * @package filter * @subpackage Mediaplugin * @copyright 2011 Rossiani Wijaya * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/filter/mediaplugin/filter.php'); // Include the code to test /** * Test cases for filter_mediaplugin class */ class filter_mediaplugin_test extends UnitTestCase { function test_filter_mediaplugin_link() { global $CFG; // we need to enable the plugins somehow $oldcfg = clone($CFG); // very, very ugly hack $CFG->filter_mediaplugin_enable_youtube = 1; $CFG->filter_mediaplugin_enable_vimeo = 1; $CFG->filter_mediaplugin_enable_mp3 = 1; $CFG->filter_mediaplugin_enable_flv = 1; $CFG->filter_mediaplugin_enable_swf = 1; $CFG->filter_mediaplugin_enable_html5audio = 1; $CFG->filter_mediaplugin_enable_html5video = 1; $CFG->filter_mediaplugin_enable_qt = 1; $CFG->filter_mediaplugin_enable_wmp = 1; $CFG->filter_mediaplugin_enable_rm = 1; $filterplugin = new filter_mediaplugin(null, array()); $validtexts = array ( 'test mp3', 'test ogg', 'test mpg', 'test', 'test file', 'test file', 'test file', 'test file', 'test file', 'test flv', 'test file', 'test mp3', 'test mp3', 'test mp3', 'test mp3', 'youtube\'s', ' test mp3', 'test mp3 ', 'youtube\'s' ); //test for valid link foreach ($validtexts as $text) { $msg = "Testing text: ". $text; $filter = $filterplugin->filter($text); $this->assertNotEqual($text, $filter, $msg); } $invalidtexts = array( 'href="http://moodle.org/testfile/test.mp3"', 'test test', 'test test', 'test test', 'test test', 'sample', '', 'test', 'test mp3', '', 'test', 'test', 'test mp3', 'test mp3', 'test mp3' ); //test for invalid link foreach ($invalidtexts as $text) { $msg = "Testing text: ". $text; $filter = $filterplugin->filter($text); $this->assertEqual($text, $filter, $msg); } $CFG = $oldcfg; // very, very ugly hack } }