3 namespace Drupal\history\Tests\Views;
5 use Drupal\views\Views;
6 use Drupal\views\Tests\ViewTestBase;
9 * Tests the history timestamp handlers.
12 * @see \Drupal\history\Plugin\views\field\HistoryTimestamp.
13 * @see \Drupal\history\Plugin\views\filter\HistoryTimestamp.
15 class HistoryTimestampTest extends ViewTestBase {
22 public static $modules = ['history', 'node'];
25 * Views used by this test.
29 public static $testViews = ['test_history'];
34 public function testHandlers() {
36 $nodes[] = $this->drupalCreateNode();
37 $nodes[] = $this->drupalCreateNode();
39 $account = $this->drupalCreateUser();
40 $this->drupalLogin($account);
41 \Drupal::currentUser()->setAccount($account);
45 'uid' => $account->id(),
46 'nid' => $nodes[0]->id(),
47 'timestamp' => REQUEST_TIME - 100,
52 'uid' => $account->id(),
53 'nid' => $nodes[1]->id(),
54 'timestamp' => REQUEST_TIME + 100,
62 // Test the history field.
63 $view = Views::getView('test_history');
64 $view->setDisplay('page_1');
65 $this->executeView($view);
66 $this->assertEqual(count($view->result), 2);
67 $output = $view->preview();
68 $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
69 $result = $this->xpath('//span[@class=:class]', [':class' => 'marker']);
70 $this->assertEqual(count($result), 1, 'Just one node is marked as new');
72 // Test the history filter.
73 $view = Views::getView('test_history');
74 $view->setDisplay('page_2');
75 $this->executeView($view);
76 $this->assertEqual(count($view->result), 1);
77 $this->assertIdenticalResultset($view, [['nid' => $nodes[0]->id()]], $column_map);
79 // Install Comment module and make sure that content types without comment
80 // field will not break the view.
81 // See \Drupal\history\Plugin\views\filter\HistoryUserTimestamp::query()
82 \Drupal::service('module_installer')->install(['comment']);
83 $view = Views::getView('test_history');
84 $view->setDisplay('page_2');
85 $this->executeView($view);