class NidArgumentTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Kernel/Views/NidArgumentTest.php \Drupal\Tests\node\Kernel\Views\NidArgumentTest
- 10 core/modules/node/tests/src/Kernel/Views/NidArgumentTest.php \Drupal\Tests\node\Kernel\Views\NidArgumentTest
- 8.9.x core/modules/node/tests/src/Kernel/Views/NidArgumentTest.php \Drupal\Tests\node\Kernel\Views\NidArgumentTest
Tests the nid argument handler.
@group node
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\node\Kernel\Views\NidArgumentTest extends \Drupal\Tests\views\Kernel\ViewsKernelTestBase
- class \Drupal\Tests\views\Kernel\ViewsKernelTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of NidArgumentTest
See also
\Drupal\node\Plugin\views\argument\Nid
File
-
core/
modules/ node/ tests/ src/ Kernel/ Views/ NidArgumentTest.php, line 16
Namespace
Drupal\Tests\node\Kernel\ViewsView source
class NidArgumentTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'field',
'text',
'node_test_config',
'user',
'node_test_views',
];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_nid_argument',
];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installConfig([
'node',
'field',
]);
ViewTestData::createTestViews(static::class, [
'node_test_views',
]);
}
/**
* Tests the nid argument.
*/
public function testNidArgument() {
$view = Views::getView('test_nid_argument');
$view->setDisplay();
$node1 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node1->save();
$node2 = Node::create([
'type' => 'default',
'title' => $this->randomMachineName(),
]);
$node2->save();
$view->preview();
$this->assertCount(2, $view->result, 'Found the expected number of results.');
// Set the second node id as an argument.
$view->destroy();
$view->preview('default', [
$node2->id(),
]);
// Verify that the title is overridden.
$this->assertEquals($node2->getTitle(), $view->getTitle());
// Verify that the argument filtering works.
$this->assertCount(1, $view->result, 'Found the expected number of results.');
$this->assertEquals($node2->id(), (string) $view->style_plugin
->getField(0, 'nid'), 'Found the correct nid.');
// Verify that setting a non-existing id as argument results in no nodes
// being shown.
$view->destroy();
$view->preview('default', [
22,
]);
$this->assertCount(0, $view->result, 'Found the expected number of results.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.