From 621b2b1cbeb67e69833a3b3e95411dfb06428175 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 11 Nov 2009 22:07:34 -0500 Subject: [PATCH] set up backward resolving of ids --- classes/ComicPressAdmin.inc | 2 +- classes/ComicPressBackend.inc | 13 ++++++++++++- test/ComicPressBackendTest.php | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/classes/ComicPressAdmin.inc b/classes/ComicPressAdmin.inc index e73b6f7..6046a0b 100644 --- a/classes/ComicPressAdmin.inc +++ b/classes/ComicPressAdmin.inc @@ -219,7 +219,7 @@ class ComicPressAdmin { foreach ($_POST['attachments'] as $post_id => $settings) { if (isset($settings['comicpress_management'])) { $media_post = get_post($post_id); - if (isset($media_post->post_parent)) { + if (isset($media_post->post_parent)) { $media_post->post_parent = $settings['post_parent']; wp_update_post($media_post); } diff --git a/classes/ComicPressBackend.inc b/classes/ComicPressBackend.inc index e494dc6..79e68db 100644 --- a/classes/ComicPressBackend.inc +++ b/classes/ComicPressBackend.inc @@ -9,7 +9,7 @@ class ComicPressBackend { $extras = array_merge($extras, $dims); } } - + foreach ($extras as $field => $value) { $extras[] = "${field}=\"${value}\" "; unset($extras[$field]); @@ -18,4 +18,15 @@ class ComicPressBackend { $output = sprintf('%s', $this->url(), $this->alt(), $this->title(), implode("", $extras)); return apply_filters('comicpress_embed_image', $output, $this); } + + function generate_from_id($id) { + $comicpress = ComicPress::get_instance(); + foreach ($comicpress->backends as $backend) { + $result = $backend->generate_from_id($id); + if ($result !== false) { + return $result; + } + } + return false; + } } \ No newline at end of file diff --git a/test/ComicPressBackendTest.php b/test/ComicPressBackendTest.php index b9f341e..e79fc4d 100644 --- a/test/ComicPressBackendTest.php +++ b/test/ComicPressBackendTest.php @@ -42,4 +42,25 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase { $this->assertTrue(preg_match($pattern, $result) > 0); } } + + function providerTestGenerateFromID() { + return array( + array(null, false), + array('1', false), + array('attachment-1', (object)array('ID' => 1)) + ); + } + + /** + * @dataProvider providerTestGenerateFromID + */ + function testGenerateFromID($id, $expected_result) { + $backend = $this->getMock('ComicPressFakeBackend', array('generate_from_id')); + $backend->expects($this->once())->method('generate_from_id')->with($id)->will($this->returnValue($expected_result)); + + $comicpress = ComicPress::get_instance(); + $comicpress->backends = array($backend); + + $this->assertEquals($expected_result, ComicPressBackend::generate_from_id($id)); + } } \ No newline at end of file