class NodeIntegrationTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest
- 10 core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest
- 8.9.x core/modules/node/tests/src/Functional/Views/NodeIntegrationTest.php \Drupal\Tests\node\Functional\Views\NodeIntegrationTest
Tests the node integration into views.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\node\Functional\Views\NodeIntegrationTest extends \Drupal\Tests\node\Functional\Views\NodeTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeIntegrationTest
File
-
core/
modules/ node/ tests/ src/ Functional/ Views/ NodeIntegrationTest.php, line 10
Namespace
Drupal\Tests\node\Functional\ViewsView source
class NodeIntegrationTest extends NodeTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_node_view',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests basic node view with a node type argument.
*/
public function testNodeViewTypeArgument() {
// 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' => 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()]));
}
}
/**
* Ensures that a list of nodes appear on the page.
*
* @param array $expected_nids
* An array of node IDs.
*
* @internal
*/
protected function assertNids(array $expected_nids = []) : void {
$result = $this->xpath('//span[@class="field-content"]');
$nids = [];
foreach ($result as $element) {
$nids[] = (int) $element->getText();
}
$this->assertEquals($expected_nids, $nids);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.