You are here

public function RowPluginTest::testRowPlugin in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/Views/RowPluginTest.php \Drupal\node\Tests\Views\RowPluginTest::testRowPlugin()

Tests the node row plugin.

File

core/modules/node/src/Tests/Views/RowPluginTest.php, line 66
Contains \Drupal\node\Tests\Views\RowPluginTest.

Class

RowPluginTest
Tests the node row plugin.

Namespace

Drupal\node\Tests\Views

Code

public function testRowPlugin() {

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = $this->container
    ->get('renderer');
  $view = Views::getView('test_node_row_plugin');
  $view
    ->initDisplay();
  $view
    ->setDisplay('page_1');
  $view
    ->initStyle();
  $view->rowPlugin->options['view_mode'] = 'full';

  // Test with view_mode full.
  $output = $view
    ->preview();
  $output = $renderer
    ->renderRoot($output);
  foreach ($this->nodes as $node) {
    $this
      ->assertFalse(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
    $this
      ->assertTrue(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text appears in the output of the view.');
  }

  // Test with teasers.
  $view->rowPlugin->options['view_mode'] = 'teaser';
  $output = $view
    ->preview();
  $output = $renderer
    ->renderRoot($output);
  foreach ($this->nodes as $node) {
    $this
      ->assertTrue(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
    $this
      ->assertFalse(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.');
  }
}