From 502ecd96969a86267ad819bee2942bdab1fd3d43 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 26 Nov 2009 00:19:19 -0500 Subject: [PATCH] backend url --- classes/backends/ComicPressBackendURL.inc | 37 +++++++++++ test/backends/ComicPressBackendURLTest.php | 71 ++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 classes/backends/ComicPressBackendURL.inc create mode 100644 test/backends/ComicPressBackendURLTest.php diff --git a/classes/backends/ComicPressBackendURL.inc b/classes/backends/ComicPressBackendURL.inc new file mode 100644 index 0000000..7320b83 --- /dev/null +++ b/classes/backends/ComicPressBackendURL.inc @@ -0,0 +1,37 @@ +ID)) { + $valid_url_groups = array(); + if (is_array($url_group)) { + $comicpress = ComicPress::get_instance(); + if (($default_type = $comicpress->get_default_image_type()) !== false) { + foreach ($url_group as $key => $urls) { + $key = null; + $valid_urls = array(); + if (is_array($urls)) { + foreach ($urls as $type => $url) { + if (isset($comicpress->comicpress_options['image_types'][$type])) { + if (@parse_url($url) !== false) { + $valid_urls[$type] = $url; + if ($type == $default_type) { $key = substr(md5($url), 0, 10); } + } + } + } + } + if (!is_null($key) && !empty($valid_urls)) { + $valid_url_groups[$key] = $valid_urls; + } + } + } + } + update_post_meta($post->ID, 'backend_url_image_urls', $valid_url_groups); + } + } + } +} diff --git a/test/backends/ComicPressBackendURLTest.php b/test/backends/ComicPressBackendURLTest.php new file mode 100644 index 0000000..4162b1e --- /dev/null +++ b/test/backends/ComicPressBackendURLTest.php @@ -0,0 +1,71 @@ + 'test'), array()), + array( + array( + 'test' => array( + 'comic' => 'http://test/test', + 'rss' => 'http://test/test2', + ) + ), + array( + $key => array( + 'comic' => 'http://test/test', + 'rss' => 'http://test/test2' + ) + ), + ) + ); + } + + /** + * @dataProvider providerTestUpdatePostUrls + */ + function testUpdatePostUrls($urls, $expected_urls) { + $comicpress = ComicPress::get_instance(true); + $comicpress->comicpress_options['image_types'] = array( + 'comic' => array('default' => true), + 'rss' => array('default' => false), + ); + + wp_insert_post((object)array('ID' => 1)); + + ComicPressBackendURL::update_post_urls(1, $urls); + + $this->assertEquals($expected_urls, get_post_meta(1, 'backend_url_image_urls', true)); + } + + function providerTestGenerateFromPost() { + $valid_backend = new ComicPressBackendURL(); + $valid_backend->id = 'url-1-12345'; + $valid_backend->urls_by_type = array('comic' => 'test'); + + return array( + array(false, array()), + array(array(), array()), + array(array('12345' => array('comic' => 'test')), array()), + ); + } + + /** + * @dataProvider providerTestGenerateFromPost + */ + function testGenerateFromPost($metadata, $expected_backends) { + update_post_meta(1, 'backend_url_images', $metadata); + } +}