You are here

function StyleTest::testCustomRowClasses in Zircon Profile 8

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

Tests custom css classes.

File

core/modules/views/src/Tests/Plugin/StyleTest.php, line 259
Contains \Drupal\views\Tests\Plugin\StyleTest.

Class

StyleTest
Tests general style functionality.

Namespace

Drupal\views\Tests\Plugin

Code

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();
  $this
    ->storeViewPreview(\Drupal::service('renderer')
    ->renderRoot($output));
  $rows = $this->elements->body->div->div->div;
  $count = 0;
  foreach ($rows as $row) {
    $attributes = $row
      ->attributes();
    $class = (string) $attributes['class'][0];
    $this
      ->assertTrue(strpos($class, $random_name) !== FALSE, 'Make sure that a custom css class is added to the output.');

    // Check token replacement.
    $name = $view->field['name']
      ->getValue($view->result[$count]);
    $this
      ->assertTrue(strpos($class, "test-token-{$name}") !== FALSE, 'Make sure that a token in custom css class is replaced.');
    $count++;
  }
}