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));