back engineer attachment
This commit is contained in:
parent
621b2b1cbe
commit
bf9ea351f0
@ -66,6 +66,19 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
|||||||
|
|
||||||
function get_info() { return array(); }
|
function get_info() { return array(); }
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
function generate_from_id($id) {
|
||||||
|
if (strpos($id, 'attachment-') === 0) {
|
||||||
|
$id = str_replace('attachment-', '', $id);
|
||||||
|
if (is_numeric($id)) {
|
||||||
|
$post = get_post($id);
|
||||||
|
if (!empty($post)) {
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -76,4 +76,22 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
|||||||
_set_image_downsize_result(1, 'comic', $image_downsize_result);
|
_set_image_downsize_result(1, 'comic', $image_downsize_result);
|
||||||
$this->assertEquals($expected_result, $this->ba->url('comic'));
|
$this->assertEquals($expected_result, $this->ba->url('comic'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestGenerateFromID() {
|
||||||
|
return array(
|
||||||
|
array(null, false),
|
||||||
|
array(1, false),
|
||||||
|
array('attachment-1', true),
|
||||||
|
array('attachment-2', false)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestGenerateFromID
|
||||||
|
*/
|
||||||
|
function testGenerateFromID($id, $is_successful) {
|
||||||
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
|
$this->assertTrue($is_successful == is_object($this->ba->generate_from_id($id)));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user