function testResponseFailure() { // Create a Mock http object $fetcher =& new Mockhttp(); $fetcher->setReturnValue('fetch', false); // Run the function $response = fetch_remote_xml('example', $fetcher); // Assert what kind of response we want $this->assertFalse($response); }
function fs_fetch_feedburner_data($url, $action, $get = '', $fetcher = false) { // Let's instantiate our result variable ahead of time, assuming // that the result will not be a success $result = array('success' => false); $name = ''; if ($url == '') { // If no URL was passed in, stop now and return an error message $result['error'] = fs_translatable_error('Configuration needed'); return $result; } elseif (preg_match("|(http:\\/\\/)?feed(.*)\\.com\\/|", $url) != 0) { // If we're using a Google FeedBurner/Google FeedProxy feed, // we'll use PCRE to grab the feed name (temporarily stored in // the $name variable) $name = preg_replace("|(http:\\/\\/)?feed(.*)\\.com\\/|", "", $url); } else { // For backwards compatibility reasons, if the feed URL isn't // a URL, we'll assume that it's the feed name $name = $url; } // Generate our request string $format = "https://feedburner.google.com/api/awareness/1.0/%s?uri=%s&%s"; $request = sprintf($format, $action, $name, $get); // Try to pull down the data $response = fetch_remote_xml($request, $fetcher); // Search through the feed for errors if (preg_match('|rsp stat="fail"|', $response->body)) { // If there's an error embedded in the feed response, make it // grammatically correct and translatable preg_match('|msg="(.*?)"|', $response->body, $msg); $result['error'] = fs_translatable_error($msg[1]); } elseif ($response->status == "401") { // If the feed does not permit AwAPI access, return that; // sometimes $result['error'] = fs_translatable_error('This feed does not permit Awareness API access'); } elseif ($response->status == "500") { // If FeedBurner is giving us an internal server error, // return the boilerplate message $result['error'] = fs_translatable_error('Feedburner issues'); } elseif (strlen($response->body) == 0) { // If there was no data returned, then there was some // problem with trying to contact FeedBurner $result['error'] = fs_translatable_error('Cannot access FeedBurner'); } elseif ($response->status == "200") { // Everything went well, so return the response from // FeedBurner back to the user $result['success'] = true; $result['status'] = $response->status; $result['data'] = $response->body; $result['url'] = $data->url; } else { // We have no idea what went wrong; tell that to the user $result['error'] = fs_translatable_error('Unknown error'); } // Send the engine as well (for debugging purposes) $result['engine'] = $response; // Return our result array to the user return $result; }