[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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_mediaplugin 19 * 20 * @package filter_mediaplugin 21 * @category phpunit 22 * @copyright 2011 Rossiani Wijaya <rwijaya@moodle.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/mediaplugin/filter.php'); // Include the code to test 30 31 32 class filter_mediaplugin_testcase extends advanced_testcase { 33 34 function test_filter_mediaplugin_link() { 35 global $CFG; 36 37 $this->resetAfterTest(true); 38 39 // we need to enable the plugins somehow 40 $CFG->core_media_enable_youtube = 1; 41 $CFG->core_media_enable_vimeo = 1; 42 $CFG->core_media_enable_mp3 = 1; 43 $CFG->core_media_enable_flv = 1; 44 $CFG->core_media_enable_swf = 1; 45 $CFG->core_media_enable_html5audio = 1; 46 $CFG->core_media_enable_html5video = 1; 47 $CFG->core_media_enable_qt = 1; 48 $CFG->core_media_enable_wmp = 1; 49 $CFG->core_media_enable_rm = 1; 50 51 52 $filterplugin = new filter_mediaplugin(null, array()); 53 54 $longurl = '<a href="http://moodle/.mp4">my test file</a>'; 55 $longhref = ''; 56 57 do { 58 $longhref .= 'a'; 59 } while(strlen($longhref) + strlen($longurl) < 4095); 60 61 $longurl = '<a href="http://moodle/' . $longhref . '.mp4">my test file</a>'; 62 63 $validtexts = array ( 64 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 65 '<a href="http://moodle.org/testfile/test.ogg">test ogg</a>', 66 '<a id="movie player" class="center" href="http://moodle.org/testfile/test.mpg">test mpg</a>', 67 '<a href="http://moodle.org/testfile/test.ram">test</a>', 68 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>', 69 '<a href="http://www.youtube-nocookie.com/watch?v=JghQgA2HMX8" class="href=css">test file</a>', 70 '<a href="http://youtu.be/JghQgA2HMX8" class="href=css">test file</a>', 71 '<a href="http://y2u.be/JghQgA2HMX8" class="href=css">test file</a>', 72 '<a class="youtube" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', 73 '<a class="_blanktarget" href="http://moodle.org/testfile/test.flv?d=100x100">test flv</a>', 74 '<a class="hrefcss" href="http://www.youtube.com/watch?v=JghQgA2HMX8">test file</a>', 75 '<a class="content" href="http://moodle.org/testfile/test.avi">test mp3</a>', 76 '<a id="audio" href="http://moodle.org/testfile/test.mp3">test mp3</a>', 77 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 78 '<a href="http://moodle.org/testfile/test.mp3">test mp3</a>', 79 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200">youtube\'s</a>', 80 '<a 81 href="http://moodle.org/testfile/test.mp3"> 82 test mp3</a>', 83 '<a class="content" 84 85 86 href="http://moodle.org/testfile/test.avi">test mp3 87 </a>', 88 '<a href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200" >youtube\'s</a>', 89 // Test a long URL under 4096 characters. 90 $longurl 91 ); 92 93 //test for valid link 94 foreach ($validtexts as $text) { 95 $msg = "Testing text: ". $text; 96 $filter = $filterplugin->filter($text); 97 $this->assertNotEquals($text, $filter, $msg); 98 } 99 100 $insertpoint = strrpos($longurl, 'http://'); 101 $longurl = substr_replace($longurl, 'http://pushover4096chars', $insertpoint, 0); 102 103 $originalurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;">' . 104 '<a href="https://www.youtube.com/watch?v=uUhWl9Lm3OM">Valid link</a></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">'; 105 $paddedurl = str_pad($originalurl, 6000, 'z'); 106 $validpaddedurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;"><span class="mediaplugin mediaplugin_youtube"> 107 <iframe title="Valid link" width="400" height="300" 108 src="https://www.youtube.com/embed/uUhWl9Lm3OM?rel=0&wmode=transparent" frameborder="0" allowfullscreen="1"></iframe> 109 </span></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">'; 110 $validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z'); 111 112 $invalidtexts = array( 113 '<a class="_blanktarget">href="http://moodle.org/testfile/test.mp3"</a>', 114 '<a>test test</a>', 115 '<a >test test</a>', 116 '<a >test test</a>', 117 '<a >test test</a>', 118 '<ahref="http://moodle.org/testfile/test.mp3">sample</a>', 119 '<a href="" test></a>', 120 '<a href="http://www.moodle.com/path/to?#param=29">test</a>', 121 '<a href="http://moodle.org/testfile/test.mp3">test mp3', 122 '<a href="http://moodle.org/testfile/test.mp3"test</a>', 123 '<a href="http://moodle.org/testfile/">test</a>', 124 '<href="http://moodle.org/testfile/test.avi">test</a>', 125 '<abbr href="http://moodle.org/testfile/test.mp3">test mp3</abbr>', 126 '<ahref="http://moodle.org/testfile/test.mp3">test mp3</a>', 127 '<aclass="content" href="http://moodle.org/testfile/test.mp3">test mp3</a>', 128 // Test a long URL over 4096 characters. 129 $longurl 130 ); 131 132 //test for invalid link 133 foreach ($invalidtexts as $text) { 134 $msg = "Testing text: ". $text; 135 $filter = $filterplugin->filter($text); 136 $this->assertEquals($text, $filter, $msg); 137 } 138 139 // Valid mediaurl followed by a longurl. 140 $precededlongurl = '<a href="http://moodle.org/testfile/test.mp3">test.mp3</a>'. $longurl; 141 $filter = $filterplugin->filter($precededlongurl); 142 $this->assertEquals(1, substr_count($filter, 'M.util.add_audio_player')); 143 $this->assertContains($longurl, $filter); 144 145 // Testing for cases where: to be filtered content has 6+ text afterwards. 146 $filter = $filterplugin->filter($paddedurl); 147 $this->assertEquals($validpaddedurl, $filter, $msg); 148 } 149 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |