function TrackerUserUidTest::testUserUid
Same name in other branches
- 8.9.x core/modules/tracker/tests/src/Kernel/Views/TrackerUserUidTest.php \Drupal\Tests\tracker\Kernel\Views\TrackerUserUidTest::testUserUid()
- 10 core/modules/tracker/tests/src/Kernel/Views/TrackerUserUidTest.php \Drupal\Tests\tracker\Kernel\Views\TrackerUserUidTest::testUserUid()
- 11.x core/modules/tracker/tests/src/Kernel/Views/TrackerUserUidTest.php \Drupal\Tests\tracker\Kernel\Views\TrackerUserUidTest::testUserUid()
Tests the user uid filter and argument.
File
-
core/
modules/ tracker/ tests/ src/ Kernel/ Views/ TrackerUserUidTest.php, line 46
Class
- TrackerUserUidTest
- Tests the tracker user uid handlers.
Namespace
Drupal\Tests\tracker\Kernel\ViewsCode
public function testUserUid() {
$this->installSchema('system', [
'sequences',
]);
$this->installConfig([
'filter',
]);
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installSchema('tracker', [
'tracker_node',
'tracker_user',
]);
ViewTestData::createTestViews(static::class, [
'tracker_test_views',
]);
$node = $this->createNode();
$map = [
'nid' => 'nid',
'title' => 'title',
];
$expected = [
[
'nid' => $node->id(),
'title' => $node->label(),
],
];
$view = Views::getView('test_tracker_user_uid');
$view->preview();
// We should have no results as the filter is set for uid 0.
$this->assertIdenticalResultSet($view, [], $map);
$view->destroy();
// Change the filter value to our user.
$view->initHandlers();
$view->filter['uid_touch_tracker']->value = $node->getOwnerId();
$view->preview();
// 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();
$view->preview(NULL, [
rand(),
]);
$this->assertIdenticalResultSet($view, [], $map);
$view->destroy();
// Test the correct argument UID.
$view->initHandlers();
$view->preview(NULL, [
$node->getOwnerId(),
]);
$this->assertIdenticalResultSet($view, $expected, $map);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.