a bunch of cleanups thanks to code coverage analysis
This commit is contained in:
parent
80dbeea163
commit
52170d130b
|
@ -52,6 +52,8 @@ class ComicPress {
|
|||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
|
||||
/**
|
||||
* Initialize the class.
|
||||
*/
|
||||
|
@ -75,6 +77,8 @@ class ComicPress {
|
|||
}
|
||||
}
|
||||
|
||||
// WordPress Filters
|
||||
|
||||
function intermediate_image_sizes($sizes) {
|
||||
return array_merge($sizes, array('comic', 'rss', 'archive', 'mini'));
|
||||
}
|
||||
|
@ -90,7 +94,6 @@ class ComicPress {
|
|||
function announce_activated_helpers() {
|
||||
echo "<center>[ <strong>Activated ComicPress helpers:</strong> " . implode(", ", array_keys($this->comicpress_options['helpers'])) . " ]</center>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather blog posts for the given index page.
|
||||
*/
|
||||
|
@ -112,6 +115,8 @@ class ComicPress {
|
|||
return $wp_query;
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Search a path for directories named after the slugs provided.
|
||||
* @param array $categories A list of category slugs going from child -> parent -> root.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
class ComicPressAdmin {
|
||||
// @codeCoverageIgnoreStart
|
||||
/**
|
||||
* Initialize the addon.
|
||||
* @param ComicPress $comicpress The master ComicPress object.
|
||||
|
@ -178,6 +179,7 @@ class ComicPressAdmin {
|
|||
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Create a dimension selector.
|
||||
|
@ -200,6 +202,7 @@ class ComicPressAdmin {
|
|||
return implode("\n", $output);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
/**
|
||||
* Update attachment information.
|
||||
*/
|
||||
|
@ -207,6 +210,7 @@ class ComicPressAdmin {
|
|||
$this->render_comic_image_ordering(true, $info['post_id']);
|
||||
exit(0);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
/**
|
||||
* Update attachment information.
|
||||
|
@ -261,8 +265,8 @@ class ComicPressAdmin {
|
|||
}
|
||||
}
|
||||
break;
|
||||
// @codeCoverageIgnoreStart
|
||||
case 'helpers':
|
||||
case 'addons':
|
||||
foreach ($info[$option] as $type => $set) {
|
||||
$this->comicpress->comicpress_options[$option][$type] = true;
|
||||
}
|
||||
|
@ -271,11 +275,13 @@ class ComicPressAdmin {
|
|||
$storyline = new ComicPressStoryline();
|
||||
$storyline->normalize($info[$option]);
|
||||
break;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function _json_decode($string) {
|
||||
if (function_exists('json_decode')) {
|
||||
return json_decode($string);
|
||||
|
@ -295,24 +301,32 @@ class ComicPressAdmin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the zoom slider info.
|
||||
* @param $info The browser input.
|
||||
*/
|
||||
/**
|
||||
* Update the zoom slider info.
|
||||
* @param $info The browser input.
|
||||
*/
|
||||
function handle_update_zoom_slider($info) {
|
||||
$this->is_ajax = true;
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
if (!empty($current_user)) {
|
||||
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
|
||||
if (!is_array($comicpress_meta)) { $comicpress_meta = array(); }
|
||||
$comicpress_meta['zoom_level'] = $info['zoom_level'];
|
||||
update_usermeta($current_user->ID, 'comicpress-settings', $comicpress_meta);
|
||||
$this->_update_zoom_slider_meta($current_user->ID, $info['zoom_level']);
|
||||
exit(0);
|
||||
}
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
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.
|
||||
|
@ -347,17 +361,7 @@ class ComicPressAdmin {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
var $messages = array(
|
||||
'info' => array(),
|
||||
'warn' => array(),
|
||||
|
@ -379,6 +383,7 @@ class ComicPressAdmin {
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
?>
|
|
@ -10,6 +10,7 @@ class ComicPressDBInterface {
|
|||
return $instance;
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function _get_categories() { return get_categories("hide_empty=0"); }
|
||||
|
||||
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); }
|
||||
}
|
||||
|
||||
?>
|
||||
// @codeCoverageIngoreEnd
|
||||
|
|
|
@ -36,6 +36,7 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
|||
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function dims($size = 'comic') {
|
||||
$metadata = image_downsize($this->attachment->ID, $size);
|
||||
if (!empty($metadata)) {
|
||||
|
@ -64,6 +65,7 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
|||
function title() { return $this->attachment->post_excerpt; }
|
||||
|
||||
function get_info() { return array(); }
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
?>
|
|
@ -178,18 +178,26 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
function providerTestHandleUpdateOverridePartial() {
|
||||
function providerTestUpdateZoomSliderMeta() {
|
||||
return array(
|
||||
array(
|
||||
'hello',
|
||||
'Update partial'
|
||||
),
|
||||
array(
|
||||
'meow',
|
||||
'Delete override partial'
|
||||
),
|
||||
array(false),
|
||||
array(array()),
|
||||
array(array('zoom_level' => 50))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -12,7 +12,9 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
|||
function providerTestGenerateFromPost() {
|
||||
return array(
|
||||
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'
|
||||
), $get_children_response);
|
||||
|
||||
foreach ($post_meta as $id => $meta) {
|
||||
foreach ($meta as $field => $value) {
|
||||
update_post_meta($id, $field, $value);
|
||||
}
|
||||
}
|
||||
update_post_meta(2, 'comicpress', $post_meta);
|
||||
|
||||
$results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1));
|
||||
if ($expected_ids === false) {
|
||||
|
|
Loading…
Reference in New Issue