diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 4d1379e..618ca9c 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -209,5 +209,3 @@ class ComicPressComicPost { return $attachments_with_children; } } - -?> diff --git a/classes/ComicPressTagBuilder.inc b/classes/ComicPressTagBuilder.inc index ef17a3f..bd7f50a 100644 --- a/classes/ComicPressTagBuilder.inc +++ b/classes/ComicPressTagBuilder.inc @@ -108,8 +108,13 @@ class ComicPressTagBuilder { case 'post': return $this->post; case 'media': - $comic_post = $this->_new_comicpresscomicpost($this->post); - return $comic_post->get_attachments_with_children(true); + if (isset($this->post)) { + $comic_post = $this->_new_comicpresscomicpost($this->post); + return $comic_post->get_attachments_with_children(true); + } else { + $which = (isset($arguments[1])) ? $arguments[1] : 'default'; + return ComicPressBackend::generate_from_id($arguments[0][$which]); + } default: $methods = $this->parse_method($method, $arguments); if (!empty($methods)) { diff --git a/functions.inc b/functions.inc index 2bbc229..edee442 100644 --- a/functions.inc +++ b/functions.inc @@ -66,31 +66,6 @@ function Unprotect() { $__post = $__wp_query = null; } -/** - * Call a function on the backend specified by the provided attachment info. - * @param array $attachment_info The post attachment info from M(). - * @param string $which The subattachment short name to reference. - * @param string $action The method to call on the backend. - * @return object The result from the backend. - */ -function EM($attachment_info, $which = 'default', $action = 'embed') { - if (substr($action, 0, 1) != '_') { - $args = func_get_args(); - - if (isset($attachment_info[$which])) { - if (($attachment = ComicPressBackend::generate_from_id($attachment_info[$which])) !== false) { - if (method_exists($attachment, $action)) { - return call_user_func_array(array($attachment, $action), array_merge(array($which), array_slice($args, 3))); - } - - switch ($action) { - case 'object': return $attachment; - } - } - } - } -} - /** * Return the raw storyline structure. * @return array The astoryline structure from ComicPressStoryline diff --git a/test/ComicPressTagBuilderTest.php b/test/ComicPressTagBuilderTest.php index 992758c..bdd880f 100644 --- a/test/ComicPressTagBuilderTest.php +++ b/test/ComicPressTagBuilderTest.php @@ -347,4 +347,21 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { $a = ComicPressTagBuilder::_new_comicpresscomicpost('test'); $this->assertTrue(is_a($a, 'ComicPressComicPost')); } + + function testFactoryMedia() { + $dbi = $this->getMock('ComicPressDBInterface'); + $core = new ComicPressTagBuilderFactory($dbi); + + $comicpress = ComicPress::get_instance(true); + + $test_backend = $this->getMock('ComicPressFakeBackendFactory', array('generate_from_id')); + $test_backend->expects($this->once()) + ->method('generate_from_id') + ->with('my-image') + ->will($this->returnValue('my-backend')); + + $comicpress->backends = array($test_backend); + + $this->assertEquals('my-backend', $core->media(array('default' => 'my-image'))); + } } diff --git a/test/FunctionsTest.php b/test/FunctionsTest.php index 1ea5b0d..ea5b337 100644 --- a/test/FunctionsTest.php +++ b/test/FunctionsTest.php @@ -61,64 +61,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase { $this->assertTrue(is_null($__wp_query)); } - function providerTestEM() { - return array( - array(array(), 'embed', 'default', false, false), - array( - array('default' => 'test-1'), - 'embed', - 'default', - 'test-1', - 'embed' - ), - array( - array('default' => 'test-1'), - 'cats', - 'default', - 'test-1', - false - ), - array( - array('default' => 'test-1'), - 'embed', - 'comic', - false, - false - ), - array( - array('default' => 'test-1', 'comic' => 'test-2'), - 'embed', - 'comic', - 'test-2', - 'embed' - ), - - ); - } - - /** - * @dataProvider providerTestEM - */ - function testEM($info, $action, $which, $will_get_id, $expected_result) { - $backend = $this->getMock('ComicPressFakeBackend', array('generate_from_id', 'embed', 'url')); - if (is_string($will_get_id)) { - $backend->expects($this->once())->method('generate_from_id')->with($will_get_id)->will($this->returnValue($backend)); - - if (method_exists($backend, $action)) { - $backend->expects($this->once())->method($action)->will($this->returnValue($expected_result)); - } else { - $backend->expects($this->never())->method($action); - } - } else { - $backend->expects($this->never())->method('generate_from_id'); - } - - $comicpress = ComicPress::get_instance(); - $comicpress->backends = array($backend); - - $this->assertEquals($expected_result, EM($info, $which, $action)); - } - function testSL() { $s = new ComicPressStoryline(); $s->set_flattened_storyline('0/1,0/2,0/2/3');