From 772016ca8584d46e6b69de2691d414fd5b93a2f5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 26 Jun 2009 06:57:15 -0400 Subject: [PATCH] add update test --- classes/PluginWonderfulWidget.php | 6 ++++++ test/PluginWonderfulWidgetTest.php | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/PluginWonderfulWidget.php b/classes/PluginWonderfulWidget.php index 59f159c..f5631ff 100644 --- a/classes/PluginWonderfulWidget.php +++ b/classes/PluginWonderfulWidget.php @@ -63,6 +63,12 @@ class PluginWonderfulWidget extends WP_Widget { echo '

'; } } + + function update($new_instance, $old_instance) { + $instance = $new_instance; + if (!isset($instance['center'])) { $instance['center'] = 0; } + return $instance; + } } ?> \ No newline at end of file diff --git a/test/PluginWonderfulWidgetTest.php b/test/PluginWonderfulWidgetTest.php index 8b24ef1..220db9d 100644 --- a/test/PluginWonderfulWidgetTest.php +++ b/test/PluginWonderfulWidgetTest.php @@ -69,7 +69,7 @@ class PluginWonderfulWidgetTest extends PHPUnit_Framework_TestCase { ); ob_start(); - $this->w->form(array('adboxid' => '123', 'center' => 0)); + $this->w->form(array('adboxid' => '123', 'center' => 1)); $source = ob_get_clean(); $this->assertTrue(($xml = _to_xml($source)) !== false); @@ -78,11 +78,15 @@ class PluginWonderfulWidgetTest extends PHPUnit_Framework_TestCase { '//input[@type="radio" and @name="' . $this->w->get_field_name('adboxid') . '" and @value="123" and @checked="checked"]' => true, '//input[@type="radio" and @name="' . $this->w->get_field_name('adboxid') . '" and @value="234" and not(@checked="checked")]' => true, '//input[@type="radio" and @name="' . $this->w->get_field_name('adboxid') . '" and @value="345" and not(@checked="checked")]' => true, - '//input[@type="checkbox" and @name="' . $this->w->get_field_name('center') . '" and @value="1" and not(@checked="checked")]' => true + '//input[@type="checkbox" and @name="' . $this->w->get_field_name('center') . '" and @value="1" and @checked="checked"]' => true ) as $xpath => $value) { $this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); } - } + } + + function testUpdateWidget() { + $this->assertEquals(array('adboxid' => 5, 'center' => 0), $this->w->update(array('adboxid' => 5), array('adboxid' => 4, 'center' => 1))); + } } ?> \ No newline at end of file