Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 * Test for core_media_player_native. 19 * 20 * @package core 21 * @category test 22 * @copyright 2019 Ruslan Kabalin 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 require_once (__DIR__ . '/fixtures/testable_core_media_player_native.php'); 28 29 /** 30 * Test for core_media_player_native. 31 * 32 * @package core 33 * @category test 34 * @covers \core_media_player_native 35 * @copyright 2019 Ruslan Kabalin 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class core_media_player_native_testcase extends advanced_testcase { 39 40 /** 41 * Pre-test setup. 42 */ 43 public function setUp(): void { 44 parent::setUp(); 45 $this->resetAfterTest(); 46 } 47 48 /** 49 * Test method get_supported_extensions 50 */ 51 public function test_get_supported_extensions() { 52 global $CFG; 53 require_once($CFG->libdir . '/filelib.php'); 54 $nativeextensions = file_get_typegroup('extension', ['html_video', 'html_audio']); 55 56 // Make sure that the list of extensions from the setting is exactly the same. 57 $player = new media_test_native_plugin(); 58 $this->assertEmpty(array_diff($player->get_supported_extensions(), $nativeextensions)); 59 $this->assertEmpty(array_diff($nativeextensions, $player->get_supported_extensions())); 60 61 } 62 63 /** 64 * Test method list_supported_urls 65 */ 66 public function test_list_supported_urls() { 67 global $CFG; 68 require_once($CFG->libdir . '/filelib.php'); 69 $nativeextensions = file_get_typegroup('extension', ['html_video', 'html_audio']); 70 71 // Create list of URLs for each extension. 72 $urls = array_map(function($ext){ 73 return new moodle_url('http://example.org/video.' . $ext); 74 }, $nativeextensions); 75 76 // Make sure that the list of supported URLs is not filtering permitted extensions. 77 $player = new media_test_native_plugin(); 78 $this->assertCount(count($urls), $player->list_supported_urls($urls)); 79 } 80 81 /** 82 * Test method get_attribute 83 */ 84 public function test_get_attribute() { 85 $urls = [ 86 new moodle_url('http://example.org/some_filename.mp4'), 87 new moodle_url('http://example.org/some_filename_hires.mp4'), 88 ]; 89 90 $player = new media_test_native_plugin(); 91 // We are using fixture embed method directly as content generator. 92 $title = 'Some Filename Video'; 93 $content = $player->embed($urls, $title, 0, 0, []); 94 95 $this->assertRegExp('~title="' . $title . '"~', $content); 96 $this->assertEquals($title, media_test_native_plugin::get_attribute($content, 'title')); 97 } 98 99 /** 100 * Test methods add_attributes and remove_attributes 101 */ 102 public function test_add_remove_attributes() { 103 $urls = [ 104 new moodle_url('http://example.org/some_filename.mp4'), 105 new moodle_url('http://example.org/some_filename_hires.mp4'), 106 ]; 107 108 $player = new media_test_native_plugin(); 109 // We are using fixture embed method directly as content generator. 110 $title = 'Some Filename Video'; 111 $content = $player->embed($urls, $title, 0, 0, []); 112 113 // Add attributes. 114 $content = media_test_native_plugin::add_attributes($content, ['preload' => 'none', 'controls' => 'true']); 115 $this->assertRegExp('~title="' . $title . '"~', $content); 116 $this->assertRegExp('~preload="none"~', $content); 117 $this->assertRegExp('~controls="true"~', $content); 118 119 // Change existing attribute. 120 $content = media_test_native_plugin::add_attributes($content, ['controls' => 'false']); 121 $this->assertRegExp('~title="' . $title . '"~', $content); 122 $this->assertRegExp('~preload="none"~', $content); 123 $this->assertRegExp('~controls="false"~', $content); 124 125 // Remove attributes. 126 $content = media_test_native_plugin::remove_attributes($content, ['title']); 127 $this->assertNotRegExp('~title="' . $title . '"~', $content); 128 $this->assertRegExp('~preload="none"~', $content); 129 $this->assertRegExp('~controls="false"~', $content); 130 131 // Remove another one. 132 $content = media_test_native_plugin::remove_attributes($content, ['preload']); 133 $this->assertNotRegExp('~title="' . $title . '"~', $content); 134 $this->assertNotRegExp('~preload="none"~', $content); 135 $this->assertRegExp('~controls="false"~', $content); 136 } 137 138 /** 139 * Test method replace_sources 140 */ 141 public function test_replace_sources() { 142 $urls = [ 143 new moodle_url('http://example.org/some_filename.mp4'), 144 new moodle_url('http://example.org/some_filename_hires.mp4'), 145 ]; 146 147 $player = new media_test_native_plugin(); 148 // We are using fixture embed method directly as content generator. 149 $title = 'Some Filename Video'; 150 $content = $player->embed($urls, $title, 0, 0, []); 151 152 // Test sources present. 153 $this->assertStringContainsString('<source src="http://example.org/some_filename.mp4" />', $content); 154 $this->assertStringContainsString('<source src="http://example.org/some_filename_hires.mp4" />', $content); 155 156 // Change sources. 157 $newsource = '<source src="http://example.org/new_filename.mp4" />'; 158 $content = media_test_native_plugin::replace_sources($content, $newsource); 159 $this->assertStringContainsString($newsource, $content); 160 $this->assertStringNotContainsString('<source src="http://example.org/some_filename.mp4" />', $content); 161 $this->assertStringNotContainsString('<source src="http://example.org/some_filename_hires.mp4" />', $content); 162 } 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body