3 namespace Drupal\Tests\node\Functional\Views;
6 * Tests the node integration into views.
10 class NodeIntegrationTest extends NodeTestBase {
13 * Views used by this test.
17 public static $testViews = ['test_node_view'];
20 * Tests basic node view with a node type argument.
22 public function testNodeViewTypeArgument() {
23 // Create two content types with three nodes each.
26 for ($i = 0; $i < 2; $i++) {
27 $type = $this->drupalCreateContentType(['name' => '<em>' . $this->randomMachineName() . '</em>']);
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();
38 $this->drupalGet('test-node-view');
39 $this->assertResponse(404);
41 $this->drupalGet('test-node-view/all');
42 $this->assertResponse(200);
43 $this->assertNids($all_nids);
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()]));
53 * Ensures that a list of nodes appear on the page.
55 * @param array $expected_nids
56 * An array of node IDs.
58 protected function assertNids(array $expected_nids = []) {
59 $result = $this->xpath('//span[@class="field-content"]');
61 foreach ($result as $element) {
62 $nids[] = (int) $element->getText();
64 $this->assertEqual($nids, $expected_nids);