You are here

public function FeedsHTTPCacheTest::testSet in Feeds 7.2

@covers FeedsHTTPCache::set().

File

tests/FeedsHTTPCacheTest.test, line 253

Class

FeedsHTTPCacheTest
@coversDefaultClass FeedsHTTPCache @group feeds

Code

public function testSet() {
  $response = $this
    ->createHttpResponse();
  $cid = $this
    ->createCacheRecordUsingApi(NULL, $response);

  // Assert that a record was created with the expected data.
  $record = db_select('cache_feeds_http')
    ->fields('cache_feeds_http', array())
    ->condition('cid', $cid)
    ->execute()
    ->fetch();

  // Check cache record.
  $this
    ->assertEqual($cid, $record->cid);
  $this
    ->assertEqual(CACHE_PERMANENT, $record->expire);

  // Check that the raw data wasn't saved in the cache record.
  $this
    ->assertFalse(strpos($record->data, $response->data), 'The raw data was not saved in the database.');

  // Check properties.
  $saved_response = unserialize($record->data);
  $this
    ->assertTrue($saved_response instanceof FeedsHTTPCacheItem, 'Cached data is instance of class FeedsHTTPCacheItem.');
  $this
    ->assertEqual($response->headers, $saved_response->headers);
  $this
    ->assertEqual(static::FEEDS_CACHE_DIR . '/' . $cid, $saved_response->file_path);

  // Assert that a file was created on the file system.
  $this
    ->assertTrue(file_exists(static::FEEDS_CACHE_DIR . '/' . $cid));
}