comicpress-core/test/backends/ComicPressBackendURLFactoryTest.php
2009-12-06 16:30:45 -05:00

68 lines
1.7 KiB
PHP

<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once('backends/ComicPressBackendURL.inc');
class ComicPressBackendUrlFactoryTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->fa = new ComicPressBackendURLFactory();
}
function providerTestGenerateFromPost() {
$valid_backend = new ComicPressBackendURL();
$valid_backend->id = 'url-1-12345';
$valid_backend->urls_by_type = array('comic' => 'test');
return array(
array(false, array()),
array(array(), array()),
array(array('12345' => array('comic' => 'test')), array($valid_backend)),
);
}
/**
* @dataProvider providerTestGenerateFromPost
*/
function testGenerateFromPost($metadata, $expected_backends) {
update_post_meta(1, 'backend_url_image_urls', $metadata);
wp_insert_post((object)array('ID' => 1));
foreach (array(1, (object)array('ID' => 1)) as $source) {
$this->assertEquals($expected_backends, $this->fa->generate_from_post($source));
}
}
function providerTestGenerateFromID() {
$valid_backend = new ComicPressBackendURL();
$valid_backend->id = 'url-1-12345';
$valid_backend->urls_by_type = array(
'comic' => 'comic',
'rss' => 'rss'
);
return array(
array('', false),
array('url-', false),
array('url-1', false),
array('url-2-12345', false),
array('url-1-123456', false),
array('url-1-12345', $valid_backend)
);
}
/**
* @dataProvider providerTestGenerateFromID
*/
function testGenerateFromID($id, $expected_result) {
wp_insert_post((object)array('ID' => 1));
update_post_meta(1, 'backend_url_image_urls', array('12345' => array('comic' => 'comic', 'rss' => 'rss')));
$this->assertEquals($expected_result, $this->fa->generate_from_id($id));
}
}