move media to tag builder

This commit is contained in:
John Bintz 2010-02-03 21:30:46 -05:00
parent b55fcf268c
commit b37a845743
5 changed files with 24 additions and 87 deletions

View File

@ -209,5 +209,3 @@ class ComicPressComicPost {
return $attachments_with_children; return $attachments_with_children;
} }
} }
?>

View File

@ -108,8 +108,13 @@ class ComicPressTagBuilder {
case 'post': case 'post':
return $this->post; return $this->post;
case 'media': case 'media':
$comic_post = $this->_new_comicpresscomicpost($this->post); if (isset($this->post)) {
return $comic_post->get_attachments_with_children(true); $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: default:
$methods = $this->parse_method($method, $arguments); $methods = $this->parse_method($method, $arguments);
if (!empty($methods)) { if (!empty($methods)) {

View File

@ -66,31 +66,6 @@ function Unprotect() {
$__post = $__wp_query = null; $__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 the raw storyline structure.
* @return array The astoryline structure from ComicPressStoryline * @return array The astoryline structure from ComicPressStoryline

View File

@ -347,4 +347,21 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
$a = ComicPressTagBuilder::_new_comicpresscomicpost('test'); $a = ComicPressTagBuilder::_new_comicpresscomicpost('test');
$this->assertTrue(is_a($a, 'ComicPressComicPost')); $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')));
}
} }

View File

@ -61,64 +61,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
$this->assertTrue(is_null($__wp_query)); $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() { function testSL() {
$s = new ComicPressStoryline(); $s = new ComicPressStoryline();
$s->set_flattened_storyline('0/1,0/2,0/2/3'); $s->set_flattened_storyline('0/1,0/2,0/2/3');