diff --git a/quick-audio-embed.php b/quick-audio-embed.php
index 54a2569..a9baba9 100644
--- a/quick-audio-embed.php
+++ b/quick-audio-embed.php
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class QuickAudioEmbed {
+ // @codeCoverageIgnoreStart
function init() {
$qae = new QuickAudioEmbed();
$qae->load();
@@ -42,11 +43,27 @@ class QuickAudioEmbed {
}
}
- function load() {
+ function plugins_loaded() {
+ if (version_compare(PHP_VERSION, '5.0.0') === 1) {
+ add_action('init', array('QuickAudioEmbed', 'init'));
+ } else {
+ add_action('admin_notices', array('QuickAudioEmbed', 'admin_notices'));
+ }
+ }
+
+ function admin_notices() {
+ deactivate_plugins(plugin_basename(__FILE__)); ?>
+
+ settings = array(
'dimensions' => '300x50'
);
+ }
+ // @codeCoverageIgnoreEnd
+ function load() {
$options = get_option('quick-audio-embed-settings');
if (is_array($options)) {
$this->settings = array_merge($this->settings, $options);
@@ -86,16 +103,13 @@ class QuickAudioEmbed {
return null;
}
+ // @codeCoverageIgnoreStart
function admin_menu() {
add_settings_section('quick-audio-embed', __('Quick Audio Embed', 'quick-audio-embed'), array(&$this, 'media_settings'), 'media');
add_settings_field('qae-dimensions', __('Dimensions', 'quick-audio-embed'), array(&$this, 'qae_dimensions'), 'media', 'quick-audio-embed');
}
- function the_content($content = '') {
- return preg_replace_callback('#]+href="(?P[^\"]+\.mp3)"[^\>]*>.* #mis', array(&$this, '_the_content_callback'), $content);
- }
-
function media_settings() { ?>
Quick Audio Embed takes any linked-to MP3 file and wraps it in Google Reader's Audio Player.
@@ -107,6 +121,11 @@ class QuickAudioEmbed {
The dimensions of the player as width xheight : 300x50
]+href="(?P[^\"]+\.mp3)"[^\>]*>.*#mis', array(&$this, '_the_content_callback'), $content);
+ }
function _the_content_callback($matches) {
$dimensions = explode('x', $this->settings['dimensions']);
@@ -124,7 +143,7 @@ class QuickAudioEmbed {
return sprintf('
assertEquals(array('test3' => 'test4', 'test5' => 'test5'), get_option('quick-audio-embed-settings'));
$this->assertEquals(array('test3' => 'test4', 'test5' => 'test5'), $qae->settings);
}
+
+ function providerTestLoad() {
+ return array(
+ array(false, array('test' => 'test')),
+ array(array(), array('test' => 'test')),
+ array(array('test' => 'test2'), array('test' => 'test2')),
+ array(array('test2' => 'test2'), array('test' => 'test', 'test2' => 'test2')),
+ );
+ }
+
+ /**
+ * @dataProvider providerTestLoad
+ */
+ function testLoad($options, $expected_settings) {
+ $this->qae->settings = array('test' => 'test');
+ update_option('quick-audio-embed-settings', $options);
+
+ $this->qae->load();
+
+ $this->assertEquals($expected_settings, $this->qae->settings);
+ }
+
+ function providerTestTheContent() {
+ return array(
+ array('', null),
+ array(' ', null),
+ array(' ', null),
+ array(' ', null),
+ array(' ', array(0 => ' ', 1 => 'test.mp3', 'url' => 'test.mp3')),
+ array(' ', array(0 => ' ', 1 => 'test.mp3', 'url' => 'test.mp3')),
+ );
+ }
+
+ /**
+ * @dataProvider providerTestTheContent
+ */
+ function testTheContent($content, $expected_call) {
+ $qae = $this->getMock('QuickAudioEmbed', array('_the_content_callback'));
+
+ if (is_null($expected_call)) {
+ $qae->expects($this->never())->method('_the_content_callback');
+ } else {
+ $qae->expects($this->once())->method('_the_content_callback')->with($expected_call);
+ }
+
+ $qae->the_content($content);
+ }
}