From b6f7d9601953caa0538d115df460826d8f3a00c1 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 10 Dec 2009 23:24:45 -0500 Subject: [PATCH] comic archive dropdown --- test/widgets/ArchiveDropdownWidgetTest.php | 28 ++++++++++++++++++++++ widgets/ArchiveDropdownWidget.inc | 22 ++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/test/widgets/ArchiveDropdownWidgetTest.php b/test/widgets/ArchiveDropdownWidgetTest.php index 2eb1eaa..d9c554f 100644 --- a/test/widgets/ArchiveDropdownWidgetTest.php +++ b/test/widgets/ArchiveDropdownWidgetTest.php @@ -58,4 +58,32 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase { $this->assertTrue(empty($html)); } + + function testBuildComicArchiveDropdown() { + $w = $this->getMock('ArchiveDropdownWidget', array('_new_comicpressstoryline', '_new_wp_query', 'build_dropdown')); + + $storyline = $this->getMock('ComicPressStoryline', array('read_from_options', 'build_from_restrictions')); + $storyline->expects($this->once())->method('read_from_options'); + $storyline->expects($this->once())->method('build_from_restrictions')->will($this->returnValue(array(1,2,3))); + + $w->expects($this->once())->method('_new_comicpressstoryline')->will($this->returnValue($storyline)); + + $query = $this->getMock('WP_Query', array('query', 'has_posts', 'next_post')); + $query->expects($this->once())->method('query')->with(array( + 'showposts' => -1, + 'category__in' => array(1,2,3) + )); + + wp_insert_post((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title')); + + $query->expects($this->at(1))->method('has_posts')->will($this->returnValue(true)); + $query->expects($this->at(2))->method('next_post')->will($this->returnValue((object)array('ID' => 1, 'guid' => 'guid', 'post_title' => 'title'))); + $query->expects($this->at(3))->method('has_posts')->will($this->returnValue(false)); + + $w->expects($this->once())->method('_new_wp_query')->will($this->returnValue($query)); + + $w->expects($this->once())->method('build_dropdown')->with(array('guid' => 'title')); + + $w->build_comic_archive_dropdown(); + } } \ No newline at end of file diff --git a/widgets/ArchiveDropdownWidget.inc b/widgets/ArchiveDropdownWidget.inc index dff7cd9..55bb6ae 100644 --- a/widgets/ArchiveDropdownWidget.inc +++ b/widgets/ArchiveDropdownWidget.inc @@ -20,15 +20,6 @@ function comicpress_archive_dropdown_storyline() { } */ -function comicpress_archive_dropdown() { ?> -
- -
-_new_comicpressstoryline(); $storyline->read_from_options(); + $query = $this->_new_wp_query(); + $query->query(array( + 'showposts' => -1, + 'category__in' => $storyline->build_from_restrictions() + )); + $results = array(); + while($query->has_posts()) { + $post = $query->next_post(); + $results[get_permalink($post)] = get_the_title($post); + } + + return $this->build_dropdown($results); } function widget($args, $instance) {