finish widget form
This commit is contained in:
parent
0c8c8a1722
commit
4a0719c954
@ -18,8 +18,6 @@ class PluginWonderful {
|
||||
$this->_get_publisher_info();
|
||||
$this->_update_database_version();
|
||||
|
||||
$this->set_up_widgets();
|
||||
|
||||
if (!empty($_POST)) { $this->handle_action(); }
|
||||
}
|
||||
}
|
||||
@ -93,25 +91,6 @@ class PluginWonderful {
|
||||
if (!empty($result)) { echo $result; }
|
||||
}
|
||||
|
||||
function render_widget($adboxid) {
|
||||
if ($this->publisher_info !== false) {
|
||||
foreach ($this->publisher_info->adboxes as $adbox) {
|
||||
if (($adbox->adboxid == $adboxid) || ($adbox->template_tag_id == $adboxid)) {
|
||||
if (get_option("plugin-wonderful-use-standardcode") == 1) {
|
||||
$output = $adbox->standardcode;
|
||||
} else {
|
||||
$output = $adbox->advancedcode;
|
||||
}
|
||||
if ($adbox->center_widget == 1) {
|
||||
$output = "<center>{$output}</center>";
|
||||
}
|
||||
echo $output;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function inject_ads_into_body_copy($body) {
|
||||
if ($this->publisher_info !== false) {
|
||||
if (get_option("plugin-wonderful-enable-body-copy-embedding") == 1) {
|
||||
@ -125,21 +104,6 @@ class PluginWonderful {
|
||||
add_options_page('Plugin Wonderful', __("Plugin Wonderful", 'plugin-wonderful'), 5, __FILE__, array($this, "plugin_wonderful_main"));
|
||||
}
|
||||
|
||||
function render_widget_control($adboxid) {
|
||||
if ($this->publisher_info !== false) {
|
||||
foreach ($this->publisher_info->adboxes as $box) {
|
||||
if ($box->adboxid == $adboxid) {
|
||||
echo '<input type="hidden" name="pw[_nonce]" value="' . wp_create_nonce("plugin-wonderful") . '" />';
|
||||
echo '<label>';
|
||||
echo '<input type="checkbox" name="pw[center][' . $adboxid . ']" ' . (($box->center_widget == 1) ? "checked" : "") . ' /> ';
|
||||
echo 'Wrap ad in <center> tags';
|
||||
echo '</label>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handle_activation() {
|
||||
$this->init();
|
||||
$this->adboxes_client->initialize();
|
||||
|
@ -17,7 +17,51 @@ class PluginWonderfulWidget extends WP_Widget {
|
||||
function widget($args, $instance) {
|
||||
global $plugin_wonderful;
|
||||
|
||||
$plugin_wonderful->render_widget($instance['adboxid']);
|
||||
if ($plugin_wonderful->publisher_info !== false) {
|
||||
foreach ($plugin_wonderful->publisher_info->adboxes as $adbox) {
|
||||
if (($adbox->adboxid == $instance['adboxid']) || ($adbox->template_tag_id == $instance['adboxid'])) {
|
||||
if (get_option("plugin-wonderful-use-standardcode") == 1) {
|
||||
$output = $adbox->standardcode;
|
||||
} else {
|
||||
$output = $adbox->advancedcode;
|
||||
}
|
||||
if ($instance['center'] == 1) {
|
||||
$output = "<center>{$output}</center>";
|
||||
}
|
||||
echo $output;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function form($instance) {
|
||||
global $plugin_wonderful;
|
||||
|
||||
if ($plugin_wonderful->publisher_info !== false) {
|
||||
echo '<p>';
|
||||
echo 'Select an adbox:';
|
||||
foreach ($plugin_wonderful->publisher_info->adboxes as $box) {
|
||||
echo '<label>';
|
||||
echo '<input type="radio" name="'
|
||||
. $this->get_field_name('adboxid')
|
||||
. '" value="'
|
||||
. $box->adboxid
|
||||
. '" '
|
||||
. (($instance['adboxid'] == $box->adboxid) ? 'checked="checked"' : "")
|
||||
. ' />';
|
||||
echo $box->adtype . " " . $box->dimensions . " (" . $box->adboxid . ")";
|
||||
echo "</label>";
|
||||
}
|
||||
echo '</p>';
|
||||
|
||||
echo '<p>';
|
||||
echo '<label>';
|
||||
echo '<input type="checkbox" value="1" name="' . $this->get_field_name('center') . '" ' . (($instance['center'] == 1) ? 'checked="checked"' : "") . ' /> ';
|
||||
echo 'Wrap ad in <center> tags';
|
||||
echo '</label>';
|
||||
echo '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,27 +24,6 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
$pw->handle_action();
|
||||
}
|
||||
|
||||
function testRenderWidgetControl() {
|
||||
_set_valid_nonce("plugin-wonderful", "12345");
|
||||
|
||||
$this->pw->publisher_info->adboxes = array(
|
||||
(object)array('adboxid' => '123',
|
||||
'center_widget' => 0)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->pw->render_widget_control('123');
|
||||
$source = ob_get_clean();
|
||||
|
||||
$this->assertTrue(($xml = _to_xml($source)) !== false);
|
||||
|
||||
foreach (array(
|
||||
'//input[@name="pw[_nonce]" and @value="12345"]' => true
|
||||
) as $xpath => $value) {
|
||||
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
|
||||
}
|
||||
}
|
||||
|
||||
function testHandleActivation() {
|
||||
$pw = $this->getMock('PluginWonderful', array('init'));
|
||||
$pw->adboxes_client = $this->getMock('PWAdboxesClient', array('initialize'));
|
||||
@ -179,44 +158,6 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function providerTestRenderWidget() {
|
||||
return array(
|
||||
array(false, null, null, null, ""),
|
||||
array(true, null, null, null, ""),
|
||||
array(true, "123", 0, null, "advanced"),
|
||||
array(true, "123", 1, null, "standard"),
|
||||
array(true, "abc", 1, null, "standard"),
|
||||
array(true, "abc", 1, 1, "<center>standard</center>")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestRenderWidget
|
||||
*/
|
||||
function testRenderWidget($has_publisher_info, $requested_adboxid, $use_standardcode, $center_widget, $expected_result) {
|
||||
$test_ad = (object)array(
|
||||
'adboxid' => '123',
|
||||
'template_tag_id' => 'abc',
|
||||
'standardcode' => 'standard',
|
||||
'advancedcode' => 'advanced',
|
||||
'center_widget' => $center_widget
|
||||
);
|
||||
|
||||
if ($has_publisher_info) {
|
||||
$this->pw->publisher_info = (object)array(
|
||||
'adboxes' => array($test_ad)
|
||||
);
|
||||
|
||||
update_option("plugin-wonderful-use-standardcode", $use_standardcode);
|
||||
} else {
|
||||
$this->pw->publisher_info = false;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->pw->render_widget($requested_adboxid);
|
||||
$this->assertEquals($expected_result, ob_get_clean());
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -17,8 +17,71 @@ class PluginWonderfulWidgetTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals("Plugin Wonderful", $wp_test_expectations['wp_widgets']['plugin-wonderful']['name']);
|
||||
}
|
||||
|
||||
function testWidget() {
|
||||
function providerTestRenderWidget() {
|
||||
return array(
|
||||
array(false, null, null, null, ""),
|
||||
array(true, null, null, null, ""),
|
||||
array(true, "123", 0, null, "advanced"),
|
||||
array(true, "123", 1, null, "standard"),
|
||||
array(true, "abc", 1, null, "standard"),
|
||||
array(true, "abc", 1, 1, "<center>standard</center>")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestRenderWidget
|
||||
*/
|
||||
function testRenderWidget($has_publisher_info, $requested_adboxid, $use_standardcode, $center_widget, $expected_result) {
|
||||
global $plugin_wonderful;
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful');
|
||||
|
||||
$test_ad = (object)array(
|
||||
'adboxid' => '123',
|
||||
'template_tag_id' => 'abc',
|
||||
'standardcode' => 'standard',
|
||||
'advancedcode' => 'advanced'
|
||||
);
|
||||
|
||||
if ($has_publisher_info) {
|
||||
$plugin_wonderful->publisher_info = (object)array(
|
||||
'adboxes' => array($test_ad)
|
||||
);
|
||||
|
||||
update_option("plugin-wonderful-use-standardcode", $use_standardcode);
|
||||
} else {
|
||||
$plugin_wonderful->publisher_info = false;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$this->w->widget(array(), array('adboxid' => $requested_adboxid, 'center' => $center_widget));
|
||||
$this->assertEquals($expected_result, ob_get_clean());
|
||||
}
|
||||
|
||||
|
||||
function testRenderWidgetControl() {
|
||||
global $plugin_wonderful;
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful');
|
||||
|
||||
$plugin_wonderful->publisher_info->adboxes = array(
|
||||
(object)array('adboxid' => '123'),
|
||||
(object)array('adboxid' => '234'),
|
||||
(object)array('adboxid' => '345'),
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$this->w->form(array('adboxid' => '123', 'center' => 0));
|
||||
$source = ob_get_clean();
|
||||
|
||||
$this->assertTrue(($xml = _to_xml($source)) !== false);
|
||||
|
||||
foreach (array(
|
||||
'//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
|
||||
) as $xpath => $value) {
|
||||
$this->assertTrue(_xpath_test($xml, $xpath, $value), $xpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user