From 7224faead7aa3d1fa59725494ac91cde9472d900 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 14 Nov 2009 11:46:20 -0500 Subject: [PATCH] get attachments with chhildren --- classes/ComicPressComicPost.inc | 15 +++++++++++- test/ComicPressComicPostTest.php | 42 +++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/classes/ComicPressComicPost.inc b/classes/ComicPressComicPost.inc index 96735d7..2ad6eef 100644 --- a/classes/ComicPressComicPost.inc +++ b/classes/ComicPressComicPost.inc @@ -143,6 +143,19 @@ class ComicPressComicPost { update_post_meta($this->post->ID, 'image-ordering', $ordering); return $ordering; } + + function get_attachments_with_children() { + $attachments_with_children = array(); + foreach ($this->normalize_ordering() as $id => $info) { + if ($info['enabled']) { + $attachments_with_children[$id] = array(); + if (isset($info['children'])) { + $attachments_with_children[$id] = $info['children']; + } + } + } + return $attachments_with_children; + } } -?> \ No newline at end of file +?> diff --git a/test/ComicPressComicPostTest.php b/test/ComicPressComicPostTest.php index 7caf3ff..85905ec 100644 --- a/test/ComicPressComicPostTest.php +++ b/test/ComicPressComicPostTest.php @@ -172,6 +172,46 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array('test'), $this->p->get_attachments()); } + + function providerTestGetAttachmentsWithChildren() { + return array( + array( + array( + 'test-1' => array('enabled' => true), + 'test-2' => array('enabled' => true), + 'test-3' => array('enabled' => false), + 'test-4' => array('enabled' => false), + ), + array( + 'test-1' => array(), + 'test-2' => array() + ) + ), + array( + array( + 'test-1' => array('enabled' => true, 'children' => array('rss' => 'test-3')), + 'test-2' => array('enabled' => false, 'children' => array('rss' => 'test-4')), + ), + array( + 'test-1' => array('rss' => 'test-3'), + ) + ), + + ); + } + + /** + * @dataProvider providerTestGetAttachmentsWithChildren + */ + function testGetAttachmentsWithChildren($normalized_ordering, $expected_result) { + $p = $this->getMock('ComicPressComicPost', array('normalize_ordering')); + + $p->post = (object)array('ID' => 1); + + $p->expects($this->once())->method('normalize_ordering')->will($this->returnValue($normalized_ordering)); + + $this->assertEquals($expected_result, $p->get_attachments_with_children()); + } } -?> \ No newline at end of file +?>