2009-11-09 03:11:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('PHPUnit/Framework.php');
|
|
|
|
require_once('MockPress/mockpress.php');
|
|
|
|
require_once('backends/ComicPressBackendAttachment.inc');
|
|
|
|
|
|
|
|
class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
|
|
|
function setUp() {
|
|
|
|
_reset_wp();
|
|
|
|
}
|
|
|
|
|
|
|
|
function providerTestGenerateFromPost() {
|
|
|
|
return array(
|
2009-11-11 03:09:53 +00:00
|
|
|
array(array(), array(), false),
|
2009-11-11 03:46:39 +00:00
|
|
|
array(array((object)array('ID' => 2)), array(), array()),
|
|
|
|
array(array((object)array('ID' => 2)), array('managed' => false), array()),
|
|
|
|
array(array((object)array('ID' => 2)), array('managed' => true), array('attachment-2')),
|
2009-11-09 03:11:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerTestGenerateFromPost
|
|
|
|
*/
|
2009-11-11 03:09:53 +00:00
|
|
|
function testGenerateFromPost($get_children_response, $post_meta, $expected_ids) {
|
2009-11-09 03:11:26 +00:00
|
|
|
_set_get_children(array(
|
|
|
|
'post_parent' => 1,
|
|
|
|
'post_type' => 'attachment',
|
|
|
|
'post_mime_type' => 'image'
|
|
|
|
), $get_children_response);
|
|
|
|
|
2009-11-11 03:46:39 +00:00
|
|
|
update_post_meta(2, 'comicpress', $post_meta);
|
2009-11-11 03:09:53 +00:00
|
|
|
|
2009-11-09 03:11:26 +00:00
|
|
|
$results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1));
|
|
|
|
if ($expected_ids === false) {
|
|
|
|
$this->assertTrue(empty($results));
|
|
|
|
} else {
|
|
|
|
$this->assertEquals(count($expected_ids), count($results));
|
|
|
|
foreach ($results as $result) {
|
|
|
|
$this->assertTrue(in_array($result->id, $expected_ids));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|