You are here

public function StyleTest::testCustomRowClasses in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Kernel/Plugin/StyleTest.php \Drupal\Tests\views\Kernel\Plugin\StyleTest::testCustomRowClasses()
  2. 9 core/modules/views/tests/src/Kernel/Plugin/StyleTest.php \Drupal\Tests\views\Kernel\Plugin\StyleTest::testCustomRowClasses()

Tests custom CSS row classes.

File

core/modules/views/tests/src/Kernel/Plugin/StyleTest.php, line 278

Class

StyleTest
Tests general style functionality.

Namespace

Drupal\Tests\views\Kernel\Plugin

Code

public function testCustomRowClasses() {
  $view = Views::getView('test_view');
  $view
    ->setDisplay();

  // Setup some random css class.
  $view
    ->initStyle();
  $random_name = $this
    ->randomMachineName();
  $view->style_plugin->options['row_class'] = $random_name . " test-token-{{ name }}";
  $output = $view
    ->preview();
  $html_dom = $this
    ->getHtmlDom($this->container
    ->get('renderer')
    ->renderRoot($output));
  $rows = $html_dom->body->div->div;
  $count = 0;
  foreach ($rows as $row) {
    $attributes = $row
      ->attributes();
    $class = (string) $attributes['class'][0];
    $this
      ->assertStringContainsString($random_name, $class);

    // Check token replacement.
    $name = $view->field['name']
      ->getValue($view->result[$count]);
    $this
      ->assertStringContainsString("test-token-{$name}", $class);
    $count++;
  }
}