This commit is contained in:
John Bintz 2009-12-14 21:19:21 -05:00
parent b6f7d96019
commit 0edca9e64a
2 changed files with 52 additions and 3 deletions

View File

@ -86,4 +86,32 @@ class ArchiveDropdownWidgetTest extends PHPUnit_Framework_TestCase {
$w->build_comic_archive_dropdown();
}
function providerTestUpdate() {
$w = new ArchiveDropdownWidget();
$valid_mode = array_shift(array_keys($w->modes));
return array(
array(array(), array()),
array(
array('title' => '<b>test</b>'),
array('title' => 'test'),
),
array(
array('mode' => 'bad'),
array()
),
array(
array('mode' => $valid_mode),
array('mode' => $valid_mode)
)
);
}
/**
* @dataProvider providerTestUpdate
*/
function testUpdate($input, $expected_output) {
$this->assertEquals($expected_output, $this->w->update($input, array()));
}
}

View File

@ -40,9 +40,16 @@ function comicpress_archive_dropdown_comics() {
}
class ArchiveDropdownWidget extends WP_Widget {
var $modes;
function ArchiveDropdownWidget() {
$widget_ops = array('classname' => 'ArchiveDropdownWidget', 'description' => __('Display a dropdown list of your archives, styled.','comicpress') );
$this->WP_Widget('archive_dropdown', __('ComicPress Archive Dropdown','comicpress'), $widget_ops);
$this->modes = array(
'monthly_archive' => __('Monthly archive', 'comicpress'),
'comic_archive' => __('Comic archive', 'comicpress')
);
}
function _verify_nonce() { return __comicpress_verify_nonce(); }
@ -136,9 +143,23 @@ class ArchiveDropdownWidget extends WP_Widget {
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['showcomicposts'] = $new_instance['showcomicposts'];
$instance = array();
foreach (array('title', 'mode') as $field) {
if (isset($new_instance[$field])) {
switch ($field) {
case 'mode':
if (isset($this->modes[$new_instance[$field]])) {
$instance[$field] = $new_instance[$field];
}
break;
default:
$instance[$field] = strip_tags($new_instance[$field]);
break;
}
}
}
return $instance;
}