You are here

function feeds_tests_nodes in Feeds 7.2

Page callback. Generates a test feed and simulates last-modified.

This is used to test the following:

  • Ensure that the source is not refetched on a second import when the source did not change.
  • Ensure that the source *is* refetched on a second import when the source *did* change.

See also

FeedsFileHTTPTestCase::testHttpRequestUsingFileCache()

FeedsFileHTTPTestCase::testSourceCaching()

FeedsFileHTTPTestCase::testChangedSource()

FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns()

1 string reference to 'feeds_tests_nodes'
feeds_tests_menu in tests/feeds_tests.module
Implements hook_menu().

File

tests/feeds_tests.module, line 286
Helper module for Feeds tests.

Code

function feeds_tests_nodes() {
  if (variable_get('feeds_tests_nodes_changed', FALSE)) {
    $file = 'nodes_changes2.csv';
    $last_modified = strtotime('Sun, 30 Mar 2016 10:19:55 GMT');
  }
  else {
    $file = 'nodes.csv';
    $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
  }
  $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
  $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;

  // Set header with last modified date.
  drupal_add_http_header('Last-Modified', gmdate(DATE_RFC7231, $last_modified));

  // Return 304 not modified if last modified.
  if ($last_modified == $if_modified_since) {
    drupal_add_http_header('Status', '304 Not Modified');
    return;
  }

  // The following headers force validation of cache:
  drupal_add_http_header('Expires', $last_modified);
  drupal_add_http_header('Cache-Control', 'must-revalidate');
  drupal_add_http_header('Content-Type', 'text/plain; charset=utf-8');

  // Read actual feed from file.
  $csv = file_get_contents(drupal_get_path('module', 'feeds') . '/tests/feeds/' . $file);
  print $csv;
}