diff --git a/test/widgets/CalendarWidgetTest.php b/test/widgets/CalendarWidgetTest.php new file mode 100644 index 0000000..2b87867 --- /dev/null +++ b/test/widgets/CalendarWidgetTest.php @@ -0,0 +1,51 @@ +w = new CalendarWidget('id', 'name', array()); + } + + function providerTestUpdate() { + return array( + array( + array(), array() + ), + array( + array('test' => 'test'), array() + ), + array( + array('thumbnail' => 'title'), array('thumbnail' => 'title') + ), + array( + array('thumbnail' => "title"), array('thumbnail' => 'title') + ), + array( + array( + 'thumbnail' => "test", + 'small' => "test", + 'medium' => "test", + 'large' => "test", + 'link' => "test", + ), array( + 'thumbnail' => "test", + 'small' => "test", + 'medium' => "test", + 'large' => "test", + 'link' => "test", + ) + ), + ); + } + + /** + * @dataProvider providerTestUpdate + */ + function testUpdate($input, $expected_output) { + $this->assertEquals($expected_output, $this->w->update($input)); + } +} diff --git a/widgets/CalendarWidget.inc b/widgets/CalendarWidget.inc new file mode 100644 index 0000000..cbc2f41 --- /dev/null +++ b/widgets/CalendarWidget.inc @@ -0,0 +1,102 @@ + 'CalendarWidget', 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') ); + $this->WP_Widget('comicpress_calendar', __('ComicPress Calendar','comicpress'), $widget_ops); + } + + function widget($args, $instance) { + global $post; + extract($args, EXTR_SKIP); + + echo $before_widget; + + if (!empty($instance)) { extract($instance); } ?> +
+
+
+ +
+ + + + + + +
+ + +
+
+
+ '', 'small' => '', 'medium' => '', 'large' => '', 'link' => '') ); + + $thumbnail = strip_tags($instance['thumbnail']); + $small = strip_tags($instance['small']); + $medium = strip_tags($instance['medium']); + $large = strip_tags($instance['large']); + $link = $instance['link']; + + foreach (array( + 'thumbnail' => __('Thumbnail URL (178px by 130px):','comicpress'), + 'link' => array('label' => __('Add link on thumbnails:','comicpress'), 'after' => '
'), + 'small' => __('Wallpaper URL (Small):','comicpress'), + 'medium' => __('Wallpaper URL (Medium):','comicpress'), + 'large' => __('Wallpaper URL (Large):','comicpress'), + ) as $field => $label) { + unset($after); + if (is_array($label)) { extract($label); } + ?>

+ +

-
-
-
- -
- - - - - - -
- - -
-
-
- 'widget_comicpress_calendar', 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') ); - $this->WP_Widget('comicpress_calendar', __('Comicpress Calendar','comicpress'), $widget_ops); - } - - function widget($args, $instance) { - global $post; - extract($args, EXTR_SKIP); - - echo $before_widget; - comicpress_calendar($instance); - echo $after_widget; - } - - function update($new_instance, $old_instance) { - $instance = $old_instance; - $instance['thumbnail'] = strip_tags($new_instance['thumbnail']); - $instance['small'] = strip_tags($new_instance['small']); - $instance['medium'] = strip_tags($new_instance['medium']); - $instance['large'] = strip_tags($new_instance['large']); - $instance['link'] = $new_instance['link']; - return $instance; - } - - function form($instance) { - $instance = wp_parse_args( (array) $instance, array( 'thumbnail' => '', 'small' => '', 'medium' => '', 'large' => '', 'link' => '') ); - $thumbnail = strip_tags($instance['thumbnail']); - $small = strip_tags($instance['small']); - $medium = strip_tags($instance['medium']); - $large = strip_tags($instance['large']); - $link = $instance['link']; - ?> -

-

-
-

-

-

-

- \ No newline at end of file