NodeIntegrationTest.php in Drupal 9
File
core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
class NodeIntegrationTest extends NodeTestBase {
public static $testViews = [
'test_node_view',
];
protected $defaultTheme = 'stark';
public function testNodeViewTypeArgument() {
$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++) {
$node = $this
->drupalCreateNode([
'type' => $type
->id(),
'created' => REQUEST_TIME - ($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()]));
}
}
protected function assertNids(array $expected_nids = []) {
$result = $this
->xpath('//span[@class="field-content"]');
$nids = [];
foreach ($result as $element) {
$nids[] = (int) $element
->getText();
}
$this
->assertEquals($expected_nids, $nids);
}
}