You are here

public function CacheTest::testArgumentDefaultCache in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/CacheTest.php \Drupal\Tests\views\Kernel\Plugin\CacheTest::testArgumentDefaultCache()
  2. 9 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 389

Class

CacheTest
Tests pluggable caching for views.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testArgumentDefaultCache() {
  $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
    ->renderPlain($output);
  $this
    ->assertEquals([
    'config:views.view.test_view',
    'example_tag',
  ], $output['#cache']['tags']);
}