You are here

function StyleTest::testCustomRowClasses in Views (for Drupal 7) 8.3

Tests custom css classes.

File

lib/Drupal/views/Tests/Plugin/StyleTest.php, line 284
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 = $this->view
    ->cloneView();

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