From ca97d7cd8572aa8422ec1170de3b5a08c2c8145c Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 10 Feb 2010 21:29:19 -0500 Subject: [PATCH] media stuff --- classes/ComicPressTagBuilder.inc | 23 ++++++++++++++- test/ComicPressTagBuilderTest.php | 49 ++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/classes/ComicPressTagBuilder.inc b/classes/ComicPressTagBuilder.inc index f4c64a3..353a15c 100644 --- a/classes/ComicPressTagBuilder.inc +++ b/classes/ComicPressTagBuilder.inc @@ -3,7 +3,7 @@ require_once('ComicPressStoryline.inc'); class ComicPressTagBuilderFactory { - private $storyline, $dbi; + public $storyline, $dbi; public function __construct($dbi = null) { $this->storyline = new ComicPressStoryline(); @@ -45,6 +45,27 @@ class ComicPressTagBuilderFactory { return $comicpress->find_file($name, $path, $categories); } + public function _new_comicpresstagbuilder($p, $s, $d) { + return new ComicPressTagBuilder($p, $s, $d); + } + + public function media($index = null) { + global $post; + + $tag = $this->_new_comicpresstagbuilder($post, $this->storyline, $this->dbi); + $media = $tag->media(); + if (is_null($index)) { + return $media; + } else { + $index = (int)$index; + if (isset($media[$index])) { + return $media[$index]; + } else { + return false; + } + } + } + /** * Protect global $post and $wp_query. * @param object $use_this_post If provided, after saving the current post, set up this post for template tag use. diff --git a/test/ComicPressTagBuilderTest.php b/test/ComicPressTagBuilderTest.php index 4b9a50e..f060acd 100644 --- a/test/ComicPressTagBuilderTest.php +++ b/test/ComicPressTagBuilderTest.php @@ -345,28 +345,43 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array('post-media'), $core->media()); } + function testMediaForCurrentPost() { + global $post; + $post = 'this-post'; + + $core = $this->getMock( + 'ComicPressTagBuilderFactory', + array('_new_comicpresstagbuilder'), + array(), + 'ComicPressTagBuilderFactory_' . md5(rand()), + false + ); + + $core->dbi = 'dbi'; + $core->storyline = 'storyline'; + + $tag_builder = $this->getMock('ComicPressTagBuilder', array('media'), array($post, 'storyline', 'dbi')); + + $tag_builder->expects($this->any()) + ->method('media') + ->will($this->returnValue(array('post-media'))); + + $core->expects($this->any()) + ->method('_new_comicpresstagbuilder') + ->with($post, 'storyline', 'dbi') + ->will($this->returnValue($tag_builder)); + + $this->assertEquals(array('post-media'), $core->media()); + + $this->assertEquals('post-media', $core->media(0)); + $this->assertEquals(false, $core->media(1)); + } + function testComicPressComicPost() { $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'))); - } - function testCategoryStructure() { $storyline = new ComicPressStoryline(); $storyline->set_flattened_storyline('0/1,0/2,0/3');