Version 1
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / PathPluginTest.php
diff --git a/web/core/modules/node/tests/src/Functional/Views/PathPluginTest.php b/web/core/modules/node/tests/src/Functional/Views/PathPluginTest.php
new file mode 100644 (file)
index 0000000..3cb4e37
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+
+namespace Drupal\Tests\node\Functional\Views;
+
+use Drupal\views\Views;
+
+/**
+ * Tests the node row plugin.
+ *
+ * @group node
+ */
+class PathPluginTest extends NodeTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['node'];
+
+  /**
+   * Views used by this test.
+   *
+   * @var array
+   */
+  public static $testViews = ['test_node_path_plugin'];
+
+  /**
+   * Contains all nodes used by this test.
+   *
+   * @var Node[]
+   */
+  protected $nodes;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp($import_test_views = TRUE) {
+    parent::setUp($import_test_views);
+
+    $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 path plugin.
+   */
+  public function testPathPlugin() {
+    /** @var \Drupal\Core\Render\RendererInterface $renderer */
+    $renderer = $this->container->get('renderer');
+    $view = Views::getView('test_node_path_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->assertTrue(strpos($output, 'This is <strong>not escaped</strong> and this is ' . $node->link('the link')) !== FALSE, 'Make sure path field rewriting is not escaped.');
+    }
+  }
+
+}