comicpress-core/test/backends/ComicPressBackendURLFactoryTest.php

77 lines
1.9 KiB
PHP
Raw Normal View History

2009-12-06 21:30:45 +00:00
<?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'
);
2009-12-09 01:09:34 +00:00
$valid_backend->alt_text = 'alt text';
$valid_backend->hover_text = 'hover text';
2009-12-06 21:30:45 +00:00
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));
2009-12-09 01:09:34 +00:00
update_post_meta(1, 'backend_url_image_urls', array(
'12345' => array(
'comic' => 'comic',
'rss' => 'rss',
'__alt_text' => 'alt text',
'__hover_text' => 'hover text'
)
));
2009-12-06 21:30:45 +00:00
$this->assertEquals($expected_result, $this->fa->generate_from_id($id));
}
}