swap out media functions for builder tags

This commit is contained in:
John Bintz 2010-02-03 20:00:55 -05:00
parent 4db64182ea
commit 2b3940b1f7
4 changed files with 34 additions and 56 deletions

View File

@ -51,7 +51,13 @@ class ComicPressTagBuilder {
$this->parent_post = $parent_post;
}
public function _setup_postdata($post) { setup_postdata($post); }
public function _setup_postdata($post) {
setup_postdata($post);
}
public function _new_comicpresscomicpost($post) {
return new ComicPressComicPost($post);
}
public function __call($method, $arguments) {
$ok = false;
@ -101,6 +107,9 @@ class ComicPressTagBuilder {
return get_permalink($this->post->ID);
case 'post':
return $this->post;
case 'media':
$comic_post = $this->_new_comicpresscomicpost($this->post);
return $comic_post->get_attachments_with_children(true);
default:
$methods = $this->parse_method($method, $arguments);
if (!empty($methods)) {

View File

@ -66,21 +66,6 @@ function Unprotect() {
$__post = $__wp_query = null;
}
/**
* Retrieve post attachment info to be used with EM().
* @param object $override_post The post to retrieve attachment info for. If not provided, use the current Loop post.
* @return array The list of attachment info.
*/
function M($override_post = null) {
global $post, $__attachments;
$post_to_use = !is_null($override_post) ? $override_post : $post;
$comic_post = new ComicPressComicPost($post_to_use);
$__attachments = $comic_post->get_attachments_with_children(true);
return $__attachments;
}
/**
* Call a function on the backend specified by the provided attachment info.
* @param array $attachment_info The post attachment info from M().

View File

@ -70,7 +70,7 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
array('first')
),
array('get_first_post', array(2,3,4), (object)array('other-post' => 'post')),
)
),
);
}
@ -313,4 +313,27 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('2010-01-01', $core->first_date_in_1('Y-m-d'));
}
function testMedia() {
$core = $this->getMock('ComicPressTagBuilder', array('_new_comicpresscomicpost'), array(), 'ComicPressTagBuilder_Mock', false);
$core->post = 'this-post';
$comicpresscomicpost = $this->getMock('ComicPressComicPost', array('get_attachments_with_children'));
$comicpresscomicpost->expects($this->once())
->method('get_attachments_with_children')
->with(true)
->will($this->returnValue(array('post-media')));
$core->expects($this->once())
->method('_new_comicpresscomicpost')
->with('this-post')
->will($this->returnValue($comicpresscomicpost));
$this->assertEquals(array('post-media'), $core->media());
}
function testComicPressComicPost() {
$a = ComicPressTagBuilder::_new_comicpresscomicpost('test');
$this->assertTrue(is_a($a, 'ComicPressComicPost'));
}
}

View File

@ -9,45 +9,6 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
_reset_wp();
}
function providerTestM() {
return array(
array(null),
array((object)array('ID' => 2))
);
}
/**
* @dataProvider providerTestM
*/
function testM($post_to_use) {
global $post, $__attachments;
$post = (object)array('ID' => 1);
$backend = $this->getMock('ComicPressFakeBackend', array('generate_from_post'));
$post_to_test = (!is_null($post_to_use)) ? $post_to_use : $post;
$backend->expects($this->once())->method('generate_from_post')->with($post_to_test)->will($this->returnValue(array('test-1', 'test-2', 'test-3')));
$comicpress = ComicPress::get_instance();
$comicpress->backends = array($backend);
$comicpress->comicpress_options['image_types'] = array();
update_post_meta($post_to_test->ID, 'image-ordering', array(
'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2'))
));
$result = M($post_to_use);
$this->assertEquals(array(
array('default' => 'test-1', 'rss' => 'test-2')
), $result);
$this->assertEquals($result, $__attachments);
$this->assertEquals(array(
'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-2'))
), get_post_meta($post_to_test->ID, 'image-ordering', true));
}
function providerTestProtect() {
return array(
array(null, 'test'),