function RowPluginTest::testRowPlugin

Same name and namespace in other branches
  1. 9 core/modules/node/tests/src/Functional/Views/RowPluginTest.php \Drupal\Tests\node\Functional\Views\RowPluginTest::testRowPlugin()
  2. 8.9.x core/modules/node/tests/src/Functional/Views/RowPluginTest.php \Drupal\Tests\node\Functional\Views\RowPluginTest::testRowPlugin()
  3. 11.x core/modules/node/tests/src/Kernel/Views/RowPluginTest.php \Drupal\Tests\node\Kernel\Views\RowPluginTest::testRowPlugin()

Tests the node row plugin.

File

core/modules/node/tests/src/Kernel/Views/RowPluginTest.php, line 92

Class

RowPluginTest
Tests the node row plugin.

Namespace

Drupal\Tests\node\Kernel\Views

Code

public function testRowPlugin() : void {
  /** @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 = (string) $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 = (string) $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);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.