3 namespace Drupal\Tests\history\Kernel\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
7 use Drupal\user\Entity\User;
8 use Drupal\views\Views;
11 * Tests the history timestamp handlers.
14 * @see \Drupal\history\Plugin\views\field\HistoryUserTimestamp
15 * @see \Drupal\history\Plugin\views\filter\HistoryUserTimestamp
17 class HistoryTimestampTest extends ViewsKernelTestBase {
24 public static $modules = ['history', 'node'];
27 * Views used by this test.
31 public static $testViews = ['test_history'];
36 protected function setUp($import_test_views = TRUE) {
37 parent::setUp($import_test_views);
39 $this->installEntitySchema('node');
40 $this->installEntitySchema('user');
41 $this->installSchema('history', ['history']);
42 // Use classy theme because its marker is wrapped in a span so it can be
43 // easily targeted with xpath.
44 \Drupal::service('theme_handler')->install(['classy']);
45 \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('classy'));
51 public function testHandlers() {
53 $node = Node::create([
59 $node = Node::create([
66 $account = User::create(['name' => 'admin']);
68 \Drupal::currentUser()->setAccount($account);
72 'uid' => $account->id(),
73 'nid' => $nodes[0]->id(),
74 'timestamp' => REQUEST_TIME - 100,
79 'uid' => $account->id(),
80 'nid' => $nodes[1]->id(),
81 'timestamp' => REQUEST_TIME + 100,
88 // Test the history field.
89 $view = Views::getView('test_history');
90 $view->setDisplay('page_1');
91 $this->executeView($view);
92 $this->assertEqual(count($view->result), 2);
93 $output = $view->preview();
94 $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
95 $result = $this->xpath('//span[@class=:class]', [':class' => 'marker']);
96 $this->assertEqual(count($result), 1, 'Just one node is marked as new');
98 // Test the history filter.
99 $view = Views::getView('test_history');
100 $view->setDisplay('page_2');
101 $this->executeView($view);
102 $this->assertEqual(count($view->result), 1);
103 $this->assertIdenticalResultset($view, [['nid' => $nodes[0]->id()]], $column_map);
105 // Install Comment module and make sure that content types without comment
106 // field will not break the view.
107 // See \Drupal\history\Plugin\views\filter\HistoryUserTimestamp::query()
108 \Drupal::service('module_installer')->install(['comment']);
109 $view = Views::getView('test_history');
110 $view->setDisplay('page_2');
111 $this->executeView($view);