public function TrackerUserUidTest::testUserUid

Tests the user uid filter and argument.

File

drupal/core/modules/tracker/lib/Drupal/tracker/Tests/Views/TrackerUserUidTest.php, line 33
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',
    'node_field_data_title' => 'title',
  );
  $expected = array(
    array(
      'nid' => $this->node
        ->id(),
      'title' => $this->node
        ->label(),
    ),
  );
  $view = views_get_view('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->uid;
  $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
    ->removeItem('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->uid,
  ));
  $this
    ->assertIdenticalResultSet($view, $expected, $map);
}