a bunch of cleanups thanks to code coverage analysis

This commit is contained in:
John Bintz 2009-11-10 22:46:39 -05:00
parent 80dbeea163
commit 52170d130b
7 changed files with 76 additions and 37 deletions

View File

@ -52,6 +52,8 @@ class ComicPress {
} }
} }
// @codeCoverageIgnoreStart
/** /**
* Initialize the class. * Initialize the class.
*/ */
@ -75,6 +77,8 @@ class ComicPress {
} }
} }
// WordPress Filters
function intermediate_image_sizes($sizes) { function intermediate_image_sizes($sizes) {
return array_merge($sizes, array('comic', 'rss', 'archive', 'mini')); return array_merge($sizes, array('comic', 'rss', 'archive', 'mini'));
} }
@ -90,7 +94,6 @@ class ComicPress {
function announce_activated_helpers() { function announce_activated_helpers() {
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>"; echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
} }
/** /**
* Gather blog posts for the given index page. * Gather blog posts for the given index page.
*/ */
@ -112,6 +115,8 @@ class ComicPress {
return $wp_query; return $wp_query;
} }
// @codeCoverageIgnoreEnd
/** /**
* Search a path for directories named after the slugs provided. * Search a path for directories named after the slugs provided.
* @param array $categories A list of category slugs going from child -> parent -> root. * @param array $categories A list of category slugs going from child -> parent -> root.

View File

@ -1,6 +1,7 @@
<?php <?php
class ComicPressAdmin { class ComicPressAdmin {
// @codeCoverageIgnoreStart
/** /**
* Initialize the addon. * Initialize the addon.
* @param ComicPress $comicpress The master ComicPress object. * @param ComicPress $comicpress The master ComicPress object.
@ -178,6 +179,7 @@ class ComicPressAdmin {
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc'); include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
} }
} }
// @codeCoverageIgnoreEnd
/** /**
* Create a dimension selector. * Create a dimension selector.
@ -200,6 +202,7 @@ class ComicPressAdmin {
return implode("\n", $output); return implode("\n", $output);
} }
// @codeCoverageIgnoreStart
/** /**
* Update attachment information. * Update attachment information.
*/ */
@ -207,6 +210,7 @@ class ComicPressAdmin {
$this->render_comic_image_ordering(true, $info['post_id']); $this->render_comic_image_ordering(true, $info['post_id']);
exit(0); exit(0);
} }
// @codeCoverageIgnoreEnd
/** /**
* Update attachment information. * Update attachment information.
@ -261,8 +265,8 @@ class ComicPressAdmin {
} }
} }
break; break;
// @codeCoverageIgnoreStart
case 'helpers': case 'helpers':
case 'addons':
foreach ($info[$option] as $type => $set) { foreach ($info[$option] as $type => $set) {
$this->comicpress->comicpress_options[$option][$type] = true; $this->comicpress->comicpress_options[$option][$type] = true;
} }
@ -271,11 +275,13 @@ class ComicPressAdmin {
$storyline = new ComicPressStoryline(); $storyline = new ComicPressStoryline();
$storyline->normalize($info[$option]); $storyline->normalize($info[$option]);
break; break;
// @codeCoverageIgnoreEnd
} }
} }
} }
} }
// @codeCoverageIgnoreStart
function _json_decode($string) { function _json_decode($string) {
if (function_exists('json_decode')) { if (function_exists('json_decode')) {
return json_decode($string); return json_decode($string);
@ -295,24 +301,32 @@ class ComicPressAdmin {
} }
} }
/** /**
* Update the zoom slider info. * Update the zoom slider info.
* @param $info The browser input. * @param $info The browser input.
*/ */
function handle_update_zoom_slider($info) { function handle_update_zoom_slider($info) {
$this->is_ajax = true; $this->is_ajax = true;
$current_user = wp_get_current_user(); $current_user = wp_get_current_user();
if (!empty($current_user)) { if (!empty($current_user)) {
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings'); $this->_update_zoom_slider_meta($current_user->ID, $info['zoom_level']);
if (!is_array($comicpress_meta)) { $comicpress_meta = array(); }
$comicpress_meta['zoom_level'] = $info['zoom_level'];
update_usermeta($current_user->ID, 'comicpress-settings', $comicpress_meta);
exit(0); exit(0);
} }
header('HTTP/1.1 500 Internal Server Error'); header('HTTP/1.1 500 Internal Server Error');
exit(0); exit(0);
} }
// @codeCoverageIgnoreEnd
/**
* Update the user's zoom slider metadata.
*/
function _update_zoom_slider_meta($user_id, $level) {
$comicpress_meta = get_usermeta($user_id, 'comicpress-settings');
if (!is_array($comicpress_meta)) { $comicpress_meta = array(); }
$comicpress_meta['zoom_level'] = $level;
update_usermeta($user_id, 'comicpress-settings', $comicpress_meta);
}
/** /**
* Handle an update. * Handle an update.
@ -347,17 +361,7 @@ class ComicPressAdmin {
} }
} }
/** // @codeCoverageIgnoreStart
* Create the dropdown for choosing a layout.
*/
function create_layout_options($layouts, $current_layout) {
$output = array();
foreach ($layouts as $layout_filename => $info) {
$output[] = '<option value="' . $layout_filename . '"' . (($layout_filename == $current_layout) ? ' selected="selected"' : '') . '>' . $info['Layout Name'] . '</option>';
}
return implode("\n", $output);
}
var $messages = array( var $messages = array(
'info' => array(), 'info' => array(),
'warn' => array(), 'warn' => array(),
@ -379,6 +383,7 @@ class ComicPressAdmin {
} }
} }
} }
// @codeCoverageIgnoreEnd
} }
?> ?>

View File

@ -10,6 +10,7 @@ class ComicPressDBInterface {
return $instance; return $instance;
} }
// @codeCoverageIgnoreStart
function _get_categories() { return get_categories("hide_empty=0"); } function _get_categories() { return get_categories("hide_empty=0"); }
function get_terminal_post($first = true, $include_categories = null) { function get_terminal_post($first = true, $include_categories = null) {
@ -96,4 +97,4 @@ class ComicPressDBInterface {
function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); } function get_next_post($categories = array(), $override_post = null) { return $this->get_adjacent_post($categories, true, $override_post); }
} }
?> // @codeCoverageIngoreEnd

View File

@ -36,6 +36,7 @@ class ComicPressBackendAttachment extends ComicPressBackend {
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true); $this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
} }
// @codeCoverageIgnoreStart
function dims($size = 'comic') { function dims($size = 'comic') {
$metadata = image_downsize($this->attachment->ID, $size); $metadata = image_downsize($this->attachment->ID, $size);
if (!empty($metadata)) { if (!empty($metadata)) {
@ -64,6 +65,7 @@ class ComicPressBackendAttachment extends ComicPressBackend {
function title() { return $this->attachment->post_excerpt; } function title() { return $this->attachment->post_excerpt; }
function get_info() { return array(); } function get_info() { return array(); }
// @codeCoverageIgnoreEnd
} }
?> ?>

View File

@ -178,18 +178,26 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
} }
} }
function providerTestHandleUpdateOverridePartial() { function providerTestUpdateZoomSliderMeta() {
return array( return array(
array( array(false),
'hello', array(array()),
'Update partial' array(array('zoom_level' => 50))
),
array(
'meow',
'Delete override partial'
),
); );
} }
/**
* @dataProvider providerTestUpdateZoomSliderMeta
*/
function testUpdateZoomSliderMeta($initial_usermeta) {
update_usermeta(1, 'comicpress-settings', $initial_usermeta);
$this->admin->_update_zoom_slider_meta(1, 100);
$this->assertEquals(array(
'zoom_level' => 100
), get_usermeta(1, 'comicpress-settings'));
}
} }
?> ?>

View File

@ -123,6 +123,26 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', $search_path, $post_categories)); $this->assertEquals($expected_path_result, $this->cp->find_file('index.inc', $search_path, $post_categories));
} }
function providerTestLoad() {
return array(
array(false, 'default'),
array(array(), 'default'),
array(array(
'comic_dimensions' => '1000x'
), '1000x')
);
}
/**
* @dataProvider providerTestLoad
*/
function testLoad($options_array, $expected_dimensions) {
update_option('comicpress-options', $options_array);
if ($expected_dimensions == 'default') { $expected_dimensions = $this->cp->comicpress_options['comic_dimensions']; }
$this->cp->load();
$this->assertEquals($expected_dimensions, $this->cp->comicpress_options['comic_dimensions']);
}
} }
?> ?>

View File

@ -12,7 +12,9 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
function providerTestGenerateFromPost() { function providerTestGenerateFromPost() {
return array( return array(
array(array(), array(), false), array(array(), array(), false),
array(array((object)array('ID' => 1)), array(), array()) array(array((object)array('ID' => 2)), array(), array()),
array(array((object)array('ID' => 2)), array('managed' => false), array()),
array(array((object)array('ID' => 2)), array('managed' => true), array('attachment-2')),
); );
} }
@ -26,11 +28,7 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
'post_mime_type' => 'image' 'post_mime_type' => 'image'
), $get_children_response); ), $get_children_response);
foreach ($post_meta as $id => $meta) { update_post_meta(2, 'comicpress', $post_meta);
foreach ($meta as $field => $value) {
update_post_meta($id, $field, $value);
}
}
$results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1)); $results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1));
if ($expected_ids === false) { if ($expected_ids === false) {