get attachments with chhildren
This commit is contained in:
parent
cf6f867a86
commit
7224faead7
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue