Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / NodeIntegrationTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional\Views;
4
5 /**
6  * Tests the node integration into views.
7  *
8  * @group node
9  */
10 class NodeIntegrationTest extends NodeTestBase {
11
12   /**
13    * Views used by this test.
14    *
15    * @var array
16    */
17   public static $testViews = ['test_node_view'];
18
19   /**
20    * Tests basic node view with a node type argument.
21    */
22   public function testNodeViewTypeArgument() {
23     // Create two content types with three nodes each.
24     $types = [];
25     $all_nids = [];
26     for ($i = 0; $i < 2; $i++) {
27       $type = $this->drupalCreateContentType(['name' => '<em>' . $this->randomMachineName() . '</em>']);
28       $types[] = $type;
29
30       for ($j = 0; $j < 5; $j++) {
31         // Ensure the right order of the nodes.
32         $node = $this->drupalCreateNode(['type' => $type->id(), 'created' => REQUEST_TIME - ($i * 5 + $j)]);
33         $nodes[$type->id()][$node->id()] = $node;
34         $all_nids[] = $node->id();
35       }
36     }
37
38     $this->drupalGet('test-node-view');
39     $this->assertResponse(404);
40
41     $this->drupalGet('test-node-view/all');
42     $this->assertResponse(200);
43     $this->assertNids($all_nids);
44
45     foreach ($types as $type) {
46       $this->drupalGet("test-node-view/{$type->id()}");
47       $this->assertEscaped($type->label());
48       $this->assertNids(array_keys($nodes[$type->id()]));
49     }
50   }
51
52   /**
53    * Ensures that a list of nodes appear on the page.
54    *
55    * @param array $expected_nids
56    *   An array of node IDs.
57    */
58   protected function assertNids(array $expected_nids = []) {
59     $result = $this->xpath('//span[@class="field-content"]');
60     $nids = [];
61     foreach ($result as $element) {
62       $nids[] = (int) $element->getText();
63     }
64     $this->assertEqual($nids, $expected_nids);
65   }
66
67 }