diff --git a/classes/BookmarkWidget.inc b/classes/BookmarkWidget.inc index ccb2911..78da664 100644 --- a/classes/BookmarkWidget.inc +++ b/classes/BookmarkWidget.inc @@ -1,7 +1,7 @@ default_instance, $instance); + echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); if (!empty($title)) { echo $before_title . $title . $after_title; }; - $mode = !isset($this->text_fields[$instance['mode']]) ? array_shift(array_keys($this->text_fields)) : $instance['mode']; + $mode = $instance['mode']; $link = is_home() ? get_bloginfo('url') : get_permalink($post); diff --git a/test/BookmarkWidgetTest.php b/test/BookmarkWidgetTest.php index 649c42c..f823796 100644 --- a/test/BookmarkWidgetTest.php +++ b/test/BookmarkWidgetTest.php @@ -79,4 +79,74 @@ class BookmarkWidgetTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array_merge($w->default_instance, $expected_instance_merge), $w->update($update_array, array())); } + + function providerTestWidget() { + return array( + array( + array( + 'title' => 'Title', + 'mode' => 'one-button', + 'tag-page' => 'Tag page', + 'bookmark-clicker-off' => 'Clicker off' + ), + array( + '//p[text()="Title"]' => true, + '//div[@class="bookmark-widget"]/a[@class="bookmark-clicker"]' => true, + '//script[contains(text(), "tag-page")]' => false, + '//script[contains(text(), "bookmark-clicker-off")]' => true, + '//script[contains(text(), "Post url")]' => true, + ) + ), + array( + array( + 'title' => 'Other Title', + 'mode' => 'three-button', + 'tag-page' => 'Tag page', + 'bookmark-clicker-off' => 'Clicker off' + ), + array( + '//p[text()="Other Title"]' => true, + '//div[@class="bookmark-widget"]/a[@class="tag-page"]' => true, + '//script[contains(text(), "tag-page")]' => true, + '//script[contains(text(), "bookmark-clicker-off")]' => false, + '//script[contains(text(), "Blog url")]' => true, + ), + true + ), + ); + } + + /** + * @dataProvider providerTestWidget + */ + function testWidget($instance, $expected_xpath, $is_home = false) { + global $post; + + $post = (object)array( + 'ID' => 1, + 'guid' => 'Post url' + ); + + wp_insert_post($post); + + $w = new ComicPressBookmarkWidget(); + + _set_bloginfo('url', 'Blog url'); + _set_current_option('is_home', $is_home); + + ob_start(); + $w->widget(array( + 'before_widget' => '', + 'after_widget' => '', + 'before_title' => '
', + 'after_title' => '
' + ), $instance); + $content = ob_get_clean(); + + $this->assertTrue(($xml = _to_xml($content, true)) !== false); + + foreach ($expected_xpath as $xpath => $value) { + $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); + } + } }