3 namespace Drupal\Tests\node\Functional\Views;
5 use Drupal\views\Views;
8 * Tests the node row plugin.
11 * @see \Drupal\node\Plugin\views\row\NodeRow
13 class RowPluginTest extends NodeTestBase {
20 public static $modules = ['node'];
23 * Views used by this test.
27 public static $testViews = ['test_node_row_plugin'];
30 * Contains all nodes used by this test.
39 protected function setUp($import_test_views = TRUE) {
40 parent::setUp($import_test_views);
42 $this->drupalCreateContentType(['type' => 'article']);
45 for ($i = 0; $i < 2; $i++) {
46 $this->nodes[] = $this->drupalCreateNode(
51 'value' => $this->randomMachineName(42),
52 'format' => filter_default_format(),
53 'summary' => $this->randomMachineName(),
62 * Tests the node row plugin.
64 public function testRowPlugin() {
65 /** @var \Drupal\Core\Render\RendererInterface $renderer */
66 $renderer = $this->container->get('renderer');
67 $view = Views::getView('test_node_row_plugin');
69 $view->setDisplay('page_1');
71 $view->rowPlugin->options['view_mode'] = 'full';
73 // Test with view_mode full.
74 $output = $view->preview();
75 $output = $renderer->renderRoot($output);
76 foreach ($this->nodes as $node) {
77 $this->assertFalse(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
78 $this->assertTrue(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text appears in the output of the view.');
82 $view->rowPlugin->options['view_mode'] = 'teaser';
83 $output = $view->preview();
84 $output = $renderer->renderRoot($output);
85 foreach ($this->nodes as $node) {
86 $this->assertTrue(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
87 $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.');