Merge branch 'widgets' of git@github.com:johnbintz/comicpress-2.8 into widgets
This commit is contained in:
commit
d87b36594b
|
@ -57,4 +57,65 @@ class BuyThisPrintWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
)
|
)
|
||||||
), $result);
|
), $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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ class BuyThisPrintWidget extends WP_Widget {
|
||||||
extract($args, EXTR_SKIP);
|
extract($args, EXTR_SKIP);
|
||||||
|
|
||||||
echo $before_widget;
|
echo $before_widget;
|
||||||
|
if (isset($instance['title'])) {
|
||||||
$title = apply_filters('widget_title', $instance['title']);
|
$title = apply_filters('widget_title', $instance['title']);
|
||||||
|
}
|
||||||
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
|
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
|
||||||
|
|
||||||
if ( get_post_meta( get_the_ID(), "buythiscomic", true ) !== 'sold' ) {
|
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' => '' ) );
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
|
||||||
$title = strip_tags($instance['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
|
<?php
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue