1 views_cache.test ViewsCacheTest::testTimeCaching()

Tests time based caching.

See also

views_plugin_cache_time

File

core/modules/views/tests/views_cache.test, line 71
Definition of ViewsCacheTest.

Class

ViewsCacheTest
Basic test for pluggable caching.

Code

function testTimeCaching() {
  // Create a basic result which just 2 results.
  $view = $this->getBasicView();
  $view->set_display();
  $view->display_handler->override_option('cache', array(
    'type' => 'time',
    'results_lifespan' => '3600',
    'output_lifespan' => '3600',
  ));

  $this->executeView($view);
  // Verify the result.
  $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));

  // Add another man to the beatles.
  $record = array(
    'name' => 'Rod Davis',
    'age' => 29,
    'job' => 'Banjo',
  );
  backdrop_write_record('views_test', $record);

  // The Result should be the same as before, because of the caching.
  $view = $this->getBasicView();
  $view->set_display();
  $view->display_handler->override_option('cache', array(
    'type' => 'time',
    'results_lifespan' => '3600',
    'output_lifespan' => '3600',
  ));

  $this->executeView($view);
  // Verify the result.
  $this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
}