From 5a717b627fed53eec050a71d294c6f09f3bef4ad Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 4 Dec 2009 22:36:00 -0500 Subject: [PATCH] handle post media update --- .../ComicPressPostMediaHandlingMetabox.inc | 28 +++++++++++++++++-- .../partials/post-media-handling/metabox.inc | 1 + ...ComicPressPostMediaHandlingMetaboxTest.php | 23 ++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/classes/ComicPressPostMediaHandlingMetabox.inc b/classes/ComicPressPostMediaHandlingMetabox.inc index 6302321..5ee030b 100644 --- a/classes/ComicPressPostMediaHandlingMetabox.inc +++ b/classes/ComicPressPostMediaHandlingMetabox.inc @@ -2,14 +2,36 @@ class ComicPressPostMediaHandlingMetabox { function __comicpress_init() { - $n = new ComicPressPostMediaHandlingMetabox(); - add_action('admin_menu', array(&$n, 'admin_menu')); + add_action('admin_menu', array('ComicPressPostMediaHandlingMetabox', 'admin_menu')); } function handle_update() {} + function _get_valid_types() { + return array_keys(ComicPressMediaHandling::_bundle_global_variables()); + } + + function handle_post_media_update($info) { + if (isset($info['post_id'])) { + if (is_numeric($info['post_id'])) { + $result = array(); + if (isset($info['urls'])) { + if (is_array($info['urls'])) { + $valid_types = $this->_get_valid_types(); + foreach ($info['urls'] as $field => $value) { + if (in_array($field, $valid_types)) { + $result[$field] = strip_tags($value); + } + } + } + } + update_post_meta($info['post_id'], 'backend_url_images', $result); + } + } + } + function admin_menu() { - add_meta_box('comicpress-post-media-handling', __('ComicPress Post Media', 'comicpress'), array(&$this, 'metabox'), 'post', 'normal', 'low'); + add_meta_box('comicpress-post-media-handling', __('ComicPress Post Media', 'comicpress'), array('ComicPressPostMediaHandlingMetabox', 'metabox'), 'post', 'normal', 'low'); } function metabox() { diff --git a/classes/partials/post-media-handling/metabox.inc b/classes/partials/post-media-handling/metabox.inc index 04e5c77..43f5a45 100644 --- a/classes/partials/post-media-handling/metabox.inc +++ b/classes/partials/post-media-handling/metabox.inc @@ -1,5 +1,6 @@ +

Enter in relative or absolute URLs to the images you want to use for this post. This will override file system searches. diff --git a/test/ComicPressPostMediaHandlingMetaboxTest.php b/test/ComicPressPostMediaHandlingMetaboxTest.php index cdf0bce..39c6039 100644 --- a/test/ComicPressPostMediaHandlingMetaboxTest.php +++ b/test/ComicPressPostMediaHandlingMetaboxTest.php @@ -5,16 +5,31 @@ require_once('MockPress/mockpress.php'); require_once(dirname(__FILE__) . '/../classes/ComicPressPostMediaHandlingMetabox.inc'); class ComicPressPostMediaHandlingMetaboxTest extends PHPUnit_Framework_TestCase { - function providerTestUpdate() { + function setUp() { + _reset_wp(); + $this->pmh = new ComicPressPostMediaHandlingMetabox(); + } + + function providerTestPostMediaUpdate() { return array( - array(array(), array()) + array(array(), ''), + array(array('post_id' => 'test'), ''), + array(array('post_id' => 1), array()), + array(array('post_id' => 1, 'urls' => false), array()), + array(array('post_id' => 1, 'urls' => array()), array()), + array(array('post_id' => 1, 'urls' => array('test' => 'test')), array()), + array(array('post_id' => 1, 'urls' => array('comic' => 'test')), array('comic' => 'test')), ); } /** - * @dataProvider providerTestUpdate + * @dataProvider providerTestPostMediaUpdate */ - function testUpdate($input, $expected_post_metadata) { + function testPostMediaUpdate($input, $expected_post_metadata) { + $pmh = $this->getMock('ComicPressPostMediaHandlingMetabox', array('_get_valid_types')); + $pmh->expects($this->any())->method('_get_valid_types')->will($this->returnValue(array('comic'))); + $this->pmh->handle_post_media_update($input); + $this->assertEquals($expected_post_metadata, get_post_meta(1, 'backend_url_images', true)); } }