Unverified Commit 34434ccc authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3046937 by claudiu.cristea, naveenvalecha: Convert TrackerUserUidTest into a Kernel test.

parent 2cdefde1
Loading
Loading
Loading
Loading
+40 −9
Changes for core/modules/tracker/tests/src/Kernel/Views/TrackerUserUidTest.php: 40 added lines, 9 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\tracker\Functional\Views;
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;

/**
@@ -9,7 +14,24 @@
 *
 * @group tracker
 */
class TrackerUserUidTest extends TrackerTestBase {
class TrackerUserUidTest extends KernelTestBase {

  use NodeCreationTrait;
  use UserCreationTrait;
  use ViewResultAssertionTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'filter',
    'node',
    'system',
    'tracker',
    'tracker_test_views',
    'user',
    'views',
  ];

  /**
   * Views used by this test.
@@ -22,6 +44,15 @@ class TrackerUserUidTest extends TrackerTestBase {
   * Tests the user uid filter and argument.
   */
  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',
@@ -29,13 +60,13 @@ public function testUserUid() {

    $expected = [
      [
        'nid' => $this->node->id(),
        'title' => $this->node->label(),
        'nid' => $node->id(),
        'title' => $node->label(),
      ],
    ];

    $view = Views::getView('test_tracker_user_uid');
    $this->executeView($view);
    $view->preview();

    // We should have no results as the filter is set for uid 0.
    $this->assertIdenticalResultSet($view, [], $map);
@@ -43,8 +74,8 @@ public function testUserUid() {

    // Change the filter value to our user.
    $view->initHandlers();
    $view->filter['uid_touch_tracker']->value = $this->node->getOwnerId();
    $this->executeView($view);
    $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);
@@ -55,13 +86,13 @@ public function testUserUid() {

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

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