comicpress-core/test/ComicPressComicPostTest.php

170 lines
4.5 KiB
PHP
Raw Normal View History

<?php
require_once('PHPUnit/Framework.php');
require_once('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 testNormalizeComicImageOrdering() {
2009-07-22 21:59:59 +00:00
$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));
2009-10-18 23:21:00 +00:00
update_post_meta(1, 'comic_ordering', array('comic' => array(3)));
2009-07-22 21:59:59 +00:00
2009-08-03 00:32:08 +00:00
$p->post = (object)array('ID' => 1);
$result = $p->normalize_comic_image_ordering();
2009-07-22 21:59:59 +00:00
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), $result);
2009-10-18 23:21:00 +00:00
$this->assertEquals(array('comic' => array(3,2), 'rss' => array(5,4)), get_post_meta(1, 'comic_ordering', true));
}
2009-08-01 15:05:39 +00:00
function providerTestChangeComicImageOrdering() {
2009-08-03 00:32:08 +00:00
return array(
array(
2009-10-18 23:21:00 +00:00
array('comic' => array(1,2,3)),
2009-08-03 00:32:08 +00:00
array(
2009-11-04 02:45:56 +00:00
'comic' => array(2,3,1)
2009-08-03 00:32:08 +00:00
),
2009-10-18 23:21:00 +00:00
array('comic' => array(2,3,1))
2009-08-03 00:32:08 +00:00
),
array(
2009-10-18 23:21:00 +00:00
array('comic' => array(1,2,3)),
2009-08-03 00:32:08 +00:00
array(
2009-11-04 02:45:56 +00:00
'comic' => array(3,1,2)
2009-08-03 00:32:08 +00:00
),
2009-10-18 23:21:00 +00:00
array('comic' => array(3,1,2))
2009-08-03 00:32:08 +00:00
),
array(
2009-10-18 23:21:00 +00:00
array('comic' => array(1,2,3)),
2009-08-03 00:32:08 +00:00
array(
2009-11-04 02:45:56 +00:00
'comic' => array(1,2)
2009-08-03 00:32:08 +00:00
),
2009-10-18 23:21:00 +00:00
array('comic' => array(1,2,3))
2009-08-03 00:32:08 +00:00
),
);
2009-08-01 15:05:39 +00:00
}
/**
* @dataProvider providerTestChangeComicImageOrdering
2009-11-04 02:45:56 +00:00
* @covers ComicPressComicPost::change_comic_image_ordering
2009-08-01 15:05:39 +00:00
*/
function testChangeComicImageOrdering($current_ordering, $revised_ordering, $expected_result) {
2009-08-03 00:32:08 +00:00
update_post_meta(1, 'comic_ordering', $current_ordering);
2009-08-01 15:05:39 +00:00
2009-08-03 00:32:08 +00:00
$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));
2009-08-01 15:05:39 +00:00
}
2009-11-06 12:33:06 +00:00
function testFindParents() {
}
}
?>