diff --git a/classes/PluginWonderful.php b/classes/PluginWonderful.php index 2a42d10..98a5c18 100644 --- a/classes/PluginWonderful.php +++ b/classes/PluginWonderful.php @@ -93,7 +93,7 @@ class PluginWonderful { if (!empty($result)) { echo $result; } } - function render_widget($options, $adboxid) { + 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)) { diff --git a/classes/PluginWonderfulWidget.php b/classes/PluginWonderfulWidget.php index 7918763..e7708cb 100644 --- a/classes/PluginWonderfulWidget.php +++ b/classes/PluginWonderfulWidget.php @@ -15,9 +15,9 @@ class PluginWonderfulWidget extends WP_Widget { } function widget($args, $instance) { - extract($args); - + global $plugin_wonderful; + $plugin_wonderful->render_widget($instance['adboxid']); } } diff --git a/test/PluginWonderfulTest.php b/test/PluginWonderfulTest.php index ed98bd2..e807699 100644 --- a/test/PluginWonderfulTest.php +++ b/test/PluginWonderfulTest.php @@ -179,6 +179,44 @@ 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, "
standard
") + ); + } + + /** + * @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()); + } } ?> \ No newline at end of file