You are here

public function FeedsFileHTTPTestCase::testFeedsHTTPFetcherResultGetRaw in Feeds 7.2

Tests that FeedsHTTPFetcherResult::getRaw() always returns the same result for the same instance, even when caches are cleared in between.

Parsers can call this method multiple times on separate requests. When an import did not complete in one run, the source should never be refetched when calling getRaw().

When an import is restarted, a new FeedsHTTPFetcherResult is created and in that case the source *should* be refetched.

File

tests/feeds_fetcher_http.test, line 612
Contains FeedsFileHTTPTestCase.

Class

FeedsFileHTTPTestCase
HTTP fetcher test class.

Code

public function testFeedsHTTPFetcherResultGetRaw() {

  // Set source file to fetch.
  $source_url = url('testing/feeds/nodes.csv', array(
    'absolute' => TRUE,
  ));

  // Retrieve the raw content.
  $fetcher_result1 = new FeedsHTTPFetcherResult($source_url);
  $raw1 = $fetcher_result1
    ->getRaw();

  // Simulate the case where the import is picked up later. In between caches
  // were cleared, the source was changed by the source provider and the
  // fetcher result was serialized and saved in the database.
  $fetcher_result_serialized = serialize($fetcher_result1);

  // Assert that the raw content was not serialized.
  $this
    ->assertTrue(strpos($fetcher_result_serialized, $raw1) === FALSE, 'The raw data was not saved in the serialized fetcher result.');
  variable_set('feeds_tests_nodes_changed', TRUE);
  drupal_static_reset();
  drupal_flush_all_caches();

  // And retrieve the raw content again.
  $fetcher_result2 = unserialize($fetcher_result_serialized);
  $raw2 = $fetcher_result2
    ->getRaw();

  // Assert that the content didn't change.
  $this
    ->assertEqual($raw1, $raw2, 'The fetcher result returned the same raw data.');

  // Simulate the case where the import has restarted and ensure that the
  // contents *do* change in that case.
  $fetcher_result3 = new FeedsHTTPFetcherResult($source_url);
  $raw3 = $fetcher_result3
    ->getRaw();

  // Assert that the content changed.
  $this
    ->assertNotEqual($raw1, $raw3, 'A new fetcher result returned the other raw data.');
}