class RowPluginTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Kernel/Views/RowPluginTest.php \Drupal\Tests\node\Kernel\Views\RowPluginTest
Tests the node row plugin.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\node\Functional\Views\RowPluginTest implements \Drupal\Tests\node\Functional\Views\NodeTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of RowPluginTest
See also
\Drupal\node\Plugin\views\row\NodeRow
File
-
core/
modules/ node/ tests/ src/ Functional/ Views/ RowPluginTest.php, line 13
Namespace
Drupal\Tests\node\Functional\ViewsView source
class RowPluginTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_node_row_plugin',
];
/**
* Contains all nodes used by this test.
*
* @var array
*/
protected $nodes;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'node_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
$this->drupalCreateContentType([
'type' => 'article',
]);
// Create two nodes.
for ($i = 0; $i < 2; $i++) {
$this->nodes[] = $this->drupalCreateNode([
'type' => 'article',
'body' => [
[
'value' => $this->randomMachineName(42),
'format' => filter_default_format(),
'summary' => $this->randomMachineName(),
],
],
]);
}
}
/**
* Tests the node row plugin.
*/
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.');
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.