You are here

public function StyleTest::testStyle in Views (for Drupal 7) 8.3

Tests the general renderering of styles.

File

lib/Drupal/views/Tests/Plugin/StyleTest.php, line 28
Definition of Drupal\views\Tests\Plugin\StyleTest.

Class

StyleTest
Tests some general style plugin related functionality.

Namespace

Drupal\views\Tests\Plugin

Code

public function testStyle() {
  $view = $this
    ->getView();
  $style = $view->display_handler
    ->getOption('style');
  $style['type'] = 'test_style';
  $view->display_handler
    ->setOption('style', $style);
  $view
    ->initDisplay();
  $view
    ->initStyle();
  $this
    ->assertTrue($view->style_plugin instanceof \Drupal\views_test_data\Plugin\views\style\StyleTest, 'Make sure the right style plugin class is loaded.');
  $random_text = $this
    ->randomName();

  // Set some custom text to the output and make sure that this value is
  // rendered.
  $view->style_plugin
    ->setOutput($random_text);
  $output = $view
    ->preview();
  $this
    ->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the style plugin appears in the output of the view.');

  // This run use the test row plugin and render with it.
  $view = $this
    ->getView();
  $style = $view->display_handler
    ->getOption('style');
  $style['type'] = 'test_style';
  $view->display_handler
    ->setOption('style', $style);
  $row = $view->display_handler
    ->getOption('row');
  $row['type'] = 'test_row';
  $view->display_handler
    ->setOption('row', $row);
  $view
    ->initDisplay();
  $view
    ->initStyle();
  $view->style_plugin
    ->setUsesRowPlugin(TRUE);

  // Reinitialize the style as it supports row plugins now.
  $view->style_plugin
    ->init($view, $view->display_handler, array());
  $this
    ->assertTrue($view->style_plugin->row_plugin instanceof \Drupal\views_test_data\Plugin\views\row\RowTest, 'Make sure the right row plugin class is loaded.');
  $random_text = $this
    ->randomName();
  $view->style_plugin->row_plugin
    ->setOutput($random_text);
  $output = $view
    ->preview();
  $this
    ->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the row plugin appears in the output of the view.');
}