comic archive dropdown
This commit is contained in:
parent
690aa46ba1
commit
b6f7d96019
|
@ -58,4 +58,32 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertTrue(empty($html));
|
$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();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -20,15 +20,6 @@ function comicpress_archive_dropdown_storyline() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function comicpress_archive_dropdown() { ?>
|
|
||||||
<div class="archive-dropdown-wrap">
|
|
||||||
<select name="archive-dropdown" class="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
|
|
||||||
<option value=""><?php echo attribute_escape(__('Archives...','comicpress')); ?></option>
|
|
||||||
<?php ; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<?php }
|
|
||||||
|
|
||||||
function comicpress_archive_dropdown_comics() {
|
function comicpress_archive_dropdown_comics() {
|
||||||
global $post, $wp_query;
|
global $post, $wp_query;
|
||||||
$temp_post = $post;
|
$temp_post = $post;
|
||||||
|
@ -109,12 +100,25 @@ class ArchiveDropdownWidget extends WP_Widget {
|
||||||
|
|
||||||
function _new_comicpressstoryline() { return new ComicPressStoryline(); }
|
function _new_comicpressstoryline() { return new ComicPressStoryline(); }
|
||||||
function _new_comicpressdbinterface() { return new ComicPressDBInterface(); }
|
function _new_comicpressdbinterface() { return new ComicPressDBInterface(); }
|
||||||
|
function _new_wp_query() { return new WP_Query(); }
|
||||||
|
|
||||||
function build_comic_archive_dropdown() {
|
function build_comic_archive_dropdown() {
|
||||||
$storyline = $this->_new_comicpressstoryline();
|
$storyline = $this->_new_comicpressstoryline();
|
||||||
$storyline->read_from_options();
|
$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) {
|
function widget($args, $instance) {
|
||||||
|
|
Loading…
Reference in New Issue