diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index 7b5017a..8beda33 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -7,7 +7,7 @@ class ComicPressAdmin { */ function init() { $this->comicpress = &ComicPress::get_instance(); - + add_action('admin_menu', array(&$this, 'admin_menu')); add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2); @@ -39,10 +39,10 @@ class ComicPressAdmin { . ']" value="' . $index . '" />'; - + return $content; } - + function comicpress_display_attached_images($content, $post_id) { $content = '
' . '' . '
'; - + return $content; } @@ -118,7 +118,7 @@ class ComicPressAdmin { . $label . ''; } - + $form_fields['comic_image_type'] = array( 'label' => __("Comic Image Type", 'comicpress'), 'input' => 'html', @@ -134,7 +134,7 @@ class ComicPressAdmin { . '' ); } - + return $form_fields; } @@ -143,14 +143,13 @@ class ComicPressAdmin { */ function render_admin() { $nonce = wp_create_nonce('comicpress'); - $root_categories = $this->get_root_categories(); $storyline = new ComicPressStoryline(); $storyline->normalize(); $storyline->read_from_options(); - include(dirname(__FILE__) . '/partials/options-admin.inc'); + include(dirname(__FILE__) . '/partials/options-admin.inc'); } - + function _render_admin_storyline_tree($node, $parent_id = "0") { foreach ($node as $category_id => $children) { $category = get_category($category_id); @@ -164,7 +163,7 @@ class ComicPressAdmin { echo ''; } } - + /** * Render the comic image ordering interface. */ @@ -173,7 +172,7 @@ class ComicPressAdmin { $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; } - + $comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID)); $ordering = $comic_post->normalize_comic_image_ordering(); @@ -202,52 +201,6 @@ class ComicPressAdmin { } } - /** - * Get all categories with a parent ID of 0. - * @return array All root categories. - */ - function get_root_categories() { - $root_categories = array(); - foreach (get_all_category_ids() as $id) { - $category = get_category($id); - if (!empty($category)) { - if ($category->parent == 0) { - $root_categories[] = $category; - } - } - } - return $root_categories; - } - - /** - * Create <option> elements for each of the provided categories. - * @param array $categories The categories to display as either IDs or category objects. - * @param int $selected_id The category to mark as selected. - * @return string The category options as HTML. - */ - function create_category_options($categories, $selected_id) { - $output = array(); - if (is_array($categories)) { - $final_categories = array(); - foreach ($categories as $category) { - if (is_numeric($category)) { - $result = get_category($category); - if (!(is_a($result, "WP_Error") || empty($result))) { - $final_categories[] = $result; - } - } - if (is_object($category)) { - $final_categories[] = $category; - } - } - - foreach ($final_categories as $category) { - $output[] = ''; - } - } - return implode("\n", $output); - } - /** * Create a dimension selector. * @param string $root The field name root. @@ -256,7 +209,7 @@ class ComicPressAdmin { */ function create_dimension_selector($root, $dimension) { $output = array(); - + $parts = explode("x", $dimension); foreach (array( 'width' => __('Width', 'comicpress'), @@ -264,7 +217,7 @@ class ComicPressAdmin { ) as $id => $name) { $dim = array_shift($parts); if (!empty($dim) && !is_numeric($dim)) { $dim = ""; } - $output[] = '
'; + $output[] = '
'; } return implode("\n", $output); } @@ -283,7 +236,7 @@ class ComicPressAdmin { 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']); + 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); @@ -292,7 +245,7 @@ class ComicPressAdmin { } } } - + /** * Update ComicPress options. */ @@ -303,14 +256,6 @@ class ComicPressAdmin { foreach ($this->comicpress->comicpress_options as $option => $value) { if (isset($info[$option])) { switch ($option) { - case 'comic_category_id': - if (is_numeric($info[$option])) { - $result = get_category($info[$option]); - if (!(is_a($result, 'WP_Error') || empty($result))) { - $this->comicpress->comicpress_options[$option] = $info[$option]; - } - } - break; case 'comic_dimensions': case 'rss_dimensions': case 'archive_dimensions': @@ -330,20 +275,12 @@ class ComicPressAdmin { } } } - + if ($is_valid) { $this->comicpress->comicpress_options[$option] = implode("x", $dim_parts); } } break; - case 'blogpost_count': - $this->comicpress->comicpress_options[$option] = (int)$info[$option]; - break; - case 'comic_space': - case 'category_usage': - case 'layout'; - $this->comicpress->comicpress_options[$option] = $info[$option]; - break; case 'helpers': case 'addons': foreach ($info[$option] as $type => $set) { @@ -366,9 +303,9 @@ class ComicPressAdmin { require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php"); $j = new Moxiecode_JSON(); return $j->decode($string); - } + } } - + function handle_update_comic_ordering() { if (is_numeric($_POST['post_ID'])) { if ($post = get_post($_POST['post_ID'])) { @@ -429,7 +366,7 @@ class ComicPressAdmin { } } } - + /** * Create the dropdown for choosing a layout. */ diff --git a/classes/partials/options-admin.inc b/classes/partials/options-admin.inc index 9912fc6..86accba 100644 --- a/classes/partials/options-admin.inc +++ b/classes/partials/options-admin.inc @@ -9,7 +9,7 @@
- _render_admin_storyline_tree(reset($storyline->get_simple_storyline())) ?>
@@ -30,12 +30,6 @@ - - - - - -

@@ -64,11 +58,11 @@ - +
all_addons as $addon) { - if (!empty($addon->name)) { + if (!empty($addon->name)) { $enabled = ($addon->is_addon_manager !== true); $checked = $enabled && $this->comicpress->comicpress_options['addons'][$addon->name]; ?> - +
diff --git a/test/ComicPressAdminTest.php b/test/ComicPressAdminTest.php index ff309eb..d3945a5 100644 --- a/test/ComicPressAdminTest.php +++ b/test/ComicPressAdminTest.php @@ -10,98 +10,22 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { $_POST = array(); $this->admin = new ComicPressAdmin(); } - - function providerTestGetRootComicCategories() { - return array( - array(array(), array()), - array( - array( - array('id' => 1, 'parent' => 0), - array('id' => 2, 'parent' => 1) - ), - array(1) - ) - ); - } - - /** - * @dataProvider providerTestGetRootComicCategories - */ - function testGetRootCategories($categories, $expected_result) { - foreach ($categories as $category) { - add_category($category['id'], (object)$category); - } - - $result_ids = array(); - foreach ($this->admin->get_root_categories() as $category) { - $result_ids[] = $category->term_id; - } - - $this->assertEquals($expected_result, $result_ids); - } - - function testCreateCategoryOptions() { - add_category(1, (object)array('name' => 'test-one')); - add_category(2, (object)array('name' => 'test-two')); - - foreach(array( - array(1,2), - array(get_category(1), get_category(2)) - ) as $category_test) { - $source = $this->admin->create_category_options($category_test, 1); - - $this->assertTrue(($xml = _to_xml($source, true)) !== false); - - foreach (array( - '//option[@value="1" and @selected="selected"]' => "test-one", - '//option[@value="2"]' => "test-two", - ) as $xpath => $value) { - $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); - } - } - } function testCreateDimensionSelector() { $source = $this->admin->create_dimension_selector("test", "760x340"); - + $this->assertTrue(($xml = _to_xml($source, true)) !== false); - + foreach (array( '//input[@name="test[width]" and @value="760"]' => true, '//input[@name="test[height]" and @value="340"]' => true, ) as $xpath => $value) { - $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); - } + $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); + } } - + function providerTestHandleUpdate() { return array( - array( - array('comic_category_id' => 1), - array('comic_category_id' => 2), - array('comic_category_id' => 1) - ), - array( - array('comic_category_id' => 1), - array('cp' => array( - 'comic_category_id' => 2), - ), - array('comic_category_id' => 2) - ), - array( - array('comic_category_id' => 1), - array('cp' => array( - 'comic_category_id' => "cat"), - ), - array('comic_category_id' => 1) - ), - array( - array('comic_category_id' => 1), - array('cp' => array( - 'comic_category_id' => 3 - )), - array('comic_category_id' => 1) - ), array( array('comic_dimensions' => '150x150'), array('cp' => array( @@ -138,26 +62,25 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { function testHandleUpdate($original, $change, $new) { $this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init')); $this->admin->comicpress->comicpress_options = array( - 'comic_category_id' => 1, 'comic_dimensions' => '760x', 'rss_dimensions' => '350x', 'archive_dimensions' => '125x' ); $this->admin->comicpress->comicpress_options = array_merge($this->admin->comicpress->comicpress_options, $original); - + add_category(2, (object)array('name' => 'test')); - + $_POST = $change; if (isset($_POST['cp'])) { $this->admin->handle_update_comicpress_options($_POST['cp']); } - + foreach ($new as $key => $value) { $this->assertEquals($value, $this->admin->comicpress->comicpress_options[$key]); } } - + function providerTestUpdateAttachments() { return array( array( @@ -187,7 +110,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { 'post_parent' => 0 ), ), - ), + ), array( array( 'post' => array( @@ -204,9 +127,9 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { ), ), ) - ); + ); } - + /** * @dataProvider providerTestUpdateAttachments */ @@ -225,20 +148,20 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { break; } } - + $_POST = array( 'attachments' => array('1' => $changes) ); - + $this->admin->handle_update_attachments(); - + foreach ($expected_settings as $settings_type => $settings) { switch ($settings_type) { case "post_meta": foreach ($settings as $key => $value) { $this->assertEquals($value, get_post_meta(1, $key, true)); } - break; + break; case "post": $post = get_post(1); foreach ($settings as $key => $value) { @@ -247,7 +170,7 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { } } } - + function providerTestHandleUpdateOverridePartial() { return array( array(