Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Views / NidArgumentTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Views;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\views\Tests\ViewTestData;
8 use Drupal\views\Views;
9
10 /**
11  * Tests the nid argument handler.
12  *
13  * @group node
14  * @see \Drupal\node\Plugin\views\argument\Nid
15  */
16 class NidArgumentTest extends ViewsKernelTestBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public static $modules = ['node', 'field', 'text', 'node_test_config', 'user', 'node_test_views'];
22
23   /**
24    * Views used by this test.
25    *
26    * @var array
27    */
28   public static $testViews = ['test_nid_argument'];
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp($import_test_views = TRUE) {
34     parent::setUp($import_test_views);
35
36     $this->installEntitySchema('node');
37     $this->installEntitySchema('user');
38     $this->installConfig(['node', 'field']);
39
40     ViewTestData::createTestViews(get_class($this), ['node_test_views']);
41   }
42
43   /**
44    * Test the nid argument.
45    */
46   public function testNidArgument() {
47     $view = Views::getView('test_nid_argument');
48     $view->setDisplay();
49
50     $node1 = Node::create([
51       'type' => 'default',
52       'title' => $this->randomMachineName(),
53     ]);
54     $node1->save();
55     $node2 = Node::create([
56       'type' => 'default',
57       'title' => $this->randomMachineName(),
58     ]);
59     $node2->save();
60
61     $view->preview();
62     $this->assertEqual(count($view->result), 2, 'Found the expected number of results.');
63
64     // Set an the second node id as an argument.
65     $view->destroy();
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.');
72
73     // Verify that setting a non-existing id as argument results in no nodes
74     // being shown.
75     $view->destroy();
76     $view->preview('default', [22]);
77     $this->assertEqual(count($view->result), 0, 'Found the expected number of results.');
78   }
79
80 }