media stuff
This commit is contained in:
parent
c781cab239
commit
ca97d7cd85
@ -3,7 +3,7 @@
|
|||||||
require_once('ComicPressStoryline.inc');
|
require_once('ComicPressStoryline.inc');
|
||||||
|
|
||||||
class ComicPressTagBuilderFactory {
|
class ComicPressTagBuilderFactory {
|
||||||
private $storyline, $dbi;
|
public $storyline, $dbi;
|
||||||
|
|
||||||
public function __construct($dbi = null) {
|
public function __construct($dbi = null) {
|
||||||
$this->storyline = new ComicPressStoryline();
|
$this->storyline = new ComicPressStoryline();
|
||||||
@ -45,6 +45,27 @@ class ComicPressTagBuilderFactory {
|
|||||||
return $comicpress->find_file($name, $path, $categories);
|
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.
|
* 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.
|
* @param object $use_this_post If provided, after saving the current post, set up this post for template tag use.
|
||||||
|
@ -345,28 +345,43 @@ class ComicPressTagBuilderTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals(array('post-media'), $core->media());
|
$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() {
|
function testComicPressComicPost() {
|
||||||
$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')));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCategoryStructure() {
|
function testCategoryStructure() {
|
||||||
$storyline = new ComicPressStoryline();
|
$storyline = new ComicPressStoryline();
|
||||||
$storyline->set_flattened_storyline('0/1,0/2,0/3');
|
$storyline->set_flattened_storyline('0/1,0/2,0/3');
|
||||||
|
Loading…
Reference in New Issue
Block a user