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

@ -18,4 +18,15 @@ class ComicPressBackend {
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url(), $this->alt(), $this->title(), implode("", $extras)); $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); 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); $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));
}
} }