function StyleTest::testCustomRowClasses

Tests custom css classes.

File

drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/StyleTest.php, line 221
Definition of Drupal\views\Tests\Plugin\StyleTest.

Class

StyleTest
Tests some general style plugin related functionality.

Namespace

Drupal\views\Tests\Plugin

Code

function testCustomRowClasses() {
  $view = views_get_view('test_view');
  $view
    ->setDisplay();

  // Setup some random css class.
  $view
    ->initStyle();
  $random_name = $this
    ->randomName();
  $view->style_plugin->options['row_class'] = $random_name . " test-token-[name]";
  $output = $view
    ->preview();
  $this
    ->storeViewPreview(drupal_render($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, 'Take 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, 'Take sure that a token in custom css class is replaced.');
    $count++;
  }
}