Simpletest Coverage - modules/aggregator/aggregator_test.module

1 <?php
2 // $Id: aggregator_test.module,v 1.1 2009/03/01 07:21:02 webchick Exp $
3
4 /**
5 * Implementation of hook_menu().
6 */
7 function aggregator_test_menu() {
8 $items['aggregator/test-feed'] = array(
9 'title' => 'Test feed static last modified date',
10 'description' => "A cached test feed with a static last modified date.",
11 'page callback' => 'aggregator_test_feed',
12 'access arguments' => array('access content'),
13 );
14 return $items;
15 }
16
17 /**
18 * Page callback. Generates a test feed and simulates last-modified and etags.
19 *
20 * @param $use_last_modified
21 * Set TRUE to send a last modified header.
22 * @param $use_etag
23 * Set TRUE to send an etag.
24 */
25 function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
26 $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
27 $etag = md5($last_modified);
28
29 $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
30 $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
31
32 // Send appropriate response. We respond with a 304 not modified on either
33 // etag or on last modified.
34 if ($use_last_modified) {
35 drupal_set_header("Last-Modified: " . gmdate(DATE_RFC1123, $last_modified));
36 }
37 if ($use_etag) {
38 drupal_set_header("ETag: " .$etag);
39 }
40 // Return 304 not modified if either last modified or etag match.
41 if ($last_modified == $if_modified_since || $etag == $if_none_match) {
42 drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
43 return;
44 }
45
46 // The following headers force validation of cache:
47 drupal_set_header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
48 drupal_set_header("Cache-Control: must-revalidate");
49 drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
50
51 // Read actual feed from file.
52 $file_name = DRUPAL_ROOT . '/' . drupal_get_path('module', 'aggregator') . '/aggregator_test_rss091.xml';
53 $handle = fopen($file_name, 'r');
54 $feed = fread($handle, filesize($file_name));
55 fclose($handle);
56
57 print $feed;
58 }
59

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.