diff --git a/test/widgets/BuyThisPrintWidgetTest.php b/test/widgets/BuyThisPrintWidgetTest.php index 7eb99f1..38c608e 100644 --- a/test/widgets/BuyThisPrintWidgetTest.php +++ b/test/widgets/BuyThisPrintWidgetTest.php @@ -55,4 +55,65 @@ class BuyThisPrintWidgetTest extends PHPUnit_Framework_TestCase { ) ), $result); } + + function providerTestWidget() { + return array( + array( + array(), array(), array(), array('beforeafter'), + ), + array( + array('title' => 'title'), array(), array(), array('before:bt:title:at:after'), + ), + array( + array('title' => 'title'), array(), array('widget_title' => 'newtitle'), array('before:bt:newtitle:at:after'), + ), + array( + array(), array(), array('comicpress_buy_print_structure' => 'buy'), array('beforebuyafter'), + ), + array( + array(), array('buythiscomic' => 'yes'), array('comicpress_buy_print_structure' => 'buy'), array('beforebuyafter'), + ), + array( + array(), array('buythiscomic' => 'sold'), array('comicpress_buy_print_structure' => 'buy'), array('beforeafter'), + ), + ); + } + + /** + * @dataProvider providerTestWidget + */ + function testWidget($instance, $post_meta, $filter_expectations, $expected_matches) { + global $post; + + $post = (object)array('ID' => 1); + foreach ($post_meta as $meta => $value) { + update_post_meta(1, $meta, $value); + } + + foreach ($filter_expectations as $name => $result) { + _set_filter_expectation($name, $result); + } + + ob_start(); + $this->w->widget(array('before_widget' => 'before', 'after_widget' => 'after', 'before_title' => ':bt:', 'after_title' => ':at:'), $instance); + $content = ob_get_clean(); + + foreach ($expected_matches as $match) { + $this->assertTrue(preg_match("#${match}#mis", $content) > 0); + } + } + + function testForm() { + ob_start(); + $this->w->form(array('title' => 'title')); + $content = ob_get_clean(); + + $this->assertTag(array( + 'tag' => 'input', + 'attributes' => array( + 'type' => 'text', + 'value' => 'title' + ) + ), $content); + } } diff --git a/widgets/BuyThisPrintWidget.inc b/widgets/BuyThisPrintWidget.inc index c8b91d5..8bcd1ba 100644 --- a/widgets/BuyThisPrintWidget.inc +++ b/widgets/BuyThisPrintWidget.inc @@ -25,7 +25,9 @@ class BuyThisPrintWidget extends WP_Widget { extract($args, EXTR_SKIP); echo $before_widget; - $title = apply_filters('widget_title', $instance['title']); + if (isset($instance['title'])) { + $title = apply_filters('widget_title', $instance['title']); + } if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; if ( get_post_meta( get_the_ID(), "buythiscomic", true ) !== 'sold' ) { @@ -59,7 +61,7 @@ class BuyThisPrintWidget extends WP_Widget { $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); $title = strip_tags($instance['title']); ?> -

+