comicpress-theme-core/test/ComicPressComicPostTest.php
2009-08-02 20:32:08 -04:00

203 lines
5.1 KiB
PHP

<?php
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
require_once(dirname(__FILE__) . '/../classes/ComicPressComicPost.inc');
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->p = new ComicPressComicPost();
}
function providerTestGenerateComicTag() {
return array(
array(
"150x150",
),
array(
false,
)
);
}
/**
* @dataProvider providerTestGenerateComicTag
*/
function testGenerateComicImgTag($dimensions) {
$this->p->comicpress = (object)array(
'comicpress_options' => array(
'comic_dimensions' => $dimensions
)
);
$source = $this->p->get_comic_img_tag("test.gif", "comic");
if (count($parts = explode("x", $dimensions)) == 2) {
list($width, $height) = $parts;
$dimensions = compact('width', 'height');
}
foreach (array('width', 'height') as $field) {
if (isset($dimensions[$field])) {
$this->assertTrue(strpos($source, "${field}=\"{$dimensions[$field]}\"") !== false, $field);
} else {
$this->assertTrue(strpos($source, "${field}=") === false, 'not set');
}
}
}
function providerTestBreakdownComicOrderingString() {
return array(
array(
"",
array()
),
array(
"comic|123",
array()
),
array(
"comic|123:meow",
array()
),
array(
"comic123:meow",
array("comic123" => array())
),
array(
"comic123:1",
array("comic123" => array(1))
),
array(
"comic123:1,2;comic234:meow",
array("comic123" => array(1, 2),
"comic234" => array())
),
);
}
/**
* @dataProvider providerTestBreakdownComicOrderingString
*/
function testBreakdownComicOrderingString($string, $expected_result) {
$this->assertEquals($expected_result, $this->p->breakdown_comic_ordering_string($string));
}
function testNormalizeComicImageOrdering() {
$p = $this->getMock('ComicPressComicPost', array('get_comic_image_attachments'));
$comic_attachments = array(
array(
'ID' => 2,
'post_parent' => 1,
'post_title' => 'Comic one',
'post_meta' => array(
'comic_image_type' => 'comic'
),
'post_date' => 1
),
array(
'ID' => 3,
'post_parent' => 1,
'post_title' => 'Comic two',
'post_meta' => array(
'comic_image_type' => 'comic'
),
'post_date' => 2
),
array(
'ID' => 4,
'post_parent' => 1,
'post_title' => 'Comic three',
'post_meta' => array(
'comic_image_type' => 'rss'
),
'post_date' => 4
),
array(
'ID' => 5,
'post_parent' => 1,
'post_title' => 'Comic four',
'post_meta' => array(
'comic_image_type' => 'rss'
),
'post_date' => 3
),
);
$attachments = array();
foreach ($comic_attachments as $attachment_info) {
$attachment = (object)array();
foreach ($attachment_info as $field => $value) {
switch ($field) {
case "post_meta":
foreach ($value as $meta => $meta_value) {
update_post_meta($attachment_info['ID'], $meta, $meta_value);
}
break;
case "post_date":
$attachment->{$field} = date("r", $value);
break;
default:
$attachment->{$field} = $value;
break;
}
}
$attachments[] = $attachment;
}
$p->expects($this->any())->method('get_comic_image_attachments')->will($this->returnValue($attachments));
wp_insert_post((object)array('ID' => 1));
update_post_meta(1, 'comic_ordering', "comic:3,2");
$p->post = (object)array('ID' => 1);
$result = $p->normalize_comic_image_ordering();
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), $result);
$this->assertEquals('comic:3,2;rss:5,4', get_post_meta(1, 'comic_ordering', true));
}
function providerTestChangeComicImageOrdering() {
return array(
array(
'comic:1,2,3',
array(
'comic' => array('1' => 3, '2' => 1, '3' => 2)
),
'comic:2,3,1'
),
array(
'comic:1,2,3',
array(
'comic' => array('1' => 2, '2' => 2, '3' => 1)
),
'comic:3,1,2'
),
array(
'comic:1,2,3',
array(
'comic' => array('1' => 1, '2' => 2)
),
'comic:1,2,3'
),
);
}
/**
* @dataProvider providerTestChangeComicImageOrdering
*/
function testChangeComicImageOrdering($current_ordering, $revised_ordering, $expected_result) {
update_post_meta(1, 'comic_ordering', $current_ordering);
$this->p->post = (object)array('ID' => 1);
$this->p->change_comic_image_ordering($revised_ordering);
$this->assertEquals($expected_result, get_post_meta(1, 'comic_ordering', true));
}
}
?>