3 namespace Drupal\Tests\node\Kernel\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views\Tests\ViewTestData;
8 use Drupal\views\Views;
11 * Tests the nid argument handler.
14 * @see \Drupal\node\Plugin\views\argument\Nid
16 class NidArgumentTest extends ViewsKernelTestBase {
21 public static $modules = ['node', 'field', 'text', 'node_test_config', 'user', 'node_test_views'];
24 * Views used by this test.
28 public static $testViews = ['test_nid_argument'];
33 protected function setUp($import_test_views = TRUE) {
34 parent::setUp($import_test_views);
36 $this->installEntitySchema('node');
37 $this->installEntitySchema('user');
38 $this->installConfig(['node', 'field']);
40 ViewTestData::createTestViews(get_class($this), ['node_test_views']);
44 * Test the nid argument.
46 public function testNidArgument() {
47 $view = Views::getView('test_nid_argument');
50 $node1 = Node::create([
52 'title' => $this->randomMachineName(),
55 $node2 = Node::create([
57 'title' => $this->randomMachineName(),
62 $this->assertEqual(count($view->result), 2, 'Found the expected number of results.');
64 // Set an the second node id as an argument.
66 $view->preview('default', [$node2->id()]);
67 // Verify that the title is overridden.
68 $this->assertEqual($view->getTitle(), $node2->getTitle());
69 // Verify that the argument filtering works.
70 $this->assertEqual(count($view->result), 1, 'Found the expected number of results.');
71 $this->assertEqual($node2->id(), (string) $view->style_plugin->getField(0, 'nid'), 'Found the correct nid.');
73 // Verify that setting a non-existing id as argument results in no nodes
76 $view->preview('default', [22]);
77 $this->assertEqual(count($view->result), 0, 'Found the expected number of results.');