RowPluginTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/Views/RowPluginTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
class RowPluginTest extends NodeTestBase {
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_node_row_plugin',
];
protected $nodes;
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->drupalCreateContentType([
'type' => 'article',
]);
for ($i = 0; $i < 2; $i++) {
$this->nodes[] = $this
->drupalCreateNode([
'type' => 'article',
'body' => [
[
'value' => $this
->randomMachineName(42),
'format' => filter_default_format(),
'summary' => $this
->randomMachineName(),
],
],
]);
}
}
public function testRowPlugin() {
$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';
$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.');
}
$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.');
}
}
}