You are here

public function RowPluginTest::testRowPlugin in Drupal 9

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

Tests the node row plugin.

File

core/modules/node/tests/src/Functional/Views/RowPluginTest.php, line 69

Class

RowPluginTest
Tests the node row plugin.

Namespace

Drupal\Tests\node\Functional\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
      ->assertStringNotContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
    $this
      ->assertStringContainsString($node->body->value, $output, '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
      ->assertStringContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
    $this
      ->assertStringNotContainsString($node->body->value, $output, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.');
  }
}