3cb4e372c9c053dd42dcb1d3556708004cf611e1
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / PathPluginTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional\Views;
4
5 use Drupal\views\Views;
6
7 /**
8  * Tests the node row plugin.
9  *
10  * @group node
11  */
12 class PathPluginTest extends NodeTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['node'];
20
21   /**
22    * Views used by this test.
23    *
24    * @var array
25    */
26   public static $testViews = ['test_node_path_plugin'];
27
28   /**
29    * Contains all nodes used by this test.
30    *
31    * @var Node[]
32    */
33   protected $nodes;
34
35   /**
36    * {@inheritdoc}
37    */
38   protected function setUp($import_test_views = TRUE) {
39     parent::setUp($import_test_views);
40
41     $this->drupalCreateContentType(['type' => 'article']);
42
43     // Create two nodes.
44     for ($i = 0; $i < 2; $i++) {
45       $this->nodes[] = $this->drupalCreateNode(
46         [
47           'type' => 'article',
48           'body' => [
49             [
50               'value' => $this->randomMachineName(42),
51               'format' => filter_default_format(),
52               'summary' => $this->randomMachineName(),
53             ],
54           ],
55         ]
56       );
57     }
58   }
59
60   /**
61    * Tests the node path plugin.
62    */
63   public function testPathPlugin() {
64     /** @var \Drupal\Core\Render\RendererInterface $renderer */
65     $renderer = $this->container->get('renderer');
66     $view = Views::getView('test_node_path_plugin');
67     $view->initDisplay();
68     $view->setDisplay('page_1');
69     $view->initStyle();
70     $view->rowPlugin->options['view_mode'] = 'full';
71
72     // Test with view_mode full.
73     $output = $view->preview();
74     $output = $renderer->renderRoot($output);
75     foreach ($this->nodes as $node) {
76       $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.');
77     }
78   }
79
80 }