finish all tests, move widget rendering back to PW
This commit is contained in:
parent
3b3e5ed87b
commit
8abc13692d
@ -273,33 +273,27 @@ class PluginWonderful {
|
||||
}
|
||||
|
||||
function handle_action_change_memberid() {
|
||||
update_option('plugin-wonderful-memberid', "");
|
||||
if (trim($_POST['memberid'])) {
|
||||
if (trim($_POST['memberid']) === (string)(int)$_POST['memberid']) {
|
||||
if (($result = file_get_contents(sprintf(PLUGIN_WONDERFUL_XML_URL, (int)$_POST['memberid']))) !== false) {
|
||||
$this->publisher_info = new PublisherInfo();
|
||||
if ($this->publisher_info->parse($result)) {
|
||||
update_option('plugin-wonderful-memberid', (int)$_POST['memberid']);
|
||||
$this->adboxes_client->post_ads($this->publisher_info);
|
||||
switch ($this->_download_project_wonderful_data((int)$_POST['memberid'])) {
|
||||
case $this->message_types['DOWNLOADED']:
|
||||
$this->messages[] = sprintf(__('Member number changed to %s and adbox information redownloaded.', 'plugin-wonderful'), (int)$_POST['memberid']);
|
||||
} else {
|
||||
break;
|
||||
case $this->message_types['CANT_PARSE']:
|
||||
$this->messages[] = __("Unable to parse publisher data from Project Wonderful.", 'plugin-wonderful');
|
||||
update_option('plugin-wonderful-memberid', "");
|
||||
$this->publisher_info = false;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case $this->message_types['CANT_READ']:
|
||||
$this->messages[] = __("Unable to read publisher data from Project Wonderful.", 'plugin-wonderful');
|
||||
update_option('plugin-wonderful-memberid', "");
|
||||
$this->publisher_info = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$this->messages[] = __("Member numbers need to be numeric.", 'plugin-wonderful');
|
||||
update_option('plugin-wonderful-memberid', "");
|
||||
$this->publisher_info = false;
|
||||
}
|
||||
} else {
|
||||
$this->messages[] = __("Existing adbox information removed.", 'plugin-wonderful');
|
||||
update_option('plugin-wonderful-memberid', "");
|
||||
|
||||
$this->publisher_info = false;
|
||||
}
|
||||
|
||||
@ -307,11 +301,30 @@ class PluginWonderful {
|
||||
update_option("plugin-wonderful-${field}", isset($_POST[$field]) ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
function _render_adbox($adboxid, $center = false) {
|
||||
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 ($center == 1) {
|
||||
$output = "<center>{$output}</center>";
|
||||
}
|
||||
echo $output;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function the_project_wonderful_ad($adboxid) {
|
||||
$w = new PluginWonderfulWidget();
|
||||
$w->widget(array(), array('adboxid' => $adboxid));
|
||||
global $plugin_wonderful;
|
||||
$plugin_wonderful->_render_adbox($adboxid);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -16,23 +16,7 @@ class PluginWonderfulWidget extends WP_Widget {
|
||||
|
||||
function widget($args, $instance) {
|
||||
global $plugin_wonderful;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
$plugin_wonderful->_render_adbox($instance['adboxid'], $instance['center']);
|
||||
}
|
||||
|
||||
function form($instance) {
|
||||
|
@ -112,17 +112,9 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
function testTemplateTag() {
|
||||
global $plugin_wonderful;
|
||||
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful');
|
||||
|
||||
$plugin_wonderful->publisher_info = (object)array(
|
||||
'adboxes' => array(
|
||||
(object)array('adboxid' => '123', 'advancedcode' => "test", 'standardcode' => "not-test")
|
||||
)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful', array('_render_adbox'));
|
||||
$plugin_wonderful->expects($this->once())->method('_render_adbox');
|
||||
the_project_wonderful_ad('123');
|
||||
$this->assertEquals("test", ob_get_clean());
|
||||
}
|
||||
|
||||
function providerInsertAdsIntoRSS() {
|
||||
@ -399,8 +391,68 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
$pw->handle_action_rebuild_database();
|
||||
}
|
||||
|
||||
function testHandleActionChangeMemberID() {
|
||||
$this->markTestIncomplete();
|
||||
function providerTestHandleActionChangeMemberID() {
|
||||
return array(
|
||||
array("", false),
|
||||
array("1.5", false),
|
||||
array("a", false),
|
||||
array("1", true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestHandleActionChangeMemberID
|
||||
*/
|
||||
function testHandleActionChangeMemberID($member_id, $is_downloaded) {
|
||||
$_POST['memberid'] = $member_id;
|
||||
|
||||
$pw = $this->getMock('PluginWonderful', array("_download_project_wonderful_data"));
|
||||
if ($is_downloaded) {
|
||||
$pw->expects($this->once())->method('_download_project_wonderful_data');
|
||||
} else {
|
||||
$pw->expects($this->never())->method('_download_project_wonderful_data');
|
||||
}
|
||||
|
||||
$pw->handle_action_change_memberid();
|
||||
}
|
||||
|
||||
function providerTestRenderAdbox() {
|
||||
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 providerTestRenderAdbox
|
||||
*/
|
||||
function testRenderAdbox($has_publisher_info, $requested_adboxid, $use_standardcode, $center_widget, $expected_result) {
|
||||
global $plugin_wonderful;
|
||||
|
||||
$test_ad = (object)array(
|
||||
'adboxid' => '123',
|
||||
'template_tag_id' => 'abc',
|
||||
'standardcode' => 'standard',
|
||||
'advancedcode' => 'advanced'
|
||||
);
|
||||
|
||||
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_adbox($requested_adboxid, $center_widget);
|
||||
$this->assertEquals($expected_result, ob_get_clean());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,47 +17,14 @@ class PluginWonderfulWidgetTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals("Plugin Wonderful", $wp_test_expectations['wp_widgets']['plugin-wonderful']['name']);
|
||||
}
|
||||
|
||||
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) {
|
||||
function testRenderWidget() {
|
||||
global $plugin_wonderful;
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful');
|
||||
$plugin_wonderful = $this->getMock('PluginWonderful', array('_render_adbox'));
|
||||
$plugin_wonderful->expects($this->once())->method('_render_adbox');
|
||||
|
||||
$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;
|
||||
$this->w->widget(array(), array());
|
||||
}
|
||||
|
||||
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');
|
||||
|
Loading…
Reference in New Issue
Block a user