8.3.x CacheTest.php public CacheTest::testTimeResultCaching()
8.0.x CacheTest.php public CacheTest::testTimeResultCaching()
8.1.x CacheTest.php public CacheTest::testTimeResultCaching()
8.2.x CacheTest.php public CacheTest::testTimeResultCaching()
8.4.x CacheTest.php public CacheTest::testTimeResultCaching()

Tests time based caching.

See also

views_plugin_cache_time

File

core/modules/views/tests/src/Kernel/Plugin/CacheTest.php, line 70

Class

CacheTest
Tests pluggable caching for views.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testTimeResultCaching() {
  $view = Views::getView('test_cache');
  $view->setDisplay();
  $view->display_handler->overrideOption('cache', array(
    'type' => 'time',
    'options' => array(
      'results_lifespan' => '3600',
      'output_lifespan' => '3600',
    )
  ));

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

  // Add another man to the beatles.
  $record = array(
    'name' => 'Rod Davis',
    'age' => 29,
    'job' => 'Banjo',
  );
  db_insert('views_test_data')->fields($record)->execute();

  // The result should be the same as before, because of the caching. (Note
  // that views_test_data records don't have associated cache tags, and hence
  // the results cache items aren't invalidated.)
  $view->destroy();
  $this->executeView($view);
  // Verify the result.
  $this->assertEqual(5, count($view->result), 'The number of returned rows match.');
}