public function HistoryTimestampTest::testHandlers

Tests the handlers.

File

drupal/core/modules/history/lib/Drupal/history/Tests/Views/HistoryTimestampTest.php, line 45
Contains \Drupal\history\Tests\Views\HistoryTimestampTest.

Class

HistoryTimestampTest
Tests the history timestamp handlers.

Namespace

Drupal\history\Tests\Views

Code

public function testHandlers() {
  $nodes = array();
  $nodes[] = $this
    ->drupalCreateNode();
  $nodes[] = $this
    ->drupalCreateNode();
  $account = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($account);
  $GLOBALS['user'] = $account;
  db_insert('history')
    ->fields(array(
    'uid' => $account
      ->id(),
    'nid' => $nodes[0]
      ->id(),
    'timestamp' => REQUEST_TIME - 100,
  ))
    ->execute();
  db_insert('history')
    ->fields(array(
    'uid' => $account
      ->id(),
    'nid' => $nodes[1]
      ->id(),
    'timestamp' => REQUEST_TIME + 100,
  ))
    ->execute();
  $column_map = array(
    'nid' => 'nid',
  );

  // Test the history field.
  $view = views_get_view('test_history');
  $view
    ->setDisplay('page_1');
  $this
    ->executeView($view);
  $this
    ->assertEqual(count($view->result), 2);
  $output = $view
    ->preview();
  $this
    ->drupalSetContent(drupal_render($output));
  $result = $this
    ->xpath('//span[@class=:class]', array(
    ':class' => 'marker',
  ));
  $this
    ->assertEqual(count($result), 1, 'Just one node is marked as new');

  // Test the history filter.
  $view = views_get_view('test_history');
  $view
    ->setDisplay('page_2');
  $this
    ->executeView($view);
  $this
    ->assertEqual(count($view->result), 1);
  $this
    ->assertIdenticalResultset($view, array(
    array(
      'nid' => $nodes[0]
        ->id(),
    ),
  ), $column_map);
}