From e4651dfc5b04431237b6bb7d5a69c05ebb01b8cb Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 12 Feb 2010 18:08:17 -0500 Subject: [PATCH] update options --- .../backends/ComicPressBackendFilesystem.inc | 42 +++++++------ .../ComicPressBackendFilesystemAdminTest.php | 59 +++++++++++++++++++ 2 files changed, 83 insertions(+), 18 deletions(-) diff --git a/classes/backends/ComicPressBackendFilesystem.inc b/classes/backends/ComicPressBackendFilesystem.inc index 636cf4a..67eb63f 100644 --- a/classes/backends/ComicPressBackendFilesystem.inc +++ b/classes/backends/ComicPressBackendFilesystem.inc @@ -348,28 +348,34 @@ class ComicPressBackendFilesystemAdmin { // @codeCoverageIgnoreEnd function handle_update_comicpress_options($info) { - if (isset($info['backend_options']['filesystem'])) { - $info = $info['backend_options']['filesystem']; - $comicpress = ComicPress::get_instance(); + if (is_array($info)) { + if (isset($info['backend_options']['filesystem'])) { + if (is_array($info['backend_options']['filesystem'])) { + $info = $info['backend_options']['filesystem']; + $comicpress = ComicPress::get_instance(); - if (!isset($comicpress->comicpress_options['backend_options'])) { - $comicpress->comicpress_options['backend_options'] = array(); - } - if (!isset($comicpress->comicpress_options['backend_options']['filesystem'])) { - $comicpress->comicpress_options['backend_options']['filesystem'] = array(); - } - - foreach (array('folders', 'search_pattern', 'url_pattern') as $valid_field) { - if (is_array($info[$valid_field])) { - $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = array(); - foreach ($info[$valid_field] as $field => $value) { - $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field][$field] = strip_tags($value); + if (!isset($comicpress->comicpress_options['backend_options'])) { + $comicpress->comicpress_options['backend_options'] = array(); } - } else { - $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = strip_tags($info[$valid_field]); + if (!isset($comicpress->comicpress_options['backend_options']['filesystem'])) { + $comicpress->comicpress_options['backend_options']['filesystem'] = array(); + } + + foreach (array('folders', 'search_pattern', 'url_pattern') as $valid_field) { + if (isset($info[$valid_field])) { + if (is_array($info[$valid_field])) { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = array(); + foreach ($info[$valid_field] as $field => $value) { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field][$field] = strip_tags($value); + } + } else { + $comicpress->comicpress_options['backend_options']['filesystem'][$valid_field] = strip_tags($info[$valid_field]); + } + } + } + $comicpress->save(); } } - $comicpress->save(); } } diff --git a/test/backends/ComicPressBackendFilesystemAdminTest.php b/test/backends/ComicPressBackendFilesystemAdminTest.php index 13431a3..bf3a874 100644 --- a/test/backends/ComicPressBackendFilesystemAdminTest.php +++ b/test/backends/ComicPressBackendFilesystemAdminTest.php @@ -90,5 +90,64 @@ class ComicPressBackendFilesystemAdminTest extends PHPUnit_Framework_TestCase { ComicPressBackendFilesystemAdmin::save_post(1); $this->assertEquals($expected_post_meta, get_post_meta(1, 'backend_filesystem_image_meta', true)); + + $comicpress = ComicPress::get_instance(true); + } + + function providerTestUpdateComicPressOptions() { + return array( + array(false, array()), + array(array(), array()), + array( + array('backend_options' => array( + 'filesystem' => 'test' + )), + array() + ), + array( + array('backend_options' => array( + 'filesystem' => array() + )), + array( + 'backend_options' => array('filesystem' => array()) + ) + ), + array( + array('backend_options' => array( + 'filesystem' => array( + 'search_pattern' => 'value', + 'url_pattern' => 'value', + 'folders' => array( + 'one' => 'value', + 'two' => 'value', + ), + ) + )), + array( + 'backend_options' => array('filesystem' => array( + 'search_pattern' => 'value', + 'url_pattern' => 'value', + 'folders' => array( + 'one' => 'value', + 'two' => 'value' + ) + )) + ) + ), + ); + } + + /** + * @dataProvider providerTestUpdateComicPressOptions + */ + function testUpdateComicPressOptions($info, $expected_comicpress_options) { + $comicpress = ComicPress::get_instance(true); + $comicpress->comicpress_options = array(); + + ComicPressBackendFilesystemAdmin::handle_update_comicpress_options($info); + + $this->assertEquals($expected_comicpress_options, $comicpress->comicpress_options); + + $comicpress = ComicPress::get_instance(true); } }