code coverage

This commit is contained in:
John Bintz 2009-12-01 07:20:33 -05:00
parent 1bb7edfd04
commit 4590eed89a
2 changed files with 28 additions and 1 deletions

View File

@ -33,4 +33,26 @@ class BuyThisPrintWidgetTest extends PHPUnit_Framework_TestCase {
function testUpdate($input, $expected_output) { function testUpdate($input, $expected_output) {
$this->assertEquals($expected_output, $this->w->update($input)); $this->assertEquals($expected_output, $this->w->update($input));
} }
function testBuyThisPrintStructure() {
global $post, $buy_print_url;
$buy_print_url = 'buy print url';
$post = (object)array('ID' => 10);
$result = $this->w->buy_print_structure();
$this->assertTag(array(
'tag' => 'form',
'attributes' => array('action' => $buy_print_url)
), $result);
$this->assertTag(array(
'tag' => 'input',
'attributes' => array(
'name' => 'comic',
'value' => 10
)
), $result);
}
} }

View File

@ -15,9 +15,11 @@ class BuyThisPrintWidget extends WP_Widget {
$this->WP_Widget('comicpress_buyprint', __('Buy This Print','comicpress'), $widget_ops); $this->WP_Widget('comicpress_buyprint', __('Buy This Print','comicpress'), $widget_ops);
} }
// @codeCoverageIgnoreStart
function init() { function init() {
add_filter('comicpress_buy_print_structure', array(&$this, 'buy_print_structure')); add_filter('comicpress_buy_print_structure', array(&$this, 'buy_print_structure'));
} }
// @codeCoverageIgnoreEnd
function widget($args, $instance) { function widget($args, $instance) {
extract($args, EXTR_SKIP); extract($args, EXTR_SKIP);
@ -34,12 +36,15 @@ class BuyThisPrintWidget extends WP_Widget {
} }
function buy_print_structure($content = '') { function buy_print_structure($content = '') {
global $buy_print_url; ?> global $buy_print_url;
ob_start();
?>
<div class="buythis"><form method="post" action="<?php echo $buy_print_url; ?>"> <div class="buythis"><form method="post" action="<?php echo $buy_print_url; ?>">
<input type="hidden" name="comic" value="<?php echo get_the_ID(); ?>" /> <input type="hidden" name="comic" value="<?php echo get_the_ID(); ?>" />
<button class="buythisbutton" type="submit" value="submit" name="submit"></button></form></div> <button class="buythisbutton" type="submit" value="submit" name="submit"></button></form></div>
<div class="clear"></div> <div class="clear"></div>
<?php <?php
return ob_get_clean();
} }
function update($new_instance, $old_instance = array()) { function update($new_instance, $old_instance = array()) {