comicpress-core/test/ComicPressComicPostTest.php

163 lines
4.7 KiB
PHP
Raw Normal View History

<?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
2009-11-07 17:18:53 +00:00
require_once('ComicPressComicPost.inc');
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->p = new ComicPressComicPost();
}
2009-11-09 03:11:26 +00:00
function providerTestNormalizeOrdering() {
return array(
2009-11-11 12:49:54 +00:00
array(
false,
array('attachment-1' => array('enabled' => false), 'attachment-2' => array('enabled' => true)),
false,
),
array(
2009-11-09 03:11:26 +00:00
array('attachment-1'),
array(),
2009-11-09 04:13:34 +00:00
array('attachment-1' => array('enabled' => true))
2009-11-09 03:11:26 +00:00
),
array(
array('attachment-1'),
2009-11-09 04:13:34 +00:00
array('attachment-1' => array('enabled' => false), 'attachment-2' => array('enabled' => true)),
array('attachment-1' => array('enabled' => false))
2009-11-09 03:11:26 +00:00
),
array(
array('attachment-1'),
2009-11-09 04:13:34 +00:00
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => array('attachment-2' => true)))),
array('attachment-1' => array('enabled' => true))
2009-11-09 03:11:26 +00:00
),
2009-11-11 12:49:54 +00:00
array(
array('attachment-1', 'attachment-2'),
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => array('attachment-2' => true, 'attachment-3' => true)))),
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => array('attachment-2' => true))))
),
2009-11-09 03:11:26 +00:00
array(
array('attachment-1', 'attachment-2', 'attachment-3'),
2009-11-09 04:13:34 +00:00
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => array('attachment-2' => true)))),
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => array('attachment-2' => true))), 'attachment-3' => array('enabled' => true))
2009-11-09 03:11:26 +00:00
),
);
}
/**
* @dataProvider providerTestNormalizeOrdering
*/
function testNormalizeOrdering($attachments, $current_meta, $expected_result) {
$p = $this->getMock('ComicPressComicPost', array('get_attachments'));
2009-11-11 12:49:54 +00:00
if (is_array($attachments)) {
$attachment_objects = array();
foreach ($attachments as $attachment) {
$attachment_objects[] = (object)array('id' => $attachment);
}
} else {
$attachment_objects = $attachments;
2009-07-22 21:59:59 +00:00
}
2009-11-09 03:11:26 +00:00
$p->expects($this->any())->method('get_attachments')->will($this->returnValue($attachment_objects));
2009-07-22 21:59:59 +00:00
wp_insert_post((object)array('ID' => 1));
2009-11-09 03:11:26 +00:00
update_post_meta(1, 'image-ordering', $current_meta);
2009-08-03 00:32:08 +00:00
$p->post = (object)array('ID' => 1);
2009-11-09 03:11:26 +00:00
$this->assertEquals($expected_result, $p->normalize_ordering());
2009-11-11 12:49:54 +00:00
if ($expected_result === false) {
$this->assertEquals($current_meta, get_post_meta(1, 'image-ordering', true));
} else {
$this->assertEquals($expected_result, get_post_meta(1, 'image-ordering', true));
}
}
2009-11-09 03:11:26 +00:00
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
}
2009-11-09 03:11:26 +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-11-09 03:11:26 +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);
2009-11-09 03:11:26 +00:00
2009-08-03 00:32:08 +00:00
$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
2009-11-07 18:47:08 +00:00
function providerTestFindParents() {
return array(
array(
array(),
array()
),
array(
array(1),
array(1 => 'root')
),
array(
array(2),
array(2 => 'comic', 1 => 'root')
),
array(
array(3),
array(3 => 'part-1', 2 => 'comic', 1 => 'root')
),
array(
array(4),
array(4 => 'blog', 1 => 'root')
),
array(
array(1, 4),
array()
),
);
}
2009-11-09 03:11:26 +00:00
2009-11-07 18:47:08 +00:00
/**
* @dataProvider providerTestFindParents
*/
function testFindParents($post_categories, $expected_result) {
add_category(1, (object)array('slug' => 'root', 'parent' => 0));
add_category(2, (object)array('slug' => 'comic', 'parent' => 1));
add_category(3, (object)array('slug' => 'part-1', 'parent' => 2));
add_category(4, (object)array('slug' => 'blog', 'parent' => 1));
2009-11-09 03:11:26 +00:00
2009-11-07 18:47:08 +00:00
wp_set_post_categories(1, $post_categories);
2009-11-09 03:11:26 +00:00
2009-11-07 18:47:08 +00:00
$this->p->post = (object)array('ID' => 1);
2009-11-09 03:11:26 +00:00
2009-11-07 18:47:08 +00:00
$this->assertEquals($expected_result, $this->p->find_parents());
2009-11-06 12:33:06 +00:00
}
}
?>