function CacheTest::testArgumentDefaultCache

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

Tests that cacheability metadata is carried over from argument defaults.

File

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

Class

CacheTest
Tests pluggable caching for views.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testArgumentDefaultCache() : void {
    $view = Views::getView('test_view');
    // Add a new argument and set the test plugin for the argument_default.
    $options = [
        'default_argument_type' => 'argument_default_test',
        'default_argument_options' => [
            'value' => 'John',
        ],
        'default_action' => 'default',
    ];
    $view->addHandler('default', 'argument', 'views_test_data', 'name', $options);
    $view->initHandlers();
    $output = $view->preview();
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    $renderer->renderInIsolation($output);
    $this->assertEquals([
        'config:views.view.test_view',
        'example_tag',
    ], $output['#cache']['tags']);
}

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