form($instance);
$outbound = ob_get_contents();
ob_end_clean();
$this->assertContains('adplugg-widget-fieldset', $outbound);
}
/**
* Test the update function.
*/
public function test_update() {
$old_title = 'old_title';
$new_title = 'new_title';
$old_zone = 'old_zone';
$new_zone = 'new_zone';
$adplugg_widget = new AdPlugg_Widget();
$old_instance = array();
$old_instance['title'] = $old_title;
$old_instance['zone'] = $old_zone;
$new_instance = array();
$new_instance['title'] = $new_title;
$new_instance['zone'] = $new_zone;
//Run the function.
$ret_instance = $adplugg_widget->update($new_instance, $old_instance);
//Assert that the ret_instance title is the new title
$this->assertEquals($ret_instance['title'], $new_title);
//Assert that the ret_instance zone is the new zone
$this->assertEquals($ret_instance['zone'], $new_zone);
}
/**
* Test the update function's validation strips illegal and malicious data.
*/
public function test_update_validation_passes_when_valid() {
$old_title = 'old_title';
$new_title = 'Our Sponsors';
$old_zone = 'old_zone';
$new_zone = 'new_zone';
$adplugg_widget = new AdPlugg_Widget();
$old_instance = array();
$old_instance['title'] = $old_title;
$old_instance['zone'] = $old_zone;
$new_instance = array();
$new_instance['title'] = $new_title;
$new_instance['zone'] = $new_zone;
//Run the function.
$ret_instance = $adplugg_widget->update($new_instance, $old_instance);
//Assert that the validation passed and the title was set as expected
$this->assertEquals($new_title, $ret_instance['title']);
//Assert that the validation passed and the zone was set as expected
$this->assertEquals($new_zone, $ret_instance['zone']);
}
/**
* Test the update function's validation strips illegal and malicious data.
*/
public function test_update_validation_strips_illegals() {
$old_title = 'old_title';
$new_title = '">';
$old_zone = 'old_zone';
$new_zone = '">';
$adplugg_widget = new AdPlugg_Widget();
$old_instance = array();
$old_instance['title'] = $old_title;
$old_instance['zone'] = $old_zone;
$new_instance = array();
$new_instance['title'] = $new_title;
$new_instance['zone'] = $new_zone;
//Run the function.
$ret_instance = $adplugg_widget->update($new_instance, $old_instance);
//Assert that the malicious code was removed
$illegal_regex = "/\