function NodeIntegrationTest::testNodeViewTypeArgument

Same name and namespace in other branches
  1. 10 core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest::testNodeViewTypeArgument()
  2. 9 core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest::testNodeViewTypeArgument()
  3. 8.9.x core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest::testNodeViewTypeArgument()
  4. main core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest::testNodeViewTypeArgument()

Tests basic node view with a node type argument.

File

core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php, line 32

Class

NodeIntegrationTest
Tests the node integration into views.

Namespace

Drupal\Tests\node\Functional\Views

Code

public function testNodeViewTypeArgument() : void {
  // Create two content types with three nodes each.
  $types = [];
  $all_nids = [];
  for ($i = 0; $i < 2; $i++) {
    $type = $this->drupalCreateContentType([
      'name' => '<em>' . $this->randomMachineName() . '</em>',
    ]);
    $types[] = $type;
    for ($j = 0; $j < 5; $j++) {
      // Ensure the right order of the nodes.
      $node = $this->drupalCreateNode([
        'type' => $type->id(),
        'created' => \Drupal::time()->getRequestTime() - ($i * 5 + $j),
      ]);
      $nodes[$type->id()][$node->id()] = $node;
      $all_nids[] = $node->id();
    }
  }
  $this->drupalGet('test-node-view');
  $this->assertSession()
    ->statusCodeEquals(404);
  $this->drupalGet('test-node-view/all');
  $this->assertSession()
    ->statusCodeEquals(200);
  $this->assertNids($all_nids);
  foreach ($types as $type) {
    $this->drupalGet("test-node-view/{$type->id()}");
    $this->assertSession()
      ->assertEscaped($type->label());
    $this->assertNids(array_keys($nodes[$type->id()]));
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.