PathPluginTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/Views/PathPluginTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\views\Views;
class PathPluginTest extends NodeTestBase {
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_node_path_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 testPathPlugin() {
$renderer = $this->container
->get('renderer');
$view = Views::getView('test_node_path_plugin');
$field = $view
->getHandler('page_1', 'field', 'path');
$this
->assertEquals('entity_link', $field['plugin_id']);
$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
->assertStringContainsString('This is <strong>not escaped</strong> and this is ' . $node
->toLink('the link')
->toString(), $output, 'Make sure path field rewriting is not escaped.');
}
}
}