function CacheTest::testNoneResultCaching

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/CacheTest.php \Drupal\Tests\views\Kernel\Plugin\CacheTest::testNoneResultCaching()
  2. 8.9.x core/modules/views/tests/src/Kernel/Plugin/CacheTest.php \Drupal\Tests\views\Kernel\Plugin\CacheTest::testNoneResultCaching()
  3. 10 core/modules/views/tests/src/Kernel/Plugin/CacheTest.php \Drupal\Tests\views\Kernel\Plugin\CacheTest::testNoneResultCaching()

Tests no caching.

See also

views_plugin_cache_time

File

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

Class

CacheTest
Tests pluggable caching for views.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testNoneResultCaching() : void {
    // Create a basic result which just 2 results.
    $view = Views::getView('test_cache');
    $view->setDisplay();
    $view->display_handler
        ->overrideOption('cache', [
        'type' => 'none',
        'options' => [],
    ]);
    $this->executeView($view);
    // Verify the result.
    $this->assertCount(5, $view->result, 'The number of returned rows match.');
    // Add another man to the beatles.
    $record = [
        'name' => 'Rod Davis',
        'age' => 29,
        'job' => 'Banjo',
    ];
    Database::getConnection()->insert('views_test_data')
        ->fields($record)
        ->execute();
    // The Result changes, because the view is not cached.
    $view = Views::getView('test_cache');
    $view->setDisplay();
    $view->display_handler
        ->overrideOption('cache', [
        'type' => 'none',
        'options' => [],
    ]);
    $this->executeView($view);
    // Verify the result.
    $this->assertCount(6, $view->result, 'The number of returned rows match.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.