From 8b34c320c33adecc24202e77c3e33fac5be42d21 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 6 Jul 2009 22:19:18 -0400 Subject: [PATCH] got dimensions updates working --- options.php | 25 +++++++++++++++++++++++-- test/OptionsPageTest.php | 31 +++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/options.php b/options.php index c2ea21e..6ec1260 100644 --- a/options.php +++ b/options.php @@ -83,6 +83,7 @@ class ComicPressOptionsAdmin { function handle_update() { if (isset($_POST['cp'])) { + $this->get_comicpress_options(); foreach ($this->comicpress_options as $option => $value) { if (isset($_POST['cp'][$option])) { switch ($option) { @@ -96,13 +97,33 @@ class ComicPressOptionsAdmin { break; case 'comic_dimensions': case 'rss_dimensions': - case 'tumbnail_dimensions': + case 'thumbnail_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_options[$option] = implode("x", $dim_parts); + } + } break; } } } + $this->update_comicpress_options(); } - $this->update_comicpress_options(); } } diff --git a/test/OptionsPageTest.php b/test/OptionsPageTest.php index 19affe7..ab2b709 100644 --- a/test/OptionsPageTest.php +++ b/test/OptionsPageTest.php @@ -114,10 +114,37 @@ class OptionsPageTest extends PHPUnit_Framework_TestCase { array( array('comic_category_id' => 1), array('cp' => array( - 'comic_category_id' => 3), - ), + 'comic_category_id' => 3 + )), array('comic_category_id' => 1) ), + array( + array('comic_dimensions' => '150x150'), + array('cp' => array( + 'comic_dimensions' => 'test' + )), + array('comic_dimensions' => '150x150') + ), + array( + array('comic_dimensions' => '150x150'), + array('cp' => array( + 'comic_dimensions' => array( + 'width' => '150', + 'height' => '' + ) + )), + array('comic_dimensions' => '150x') + ), + array( + array('comic_dimensions' => '150x150'), + array('cp' => array( + 'comic_dimensions' => array( + 'width' => '150.1', + 'height' => '' + ) + )), + array('comic_dimensions' => '150x150') + ), ); }