media stuff

This commit is contained in:
John Bintz 2010-02-10 21:29:19 -05:00
parent c781cab239
commit ca97d7cd85
2 changed files with 54 additions and 18 deletions

View File

@ -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.

View File

@ -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');