working on tests and code coverage
This commit is contained in:
parent
dde0023ef9
commit
2d9b0069ff
@ -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__)); ?>
|
||||
<div class="updated fade"><p><?php _e('You need to be running at least PHP 5 to use Quick Audio Embed. Plugin <strong>not</strong> activated.') ?></p></div>
|
||||
<?php }
|
||||
|
||||
function __construct() {
|
||||
$this->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('#<a[^\>]+href="(?P<url>[^\"]+\.mp3)"[^\>]*>.*</a>#mis', array(&$this, '_the_content_callback'), $content);
|
||||
}
|
||||
|
||||
function media_settings() { ?>
|
||||
<p><em><strong>Quick Audio Embed</strong> takes any linked-to MP3 file and wraps it in Google Reader's Audio Player.</em></p>
|
||||
<input type="hidden" name="qae[_nonce]" value="<?php echo esc_attr(wp_create_nonce('quick-audio-embed')) ?>" />
|
||||
@ -107,6 +121,11 @@ class QuickAudioEmbed {
|
||||
<em>The dimensions of the player as <strong>width</strong>x<strong>height</strong>: <code>300x50</code></em>
|
||||
</p>
|
||||
<?php }
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function the_content($content = '') {
|
||||
return preg_replace_callback('#<a[^\>]+href="(?P<url>[^\"]+\.mp3)"[^\>]*>.*</a>#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('
|
||||
<embed type="application/x-shockwave-flash"
|
||||
src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=%s"
|
||||
src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=%s&play=true"
|
||||
width="%d"
|
||||
height="%d"
|
||||
allowscriptaccess="never"
|
||||
@ -136,4 +155,4 @@ class QuickAudioEmbed {
|
||||
}
|
||||
}
|
||||
|
||||
add_action('init', array('QuickAudioEmbed', 'init'));
|
||||
add_action('plugins_loaded', array('QuickAudioEmbed', 'plugins_loaded'));
|
||||
|
@ -41,4 +41,51 @@ class QuickAudioEmbedTest extends PHPUnit_Framework_TestCase {
|
||||
$this->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('<a href="test"></a>', null),
|
||||
array('<a href="mp3"></a>', null),
|
||||
array('<a href=".mp3"></a>', null),
|
||||
array('<a href="test.mp3"></a>', array(0 => '<a href="test.mp3"></a>', 1 => 'test.mp3', 'url' => 'test.mp3')),
|
||||
array('<a rel="test" href="test.mp3"></a>', array(0 => '<a rel="test" href="test.mp3"></a>', 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user