From 88fa4b78e760f299500b012940e8455054e62d08 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jul 2009 13:40:24 -0400 Subject: [PATCH] clean up test cases a bit --- addons/Core/Core.inc | 129 +++++++++++++++------------ addons/Core/test/OptionsPageTest.php | 2 +- classes/ComicPress.inc | 16 ++-- 3 files changed, 80 insertions(+), 67 deletions(-) diff --git a/addons/Core/Core.inc b/addons/Core/Core.inc index e21513d..b49bfef 100644 --- a/addons/Core/Core.inc +++ b/addons/Core/Core.inc @@ -339,72 +339,85 @@ class ComicPressAddonCore extends ComicPressAddon { } } + /** + * Update attachment information. + */ + function handle_update_attachments() { + foreach ($_POST['attachments'] as $post_id => $settings) { + if (isset($settings['comic_image_type'])) { + update_post_meta($post_id, 'comic_image_type', $settings['comic_image_type']); + } + if (isset($settings['auto_attach']) && isset($settings['post_parent'])) { + $media_post = get_post($post_id); + $media_post->post_parent = $settings['post_parent']; + wp_update_post($media_post); + } + } + } + + /** + * Update ComicPress options. + */ + function handle_update_comicpress_options() { + foreach ($this->comicpress->comicpress_options as $option => $value) { + if (isset($_POST['cp'][$option])) { + switch ($option) { + case 'comic_category_id': + if (is_numeric($_POST['cp'][$option])) { + $result = get_category($_POST['cp'][$option]); + if (!(is_a($result, 'WP_Error') || empty($result))) { + $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; + } + } + break; + case 'comic_dimensions': + case 'rss_dimensions': + case 'archive_dimensions': + case 'mini_dimensions': + if (is_array($_POST['cp'][$option])) { + $dim_parts = array(); + $is_valid = true; + foreach (array('width', 'height') as $field) { + $requested_dim = trim($_POST['cp'][$option][$field]); + if ($requested_dim == "") { + $dim_parts[] = $requested_dim; + } else { + if ((int)$requested_dim == $requested_dim) { + $dim_parts[] = $requested_dim; + } else { + $is_valid = false; break; + } + } + } + + if ($is_valid) { + $this->comicpress->comicpress_options[$option] = implode("x", $dim_parts); + } + } + break; + case 'blogpost_count': + $this->comicpress->comicpress_options[$option] = (int)$_POST['cp'][$option]; + break; + case 'comic_space': + case 'category_page_usage': + $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; + break; + } + } + } + } + /** * Handle an update. */ function handle_update() { if (isset($_POST['attachments'])) { //coming from media editor - foreach ($_POST['attachments'] as $post_id => $settings) { - if (isset($settings['comic_image_type'])) { - update_post_meta($post_id, 'comic_image_type', $settings['comic_image_type']); - } - if (isset($settings['auto_attach'])) { - if (isset($settings['post_parent'])) { - $media_post = get_post($post_id); - $media_post->post_parent = $settings['post_parent']; - wp_update_post($media_post); - } - } - } + $this->handle_update_attachments(); } else { //coming from us - foreach ($this->comicpress->comicpress_options as $option => $value) { - if (isset($_POST['cp'][$option])) { - switch ($option) { - case 'comic_category_id': - if (is_numeric($_POST['cp'][$option])) { - $result = get_category($_POST['cp'][$option]); - if (!(is_a($result, 'WP_Error') || empty($result))) { - $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; - } - } - break; - case 'comic_dimensions': - case 'rss_dimensions': - case 'archive_dimensions': - if (is_array($_POST['cp'][$option])) { - $dim_parts = array(); - $is_valid = true; - foreach (array('width', 'height') as $field) { - $requested_dim = trim($_POST['cp'][$option][$field]); - if ($requested_dim == "") { - $dim_parts[] = $requested_dim; - } else { - if ((int)$requested_dim == $requested_dim) { - $dim_parts[] = $requested_dim; - } else { - $is_valid = false; break; - } - } - } - - if ($is_valid) { - $this->comicpress->comicpress_options[$option] = implode("x", $dim_parts); - } - } - break; - case 'blogpost_count': - $this->comicpress->comicpress_options[$option] = (int)$_POST['cp'][$option]; - break; - case 'comic_space': - case 'category_page_usage': - $this->comicpress->comicpress_options[$option] = $_POST['cp'][$option]; - break; - } - } - } - + $this->handle_update_comicpress_options(); + if (isset($_GET['cp']['move_direction']) && isset($_GET['cp']['category'])) { $this->move_storyline_category_order($_GET['cp']['category'], $_GET['cp']['move_direction']); } diff --git a/addons/Core/test/OptionsPageTest.php b/addons/Core/test/OptionsPageTest.php index 9adc20a..e500aa7 100644 --- a/addons/Core/test/OptionsPageTest.php +++ b/addons/Core/test/OptionsPageTest.php @@ -166,7 +166,7 @@ class CoreTest extends PHPUnit_Framework_TestCase { $_POST = $change; - $this->core->handle_update(); + $this->core->handle_update_comicpress_options(); foreach ($new as $key => $value) { $this->assertEquals($value, $this->core->comicpress->comicpress_options[$key]); diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 7af093f..7426bbb 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -5,14 +5,14 @@ */ class ComicPress { var $comicpress_options = array( - 'comic_category_id' => 1, - 'comic_dimensions' => '760x', - 'rss_dimensions' => '350x', - 'archive_dimensions' => '125x', - 'mini_dimensions' => '100x', - 'category_order' => false, - 'blogpost_count' => 10, - 'comic_space' => 'comic_only', + 'comic_category_id' => 1, + 'comic_dimensions' => '760x', + 'rss_dimensions' => '350x', + 'archive_dimensions' => '125x', + 'mini_dimensions' => '100x', + 'category_order' => false, + 'blogpost_count' => 10, + 'comic_space' => 'comic_only', 'category_page_usage' => 'archive_list' );