You are here

public function TrackerUserUidTest::testUserUid in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php \Drupal\tracker\Tests\Views\TrackerUserUidTest::testUserUid()

Tests the user uid filter and argument.

File

core/modules/tracker/src/Tests/Views/TrackerUserUidTest.php, line 29
Contains \Drupal\tracker\Tests\Views\TrackerUserUidTest.

Class

TrackerUserUidTest
Tests the tracker user uid handlers.

Namespace

Drupal\tracker\Tests\Views

Code

public function testUserUid() {
  $map = array(
    'nid' => 'nid',
    'title' => 'title',
  );
  $expected = array(
    array(
      'nid' => $this->node
        ->id(),
      'title' => $this->node
        ->label(),
    ),
  );
  $view = Views::getView('test_tracker_user_uid');
  $this
    ->executeView($view);

  // We should have no results as the filter is set for uid 0.
  $this
    ->assertIdenticalResultSet($view, array(), $map);
  $view
    ->destroy();

  // Change the filter value to our user.
  $view
    ->initHandlers();
  $view->filter['uid_touch_tracker']->value = $this->node
    ->getOwnerId();
  $this
    ->executeView($view);

  // We should have one result as the filter is set for the created user.
  $this
    ->assertIdenticalResultSet($view, $expected, $map);
  $view
    ->destroy();

  // Remove the filter now, so only the argument will affect the query.
  $view
    ->removeHandler('default', 'filter', 'uid_touch_tracker');

  // Test the incorrect argument UID.
  $view
    ->initHandlers();
  $this
    ->executeView($view, array(
    rand(),
  ));
  $this
    ->assertIdenticalResultSet($view, array(), $map);
  $view
    ->destroy();

  // Test the correct argument UID.
  $view
    ->initHandlers();
  $this
    ->executeView($view, array(
    $this->node
      ->getOwnerId(),
  ));
  $this
    ->assertIdenticalResultSet($view, $expected, $map);
}