2009-07-10 11:48:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
2009-10-18 21:05:10 +00:00
|
|
|
require_once('MockPress/mockpress.php');
|
2009-11-07 17:18:53 +00:00
|
|
|
require_once('ComicPressComicPost.inc');
|
2009-07-10 11:48:20 +00:00
|
|
|
|
|
|
|
class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
|
|
|
_reset_wp();
|
|
|
|
$this->p = new ComicPressComicPost();
|
|
|
|
}
|
|
|
|
|
2009-11-09 03:11:26 +00:00
|
|
|
function providerTestNormalizeOrdering() {
|
2009-11-12 00:57:19 +00:00
|
|
|
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-12 00:57:19 +00:00
|
|
|
array('attachment-1'),
|
|
|
|
array(),
|
|
|
|
array('attachment-1' => array('enabled' => true))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('attachment-1'),
|
|
|
|
array('attachment-1' => array('enabled' => false), 'attachment-2' => array('enabled' => true)),
|
|
|
|
array('attachment-1' => array('enabled' => false))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
array('attachment-1'),
|
2009-11-13 21:15:36 +00:00
|
|
|
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => 'attachment-2'))),
|
2009-11-12 00:57:19 +00:00
|
|
|
array('attachment-1' => array('enabled' => true))
|
|
|
|
),
|
2009-11-14 00:07:19 +00:00
|
|
|
array(
|
|
|
|
array('attachment-1', 'attachment-2'),
|
|
|
|
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => 'attachment-2', 'comic' => 'attachment-3'))),
|
|
|
|
array('attachment-1' => array('enabled' => true, 'children' => array('rss' => 'attachment-2')))
|
|
|
|
),
|
2009-11-12 00:57:19 +00:00
|
|
|
array(
|
|
|
|
array('attachment-1', 'attachment-2', 'attachment-3'),
|
2009-11-13 21:15:36 +00:00
|
|
|
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => 'attachment-2'))),
|
|
|
|
array('attachment-1' => array('enabled' => false, 'children' => array('rss' => 'attachment-2')), 'attachment-3' => array('enabled' => true))
|
2009-11-12 00:57:19 +00:00
|
|
|
),
|
|
|
|
);
|
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-07-10 11:48:20 +00:00
|
|
|
}
|
2009-11-09 03:11:26 +00:00
|
|
|
|
2009-11-13 21:15:36 +00:00
|
|
|
function providerTestUpdatePostMediaData() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'id' => 'attachment-1',
|
2009-11-14 00:05:41 +00:00
|
|
|
'enabled' => true,
|
2009-11-13 21:15:36 +00:00
|
|
|
'children' => array('rss' => '', 'archive' => '')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'attachment-1' => array('enabled' => true)
|
|
|
|
)
|
2009-11-14 00:05:41 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'id' => 'attachment-1',
|
|
|
|
'enabled' => false,
|
|
|
|
'children' => array('rss' => 'attachment-2', 'archive' => '')
|
|
|
|
)
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'attachment-1' => array('enabled' => false, 'children' => array('rss' => 'attachment-2'))
|
|
|
|
)
|
|
|
|
),
|
2009-11-13 21:15:36 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestUpdatePostMediaData
|
|
|
|
*/
|
|
|
|
function testUpdatePostMediaData($updated_ordering, $expected_meta) {
|
|
|
|
$this->p->post = (object)array('ID' => 1);
|
|
|
|
$this->assertEquals($expected_meta, $this->p->update_post_media_data($updated_ordering));
|
|
|
|
$this->assertEquals($expected_meta, get_post_meta(1, 'image-ordering', true));
|
|
|
|
}
|
|
|
|
|
2009-11-07 18:47:08 +00:00
|
|
|
function providerTestFindParents() {
|
2009-11-12 00:57:19 +00:00
|
|
|
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-07 18:47:08 +00:00
|
|
|
}
|
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
|
|
|
}
|
2009-11-12 00:57:19 +00:00
|
|
|
|
|
|
|
function testGetAttachments() {
|
|
|
|
$backend = $this->getMock('ComicPressFakeBackend', array('generate_from_post'));
|
|
|
|
|
|
|
|
$post = (object)array('ID' => 1);
|
|
|
|
|
|
|
|
$backend->expects($this->once())->method('generate_from_post')->with($post)->will($this->returnValue(array('test')));
|
|
|
|
|
|
|
|
$comicpress = ComicPress::get_instance();
|
|
|
|
$comicpress->backends = array($backend);
|
|
|
|
|
|
|
|
$this->p->post = $post;
|
|
|
|
|
|
|
|
$this->assertEquals(array('test'), $this->p->get_attachments());
|
|
|
|
}
|
2009-07-10 11:48:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|