From aa7d5e0dfadb1363c90434c2baf11930c5ea28d1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 10 Nov 2009 22:09:53 -0500 Subject: [PATCH] update to some tests --- classes/ComicPressStoryline.inc | 8 +++++--- classes/backends/ComicPressBackendAttachment.inc | 4 +++- test/ComicPressAdminTest.php | 11 +++++++---- test/backends/ComicPressBackendAttachmentTest.php | 12 +++++++++--- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/classes/ComicPressStoryline.inc b/classes/ComicPressStoryline.inc index 55f28db..0ad8bce 100644 --- a/classes/ComicPressStoryline.inc +++ b/classes/ComicPressStoryline.inc @@ -156,11 +156,13 @@ class ComicPressStoryline { if (isset($this->_structure[$id])) { $all_adjacent = array(); do { + $new_id = $this->_structure[$id][$direction]; + $has_adjacent = false; - if (!in_array($id, $all_adjacent)) { + if (!in_array($new_id, $all_adjacent)) { if ($has_adjacent = isset($this->_structure[$id][$direction])) { - $all_adjacent[] = $this->_structure[$id][$direction]; - $id = $this->_structure[$id][$direction]; + $all_adjacent[] = $new_id; + $id = $new_id; } } } while ($has_adjacent); diff --git a/classes/backends/ComicPressBackendAttachment.inc b/classes/backends/ComicPressBackendAttachment.inc index e2d9434..b013330 100644 --- a/classes/backends/ComicPressBackendAttachment.inc +++ b/classes/backends/ComicPressBackendAttachment.inc @@ -17,7 +17,9 @@ class ComicPressBackendAttachment extends ComicPressBackend { if (!empty($children)) { foreach ($children as $child) { - $result[] = new ComicPressBackendAttachment($child); + if (get_post_meta($child->ID, 'comicpress_management', true)) { + $result[] = new ComicPressBackendAttachment($child); + } } } } diff --git a/test/ComicPressAdminTest.php b/test/ComicPressAdminTest.php index d3945a5..8e359e4 100644 --- a/test/ComicPressAdminTest.php +++ b/test/ComicPressAdminTest.php @@ -88,11 +88,11 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { 'post_meta' => array(), ), array( - 'comic_image_type' => "test" + 'comicpress_management' => "yes" ), array( 'post_meta' => array( - 'comic_image_type' => "test" + 'comicpress_management' => true ), ), ), @@ -119,12 +119,15 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase { ), array( 'post_parent' => "2", - 'auto_attach' => 1 + 'comicpress_management' => "yes" ), array( 'post' => array( - 'post_parent' => 2 + 'post_parent' => 2, ), + 'post_meta' => array( + 'comicpress_management' => true + ) ), ) ); diff --git a/test/backends/ComicPressBackendAttachmentTest.php b/test/backends/ComicPressBackendAttachmentTest.php index e1e0cd5..9147e8a 100644 --- a/test/backends/ComicPressBackendAttachmentTest.php +++ b/test/backends/ComicPressBackendAttachmentTest.php @@ -11,21 +11,27 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase { function providerTestGenerateFromPost() { return array( - array(array(), false), - array(array((object)array('ID' => 1)), array('attachment-1')) + array(array(), array(), false), + array(array((object)array('ID' => 1)), array(), array()) ); } /** * @dataProvider providerTestGenerateFromPost */ - function testGenerateFromPost($get_children_response, $expected_ids) { + function testGenerateFromPost($get_children_response, $post_meta, $expected_ids) { _set_get_children(array( 'post_parent' => 1, 'post_type' => 'attachment', 'post_mime_type' => 'image' ), $get_children_response); + foreach ($post_meta as $id => $meta) { + foreach ($meta as $field => $value) { + update_post_meta($id, $field, $value); + } + } + $results = ComicPressBackendAttachment::generate_from_post((object)array('ID' => 1)); if ($expected_ids === false) { $this->assertTrue(empty($results));