Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea -... Línea 16...
-
 
16
 
-
 
17
namespace filter_mediaplugin;
16
 
18
 
17
/**
19
/**
18
 * Unit test for the filter_mediaplugin
20
 * Unit test for the filter_mediaplugin
19
 *
21
 *
20
 * @package    filter_mediaplugin
22
 * @package    filter_mediaplugin
21
 * @category   phpunit
23
 * @category   test
22
 * @copyright  2011 Rossiani Wijaya <rwijaya@moodle.com>
24
 * @copyright  2011 Rossiani Wijaya <rwijaya@moodle.com>
-
 
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @covers \filter_mediaplugin\text_filter
24
 */
-
 
25
 
-
 
26
namespace filter_mediaplugin;
-
 
27
 
-
 
28
use filter_mediaplugin;
-
 
29
 
-
 
30
defined('MOODLE_INTERNAL') || die();
-
 
31
 
-
 
32
global $CFG;
-
 
33
require_once($CFG->dirroot . '/filter/mediaplugin/filter.php'); // Include the code to test
-
 
34
 
-
 
35
 
27
 */
36
class filter_test extends \advanced_testcase {
-
 
37
 
28
final class filter_test extends \advanced_testcase {
38
    function test_filter_mediaplugin_link(): void {
29
    public function test_text_filter_link(): void {
Línea 39... Línea 30...
39
        $this->resetAfterTest(true);
30
        $this->resetAfterTest(true);
40
 
31
 
Línea 41... Línea 32...
41
        // We need to enable the media plugins.
32
        // We need to enable the media plugins.
Línea 42... Línea 33...
42
        \core\plugininfo\media::set_enabled_plugins('vimeo,youtube,videojs,html5video,html5audio');
33
        \core\plugininfo\media::set_enabled_plugins('vimeo,youtube,videojs,html5video,html5audio');
43
 
34
 
Línea 44... Línea 35...
44
        $filterplugin = new filter_mediaplugin(null, array());
35
        $filterplugin = new text_filter(null, []);
45
 
36
 
46
        $longurl = '<a href="http://moodle/.mp4">my test file</a>';
37
        $longurl = '<a href="http://moodle/.mp4">my test file</a>';
Línea 47... Línea 38...
47
        $longhref = '';
38
        $longhref = '';
Línea 48... Línea 39...
48
 
39
 
49
        do {
40
        do {
50
            $longhref .= 'a';
41
            $longhref .= 'a';
51
        } while(strlen($longhref) + strlen($longurl) < 4095);
42
        } while (strlen($longhref) + strlen($longurl) < 4095);
52
 
43
 
53
        $longurl = '<a href="http://moodle/' . $longhref . '.mp4">my test file</a>';
44
        $longurl = '<a href="http://moodle/' . $longhref . '.mp4">my test file</a>';
Línea 76... Línea 67...
76
 
67
 
77
                            href="http://moodle.org/testfile/test.wav">test wav
68
                            href="http://moodle.org/testfile/test.wav">test wav
78
                                    </a>',
69
                                    </a>',
79
            '<a             href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200"     >youtube\'s</a>',
70
            '<a             href="http://www.youtube.com/watch?v=JghQgA2HMX8?d=200x200"     >youtube\'s</a>',
80
            // Test a long URL under 4096 characters.
71
            // Test a long URL under 4096 characters.
81
            $longurl
72
            $longurl,
Línea 82... Línea 73...
82
        );
73
        ];
83
 
74
 
84
        //test for valid link
75
        // Test for valid link.
85
        foreach ($validtexts as $text) {
76
        foreach ($validtexts as $text) {
86
            $msg = "Testing text: ". $text;
77
            $msg = "Testing text: " . $text;
87
            $filter = $filterplugin->filter($text);
78
            $filter = $filterplugin->filter($text);
Línea 88... Línea 79...
88
            $this->assertNotEquals($text, $filter, $msg);
79
            $this->assertNotEquals($text, $filter, $msg);
89
        }
80
        }
Línea 90... Línea 81...
90
 
81
 
91
        $insertpoint = strrpos($longurl, 'http://');
82
        $insertpoint = strrpos($longurl, 'http://');
-
 
83
        $longurl = substr_replace($longurl, 'http://pushover4096chars', $insertpoint, 0);
92
        $longurl = substr_replace($longurl, 'http://pushover4096chars', $insertpoint, 0);
84
 
-
 
85
        $originalurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;">' .
93
 
86
            '<a href="https://www.youtube.com/watch?v=uUhWl9Lm3OM">Valid link</a>' .
-
 
87
            '</pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
94
        $originalurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;">' .
88
        $paddedurl = str_pad($originalurl, 6000, 'z');
95
            '<a href="https://www.youtube.com/watch?v=uUhWl9Lm3OM">Valid link</a></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
89
        $validpaddedurl = '<p>Some text.</p>' .
96
        $paddedurl = str_pad($originalurl, 6000, 'z');
90
            '<pre style="color: rgb(0, 0, 0); line-height: normal;">' .
97
        $validpaddedurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;"><span class="mediaplugin mediaplugin_youtube">
91
            '<span class="mediaplugin mediaplugin_youtube">
Línea 98... Línea 92...
98
<iframe title="Valid link" width="640" height="360" style="border:0;"
92
<iframe title="Valid link" width="640" height="360" style="border:0;"
99
        src="https://www.youtube.com/embed/uUhWl9Lm3OM?rel=0&wmode=transparent" allow="fullscreen" loading="lazy"></iframe>
93
        src="https://www.youtube.com/embed/uUhWl9Lm3OM?rel=0&wmode=transparent" allow="fullscreen" loading="lazy"></iframe>
100
</span></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
94
</span></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
101
        $validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z');
95
        $validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z');
102
 
96
 
103
        $invalidtexts = array(
97
        $invalidtexts = [
Línea 115... Línea 109...
115
            '<href="http://moodle.org/testfile/test.avi">test</a>',
109
            '<href="http://moodle.org/testfile/test.avi">test</a>',
116
            '<abbr href="http://moodle.org/testfile/test.mp3">test mp3</abbr>',
110
            '<abbr href="http://moodle.org/testfile/test.mp3">test mp3</abbr>',
117
            '<ahref="http://moodle.org/testfile/test.mp3">test mp3</a>',
111
            '<ahref="http://moodle.org/testfile/test.mp3">test mp3</a>',
118
            '<aclass="content" href="http://moodle.org/testfile/test.mp3">test mp3</a>',
112
            '<aclass="content" href="http://moodle.org/testfile/test.mp3">test mp3</a>',
119
            // Test a long URL over 4096 characters.
113
            // Test a long URL over 4096 characters.
120
            $longurl
114
            $longurl,
121
        );
115
        ];
Línea 122... Línea 116...
122
 
116
 
123
        //test for invalid link
117
        // Test for invalid link.
124
        foreach ($invalidtexts as $text) {
118
        foreach ($invalidtexts as $text) {
125
            $msg = "Testing text: ". $text;
119
            $msg = "Testing text: " . $text;
126
            $filter = $filterplugin->filter($text);
120
            $filter = $filterplugin->filter($text);
127
            $this->assertEquals($text, $filter, $msg);
121
            $this->assertEquals($text, $filter, $msg);
Línea 128... Línea 122...
128
        }
122
        }
129
 
123
 
130
        // Valid mediaurl followed by a longurl.
124
        // Valid mediaurl followed by a longurl.
131
        $precededlongurl = '<a href="http://moodle.org/testfile/test.mp3">test.mp3</a>'. $longurl;
125
        $precededlongurl = '<a href="http://moodle.org/testfile/test.mp3">test.mp3</a>' . $longurl;
132
        $filter = $filterplugin->filter($precededlongurl);
126
        $filter = $filterplugin->filter($precededlongurl);
Línea 133... Línea 127...
133
        $this->assertEquals(1, substr_count($filter, '</audio>'));
127
        $this->assertEquals(1, substr_count($filter, '</audio>'));