refactor out get publiser info code

This commit is contained in:
John Bintz 2009-06-29 06:42:38 -04:00
parent 2f9ab57bbd
commit 3b3e5ed87b
2 changed files with 11 additions and 58 deletions

View File

@ -73,13 +73,7 @@ class PluginWonderful {
$last_update = (int)$last_update; $last_update = (int)$last_update;
if (($last_update + PLUGIN_WONDERFUL_UPDATE_TIME) < time()) { if (($last_update + PLUGIN_WONDERFUL_UPDATE_TIME) < time()) {
if (($result = $this->_retrieve_url(sprintf(PLUGIN_WONDERFUL_XML_URL, (int)get_option('plugin-wonderful-memberid')))) !== false) { $this->_download_project_wonderful_data($member_id);
$this->publisher_info = $this->_get_new_publisher_info_object();
if ($this->publisher_info->parse($result)) {
$this->adboxes_client->post_ads($this->publisher_info);
update_option('plugin-wonderful-last-update', time());
}
}
} }
} }

View File

@ -30,89 +30,48 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
array( array(
array( array(
'plugin-wonderful-memberid' => "", 'plugin-wonderful-memberid' => "",
), )
false,
false,
false
), ),
array( array(
array( array(
'plugin-wonderful-memberid' => 1, 'plugin-wonderful-memberid' => 1,
'plugin-wonderful-last-update' => time() 'plugin-wonderful-last-update' => time()
), )
false,
false,
"~*test*~"
), ),
array( array(
array( array(
'plugin-wonderful-memberid' => 1, 'plugin-wonderful-memberid' => 1,
'plugin-wonderful-last-update' => 0 'plugin-wonderful-last-update' => 0
), )
false,
false,
"~*test*~"
), ),
array( array(
array( array(
'plugin-wonderful-memberid' => 1, 'plugin-wonderful-memberid' => 1,
'plugin-wonderful-last-update' => 0 'plugin-wonderful-last-update' => 0
), )
true,
false,
"~*test-xml*~"
), ),
array(
array(
'plugin-wonderful-memberid' => 1,
'plugin-wonderful-last-update' => 0
),
true,
true,
"~*test-xml*~"
)
); );
} }
/** /**
* @dataProvider providerTestGetPubliserInfo * @dataProvider providerTestGetPubliserInfo
*/ */
function testGetPublisherInfo($options, $retrieve_url_return, $parse_success, $expected_result) { function testGetPublisherInfo($options) {
foreach ($options as $key => $value) { update_option($key, $value); } foreach ($options as $key => $value) { update_option($key, $value); }
$pw = $this->getMock('PluginWonderful', array('_retrieve_url', '_get_new_publisher_info_object')); $pw = $this->getMock('PluginWonderful', array('_download_project_wonderful_data'));
$pw->adboxes_client = $this->getMock('PWAdboxesClient', array('get_ads', 'post_ads')); $pw->adboxes_client = $this->getMock('PWAdboxesClient', array('get_ads', 'post_ads'));
$test_publisher_info = $this->getMock('PublisherInfo');
$test_xml_publisher_info = $this->getMock('PublisherInfo', array('parse'));
if (is_numeric($options['plugin-wonderful-memberid'])) { if (is_numeric($options['plugin-wonderful-memberid'])) {
$pw->adboxes_client->expects($this->once())->method('get_ads')->will($this->returnValue($test_publisher_info)); $pw->adboxes_client->expects($this->once())->method('get_ads')->will($this->returnValue($test_publisher_info));
if (($options['plugin-wonderful-last-update'] + PLUGIN_WONDERFUL_UPDATE_TIME) < time()) { if (($options['plugin-wonderful-last-update'] + PLUGIN_WONDERFUL_UPDATE_TIME) < time()) {
$pw->expects($this->once())->method('_retrieve_url')->will($this->returnValue($retrieve_url_return)); $pw->expects($this->once())->method('_download_project_wonderful_data');
if ($retrieve_url_return) {
$pw->expects($this->once())->method('_get_new_publisher_info_object')->will($this->returnValue($test_xml_publisher_info));
$test_xml_publisher_info->expects($this->once())->method('parse')->will($this->returnValue($parse_success));
if ($parse_success) {
$pw->adboxes_client->expects($this->once())->method('post_ads');
} else {
$pw->adboxes_client->expects($this->never())->method('post_ads');
}
} else {
$pw->expects($this->never())->method('_get_new_publisher_info_object');
}
} else { } else {
$pw->expects($this->never())->method('_retrieve_url'); $pw->expects($this->never())->method('_download_project_wonderful_data');
} }
} }
if ($expected_result == "~*test*~") { $expected_result = $test_publisher_info; } $pw->_get_publisher_info();
if ($expected_result == "~*test-xml*~") { $expected_result = $test_xml_publisher_info; }
$this->assertEquals($expected_result, $pw->_get_publisher_info());
} }
function providerTestUpdateDatabaseVersion() { function providerTestUpdateDatabaseVersion() {