Skip to content

Commit

Permalink
MDL-58361 media: Remove media manager subclass from unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
John Okely committed Mar 28, 2017
1 parent 216ea39 commit 2553d67
Showing 1 changed file with 31 additions and 40 deletions.
71 changes: 31 additions & 40 deletions lib/tests/medialib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,28 @@ public function test_list_supported_urls() {
*/
public function test_get_players() {
// All players are initially disabled (except link, which you can't).
$manager = new core_media_manager_test();
$this->assertEmpty($manager->get_players_test());
$manager = core_media_manager::instance();
$this->assertEmpty($this->get_players_test($manager));

// A couple enabled, check the order.
\core\plugininfo\media::set_enabled_plugins('youtube,html5audio');
$manager = new core_media_manager_test();
$this->assertSame('youtube, html5audio', $manager->get_players_test());
$manager = core_media_manager::instance();
$this->assertSame('youtube, html5audio', $this->get_players_test($manager));

// Test SWF and HTML5 media order.
\core\plugininfo\media::set_enabled_plugins('html5video,html5audio,swf');
$manager = new core_media_manager_test();
$this->assertSame('html5video, html5audio, swf', $manager->get_players_test());
$manager = core_media_manager::instance();
$this->assertSame('html5video, html5audio, swf', $this->get_players_test($manager));

// Make sure that our test plugin is considered installed.
\core\plugininfo\media::set_enabled_plugins('test,html5video');
$manager = new core_media_manager_test();
$this->assertSame('test, html5video', $manager->get_players_test());
$manager = core_media_manager::instance();
$this->assertSame('test, html5video', $this->get_players_test($manager));

// Make sure that non-existing plugin is NOT considered installed.
\core\plugininfo\media::set_enabled_plugins('nonexistingplugin,html5video');
$manager = new core_media_manager_test();
$this->assertSame('html5video', $manager->get_players_test());
$manager = core_media_manager::instance();
$this->assertSame('html5video', $this->get_players_test($manager));
}

/**
Expand Down Expand Up @@ -474,6 +474,27 @@ public function test_initialise() {

$this->assertNotSame($mediamanager1, $mediamanager3);
}


/**
* Access list of players as string, shortening it by getting rid of
* repeated text.
* @param core_media_manager $manager The core_media_manager instance
* @return string Comma-separated list of players
*/
public function get_players_test($manager) {
$method = new ReflectionMethod("core_media_manager", "get_players");
$method->setAccessible(true);
$players = $method->invoke($manager);
$out = '';
foreach ($players as $player) {
if ($out) {
$out .= ', ';
}
$out .= str_replace('core_media_player_', '', preg_replace('/^media_(.*)_plugin$/', '$1', get_class($player)));
}
return $out;
}
}

/**
Expand Down Expand Up @@ -513,33 +534,3 @@ public function get_rank() {
return 10;
}
}

/**
* Media renderer override for testing purposes.
*/
class core_media_manager_test extends core_media_manager {
/**
* Access list of players as string, shortening it by getting rid of
* repeated text.
* @return string Comma-separated list of players
*/
public function get_players_test() {
$players = $this->get_players();
$out = '';
foreach ($players as $player) {
if ($out) {
$out .= ', ';
}
$out .= str_replace('core_media_player_', '', preg_replace('/^media_(.*)_plugin$/', '$1', get_class($player)));
}
return $out;
}

/**
* Override the constructor to access it.
*/
public function __construct() {
global $PAGE;
parent::__construct($PAGE);
}
}

0 comments on commit 2553d67

Please sign in to comment.