generate from post

This commit is contained in:
John Bintz 2009-11-24 19:33:16 -05:00
parent b0b01a5177
commit b33093ac13
2 changed files with 60 additions and 0 deletions

View File

@ -4,6 +4,7 @@ require_once(dirname(__file__) . '/../ComicPressBackend.inc');
class ComicPressBackendFilesystem extends ComicPressBackend {
var $search_string = '';
var $id, $type, $filepath;
function process_search_string($post, $type) {
$this->_searches = array($this->search_string);
@ -101,4 +102,35 @@ class ComicPressBackendFilesystem extends ComicPressBackend {
}
return false;
}
function generate_from_post($post) {
$return = array();
$comicpress = ComicPress::get_instance();
if (isset(
$comicpress->comicpress_options['backend_options'],
$comicpress->comicpress_options['backend_options']['filesystem'],
$comicpress->comicpress_options['backend_options']['filesystem']['search_pattern']
)) {
$this->search_pattern = (string)$comicpress->comicpress_options['backend_options']['filesystem']['search_pattern'];
}
if (isset($comicpress->comicpress_options['image_types'])) {
foreach (array_keys($comicpress->comicpress_options['image_types']) as $type) {
$patterns = $this->process_search_string($post, $type);
if (!empty($patterns)) {
$result = $this->find_matching_files($patterns);
if (!empty($result)) {
$fs = new ComicPressBackendFilesystem();
$fs->id = 'filesystem-' . md5($result);
$fs->type = $type;
$fs->filepath = $result;
$return[] = $fs;
}
}
}
}
return $return;
}
}

View File

@ -3,6 +3,7 @@
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('backends/ComicPressBackendFilesystem.inc');
require_once('ComicPress.inc');
require_once('vfsStream/vfsStream.php');
class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase {
@ -87,4 +88,31 @@ class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_match, $this->fs->find_matching_files(array(vfsStream::url('root/comic/2009-01-01*.jpg'))));
}
function testGenerateFromPost() {
$post = (object)array('ID' => 1);
$comicpress = ComicPress::get_instance();
$comicpress->comicpress_options['image_types'] = array(
'comic' => array(),
'rss' => array()
);
$fs = $this->getMock('ComicPressBackendFilesystem', array('process_search_string', 'find_matching_files'));
$fs->expects($this->at(0))->method('process_search_string')->with($post, 'comic')->will($this->returnValue(array('comic')));
$fs->expects($this->at(1))->method('find_matching_files')->with(array('comic'))->will($this->returnValue('comic'));
$fs->expects($this->at(2))->method('process_search_string')->with($post, 'rss')->will($this->returnValue(array('rss')));
$fs->expects($this->at(3))->method('find_matching_files')->with(array('rss'))->will($this->returnValue('rss'));
$return = $fs->generate_from_post($post);
$this->assertEquals(2, count($return));
$this->assertEquals('filesystem-' . md5('comic'), $return[0]->id);
$this->assertEquals('filesystem-' . md5('rss'), $return[1]->id);
$this->assertEquals('comic', $return[0]->type);
$this->assertEquals('rss', $return[1]->type);
$this->assertEquals('comic', $return[0]->filepath);
$this->assertEquals('rss', $return[1]->filepath);
}
}