handle post media update

This commit is contained in:
John Bintz 2009-12-04 22:36:00 -05:00
parent 06a765ad55
commit 5a717b627f
3 changed files with 45 additions and 7 deletions

View File

@ -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() {

View File

@ -1,5 +1,6 @@
<input type="hidden" name="cp[_nonce]" value="<?php echo esc_attr($nonce) ?>" />
<input type="hidden" name="cp[action]" value="post-media-update" />
<input type="hidden" name="cp[post_id]" value="<?php echo $post->ID ?>" />
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
<p>
<em>Enter in relative or absolute URLs to the images you want to use for this post. This will override file system searches.</em>

View File

@ -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));
}
}