add update test

This commit is contained in:
John Bintz 2009-06-26 06:57:15 -04:00
parent 4a0719c954
commit 772016ca85
2 changed files with 13 additions and 3 deletions

View File

@ -63,6 +63,12 @@ class PluginWonderfulWidget extends WP_Widget {
echo '</p>'; echo '</p>';
} }
} }
function update($new_instance, $old_instance) {
$instance = $new_instance;
if (!isset($instance['center'])) { $instance['center'] = 0; }
return $instance;
}
} }
?> ?>

View File

@ -69,7 +69,7 @@ class PluginWonderfulWidgetTest extends PHPUnit_Framework_TestCase {
); );
ob_start(); ob_start();
$this->w->form(array('adboxid' => '123', 'center' => 0)); $this->w->form(array('adboxid' => '123', 'center' => 1));
$source = ob_get_clean(); $source = ob_get_clean();
$this->assertTrue(($xml = _to_xml($source)) !== false); $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="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="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="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) { ) as $xpath => $value) {
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath); $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)));
}
} }
?> ?>