|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/filter/mediaplugin/filter.php'); // Include the code to test 00030 00034 class filter_mediaplugin_test extends UnitTestCase { 00035 00036 function test_filter_mediaplugin_link() { 00037 global $CFG; 00038 00039 // we need to enable the plugins somehow 00040 $oldcfg = clone($CFG); // very, very ugly hack 00041 $CFG->filter_mediaplugin_enable_youtube = 1; 00042 $CFG->filter_mediaplugin_enable_vimeo = 1; 00043 $CFG->filter_mediaplugin_enable_mp3 = 1; 00044 $CFG->filter_mediaplugin_enable_flv = 1; 00045 $CFG->filter_mediaplugin_enable_swf = 1; 00046 $CFG->filter_mediaplugin_enable_html5audio = 1; 00047 $CFG->filter_mediaplugin_enable_html5video = 1; 00048 $CFG->filter_mediaplugin_enable_qt = 1; 00049 $CFG->filter_mediaplugin_enable_wmp = 1; 00050 $CFG->filter_mediaplugin_enable_rm = 1; 00051 00052 00053 $filterplugin = new filter_mediaplugin(null, array()); 00054 00055 $validtexts = array ( 00056 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 00057 '<a href="http://moodle.org/testfile/test.ogg">test ogg</a>', 00058 '<a id="movie player" class="center" href="http://moodle.org/testfile/test.mpg">test mpg</a>', 00059 '<a href="http://moodle.org/testfile/test.ram">test</a>', 00060 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>', 00061 '<a class="youtube" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', 00062 '<a class="_blanktarget" href="http://moodle.org/testfile/test.flv?d=100x100">test flv</a>', 00063 '<a class="hrefcss" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', 00064 '<a class="content" href="http://moodle.org/testfile/test.avi">test mp3</a>', 00065 '<a id="audio" href="http://moodle.org/testfile/test.mp3">test mp3</a>', 00066 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 00067 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 00068 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200">youtube\'s</a>', 00069 '<a 00070 href="http://moodle.org/testfile/test.mp3"> 00071 test mp3</a>', 00072 '<a class="content" 00073 00074 00075 href="http://moodle.org/testfile/test.avi">test mp3 00076 </a>', 00077 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200" >youtube\'s</a>' 00078 ); 00079 00080 //test for valid link 00081 foreach ($validtexts as $text) { 00082 $msg = "Testing text: ". $text; 00083 $filter = $filterplugin->filter($text); 00084 $this->assertNotEqual($text, $filter, $msg); 00085 } 00086 00087 $invalidtexts = array( 00088 '<a class="_blanktarget">href="http://moodle.org/testfile/test.mp3"</a>', 00089 '<a>test test</a>', 00090 '<a >test test</a>', 00091 '<a >test test</a>', 00092 '<a >test test</a>', 00093 '<ahref="http://moodle.org/testfile/test.mp3">sample</a>', 00094 '<a href="" test></a>', 00095 '<a href="http://www.moodle.com/path/to?#param=29">test</a>', 00096 '<a href="http://moodle.org/testfile/test.mp3">test mp3', 00097 '<a href="http://moodle.org/testfile/test.mp3"test</a>', 00098 '<a href="http://moodle.org/testfile/">test</a>', 00099 '<href="http://moodle.org/testfile/test.avi">test</a>', 00100 '<abbr href="http://moodle.org/testfile/test.mp3">test mp3</abbr>', 00101 '<ahref="http://moodle.org/testfile/test.mp3">test mp3</a>', 00102 '<aclass="content" href="http://moodle.org/testfile/test.mp3">test mp3</a>' 00103 ); 00104 00105 //test for invalid link 00106 foreach ($invalidtexts as $text) { 00107 $msg = "Testing text: ". $text; 00108 $filter = $filterplugin->filter($text); 00109 $this->assertEqual($text, $filter, $msg); 00110 } 00111 00112 $CFG = $oldcfg; // very, very ugly hack 00113 } 00114 }