Simpletest Coverage - modules/aggregator/aggregator.fetcher.inc

1 <?php
2 // $Id: aggregator.fetcher.inc,v 1.5 2009/05/27 18:33:54 dries Exp $
3
4 /**
5 * @file
6 * Fetcher functions for the aggregator module.
7 */
8
9 /**
10 * Implement hook_aggregator_fetch_info().
11 */
12 function aggregator_aggregator_fetch_info() {
13 return array(
14 'title' => t('Default fetcher'),
15 'description' => t('Downloads data from a URL using Drupal\'s HTTP request handler.'),
16 );
17 }
18
19 /**
20 * Implement hook_aggregator_fetch().
21 */
22 function aggregator_aggregator_fetch($feed) {
23 $feed->source_string = FALSE;
24
25 // Generate conditional GET headers.
26 $headers = array();
27 if ($feed->etag) {
28 $headers['If-None-Match'] = $feed->etag;
29 }
30 if ($feed->modified) {
31 $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed->modified) . ' GMT';
32 }
33
34 // Request feed.
35 $result = drupal_http_request($feed->url, array('headers' => $headers));
36
37
38 // Process HTTP response code.
39 switch ($result->code) {
40 case 304:
41 db_update('aggregator_feed')
42 ->fields(array('checked' => REQUEST_TIME))
43 ->condition('fid', $feed->fid)
44 ->execute();
45 drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed->title)));
46 break;
47 case 301:
48 $feed->url = $result->redirect_url;
49 $feed->redirected = TRUE;
50 // Do not break here.
51 case 200:
52 case 302:
53 case 307:
54 // We store the md5 hash of feed data in the database. When refreshing a
55 // feed we compare stored hash and new hash calculated from downloaded
56 // data. If both are equal we say that feed is not updated.
57 if (!isset($result->data)) {
58 $result->data = '';
59 }
60 if (!isset($result->headers)) {
61 $result->headers = array();
62 }
63 $md5 = md5($result->data);
64 if ($feed->hash == $md5) {
65 db_update('aggregator_feed')
66 ->condition('fid', $feed->fid)
67 ->fields(array('checked' => REQUEST_TIME))
68 ->execute();
69 drupal_set_message(t('There is no new syndicated content from %site.', array('%site' => $feed->title)));
70 break;
71 }
72
73 $feed->source_string = $result->data;
74 $feed->http_headers = $result->headers;
75 break;
76 default:
77 watchdog('aggregator', 'The feed from %site seems to be broken, due to "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error), WATCHDOG_WARNING);
78 drupal_set_message(t('The feed from %site seems to be broken, because of error "%error".', array('%site' => $feed->title, '%error' => $result->code . ' ' . $result->error)));
79 }
80 }
81

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.