View source
<?php
namespace Drupal\Tests\tracker\Kernel\Views;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\views\Tests\ViewResultAssertionTrait;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
class TrackerUserUidTest extends KernelTestBase {
use NodeCreationTrait;
use UserCreationTrait;
use ViewResultAssertionTrait;
protected static $modules = [
'filter',
'node',
'system',
'tracker',
'tracker_test_views',
'user',
'views',
];
public static $testViews = [
'test_tracker_user_uid',
];
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();
$this
->assertIdenticalResultSet($view, [], $map);
$view
->destroy();
$view
->initHandlers();
$view->filter['uid_touch_tracker']->value = $node
->getOwnerId();
$view
->preview();
$this
->assertIdenticalResultSet($view, $expected, $map);
$view
->destroy();
$view
->removeHandler('default', 'filter', 'uid_touch_tracker');
$view
->initHandlers();
$view
->preview(NULL, [
rand(),
]);
$this
->assertIdenticalResultSet($view, [], $map);
$view
->destroy();
$view
->initHandlers();
$view
->preview(NULL, [
$node
->getOwnerId(),
]);
$this
->assertIdenticalResultSet($view, $expected, $map);
}
}