From c8db41accfa81f3139c4813d7079674112f93435 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sun, 5 Jul 2009 15:46:32 -0400 Subject: [PATCH] add comicpress options and start dimension selector bits --- options.php | 36 ++++++++++++++++++++++++++++++++++++ partials/options-admin.inc | 3 ++- test/OptionsPageTest.php | 17 ++++++++++++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/options.php b/options.php index 1699aaf..c19b52a 100644 --- a/options.php +++ b/options.php @@ -1,8 +1,16 @@ 1, + 'thumbnail_dimensions' => '760x' + ); + function render_admin() { $nonce = wp_create_nonce('comicpress'); + $root_categories = $this->get_root_categories(); + + $this->get_comicpress_options(); include(dirname(__FILE__) . '/partials/options-admin.inc'); } @@ -42,6 +50,34 @@ class ComicPressOptionsAdmin { } return implode("\n", $output); } + + function create_dimension_selector($root, $dimension) { + $output = array(); + + $parts = explode("x", $dimension); + foreach (array( + 'width' => __('Width', 'comicpress'), + 'height' => __('Height', 'comicpress') + ) as $id => $name) { + $dim = array_shift($parts); + if (!empty($dim) && !is_numeric($dim)) { $dim = ""; } + $output[] = ''; + } + return implode("\n", $output); + } + + function get_comicpress_options() { + $result = get_option('comicpress-options'); + if (is_array($result)) { + $this->comicpress_options = $result; + } + } + + function update_comicpress_options() { + if (is_array($this->comicpress_options)) { + update_option('comicpress-options', $this->comicpress_options); + } + } } $comicpress_options_admin = new ComicPressOptionsAdmin(); diff --git a/partials/options-admin.inc b/partials/options-admin.inc index 5e17003..cc8a43d 100644 --- a/partials/options-admin.inc +++ b/partials/options-admin.inc @@ -6,7 +6,8 @@ Master Comic Category - + create_category_options($root_categories, $this->comicpress_options['comicpress_category_id']) ?> diff --git a/test/OptionsPageTest.php b/test/OptionsPageTest.php index 76e1eb6..e697d17 100644 --- a/test/OptionsPageTest.php +++ b/test/OptionsPageTest.php @@ -20,7 +20,7 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { $this->assertTrue(($xml = _to_xml($source)) !== false); foreach (array( '//input[@name="cp[_nonce]" and @value="' . $nonce . '"]' => true, - '//select[@name="cp[comiccat]"]' => true + '//select[@name="cp[comic_category_id]"]' => true ) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } @@ -67,8 +67,6 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { $this->assertTrue(($xml = _to_xml($source, true)) !== false); - var_dump($source); - foreach (array( '//option[@value="1" and @selected="selected"]' => "test-one", '//option[@value="2"]' => "test-two", @@ -77,6 +75,19 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { } } } + + 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); + } + } } ?>