set up backward resolving of ids

This commit is contained in:
John Bintz 2009-11-11 22:07:34 -05:00
parent 8c9d8c02d6
commit 621b2b1cbe
3 changed files with 34 additions and 2 deletions

View File

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

View File

@ -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('<img src="%s" alt="%s" title="%s" %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;
}
}

View File

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