Merge branch 'widgets' of git@github.com:johnbintz/comicpress-2.8 into widgets

This commit is contained in:
John Bintz 2009-12-15 06:43:48 -05:00
commit d87b36594b
2 changed files with 65 additions and 2 deletions

View File

@ -57,4 +57,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);
}
}

View File

@ -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' ) {
@ -60,7 +62,7 @@ class BuyThisPrintWidget extends WP_Widget {
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
$title = strip_tags($instance['title']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','comicpress'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','comicpress'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
<?php
}
}