From 3b3e5ed87b223a437df6c351669ee9b8a5720fa5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 29 Jun 2009 06:42:38 -0400 Subject: [PATCH] refactor out get publiser info code --- classes/PluginWonderful.php | 8 +---- test/PluginWonderfulTest.php | 61 ++++++------------------------------ 2 files changed, 11 insertions(+), 58 deletions(-) diff --git a/classes/PluginWonderful.php b/classes/PluginWonderful.php index a8dbcc2..828d178 100644 --- a/classes/PluginWonderful.php +++ b/classes/PluginWonderful.php @@ -73,13 +73,7 @@ class PluginWonderful { $last_update = (int)$last_update; 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->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()); - } - } + $this->_download_project_wonderful_data($member_id); } } diff --git a/test/PluginWonderfulTest.php b/test/PluginWonderfulTest.php index 0b11607..1073df7 100644 --- a/test/PluginWonderfulTest.php +++ b/test/PluginWonderfulTest.php @@ -30,89 +30,48 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase { array( array( 'plugin-wonderful-memberid' => "", - ), - false, - false, - false + ) ), array( array( 'plugin-wonderful-memberid' => 1, 'plugin-wonderful-last-update' => time() - ), - false, - false, - "~*test*~" + ) ), array( array( 'plugin-wonderful-memberid' => 1, 'plugin-wonderful-last-update' => 0 - ), - false, - false, - "~*test*~" + ) ), array( array( 'plugin-wonderful-memberid' => 1, '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 */ - function testGetPublisherInfo($options, $retrieve_url_return, $parse_success, $expected_result) { + function testGetPublisherInfo($options) { 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')); - $test_publisher_info = $this->getMock('PublisherInfo'); - $test_xml_publisher_info = $this->getMock('PublisherInfo', array('parse')); - if (is_numeric($options['plugin-wonderful-memberid'])) { $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()) { - $pw->expects($this->once())->method('_retrieve_url')->will($this->returnValue($retrieve_url_return)); - - 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'); - } + $pw->expects($this->once())->method('_download_project_wonderful_data'); } 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; } - if ($expected_result == "~*test-xml*~") { $expected_result = $test_xml_publisher_info; } - - $this->assertEquals($expected_result, $pw->_get_publisher_info()); + + $pw->_get_publisher_info(); } function providerTestUpdateDatabaseVersion() {