From 33bbfa4f32c3afa80578093981006b811c63e65c Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 2 Apr 2019 09:49:48 +0100
Subject: [PATCH] Issue #3041786 by claudiu.cristea, Lendude: Convert
 LatestRevisionFilterTest to a kernel test

(cherry picked from commit 1cb3315fdabceadd21a39496c7c88909fc262083)
---
 .../Entity/LatestRevisionFilterTest.php       | 85 +++++++------------
 1 file changed, 31 insertions(+), 54 deletions(-)
 rename core/modules/views/tests/src/{Functional => Kernel}/Entity/LatestRevisionFilterTest.php (59%)

diff --git a/core/modules/views/tests/src/Functional/Entity/LatestRevisionFilterTest.php b/core/modules/views/tests/src/Kernel/Entity/LatestRevisionFilterTest.php
similarity index 59%
rename from core/modules/views/tests/src/Functional/Entity/LatestRevisionFilterTest.php
rename to core/modules/views/tests/src/Kernel/Entity/LatestRevisionFilterTest.php
index d73a11793bc2..54e95283f46e 100644
--- a/core/modules/views/tests/src/Functional/Entity/LatestRevisionFilterTest.php
+++ b/core/modules/views/tests/src/Kernel/Entity/LatestRevisionFilterTest.php
@@ -1,9 +1,10 @@
 <?php
 
-namespace Drupal\Tests\views\Functional\Entity;
+namespace Drupal\Tests\views\Kernel\Entity;
 
 use Drupal\node\Entity\Node;
-use Drupal\Tests\views\Functional\ViewTestBase;
+use Drupal\node\Entity\NodeType;
+use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
 use Drupal\views\ViewExecutable;
 use Drupal\views\Views;
 
@@ -12,43 +13,26 @@
  *
  * @group views
  */
-class LatestRevisionFilterTest extends ViewTestBase {
+class LatestRevisionFilterTest extends ViewsKernelTestBase {
 
   /**
-   * An array of node revisions.
-   *
-   * @var \Drupal\node\NodeInterface[]
-   */
-  protected $allRevisions = [];
-
-  /**
-   * An array of node revisions.
-   *
-   * @var \Drupal\node\NodeInterface[]
-   */
-  protected $latestRevisions = [];
-
-  /**
-   * Views used by this test.
-   *
-   * @var array
+   * {@inheritdoc}
    */
   public static $testViews = ['test_latest_revision_filter'];
 
   /**
-   * Modules to enable.
-   *
-   * @var array
+   * {@inheritdoc}
    */
   public static $modules = ['node'];
 
   /**
-   * {@inheritdoc}
+   * Tests the 'Latest revision' filter.
    */
-  protected function setUp($import_test_views = TRUE) {
-    parent::setUp();
-
-    $this->drupalCreateContentType(['type' => 'article']);
+  public function testLatestRevisionFilter() {
+    $this->installEntitySchema('user');
+    $this->installEntitySchema('node');
+    $this->installSchema('node', ['node_access']);
+    NodeType::create(['type' => 'article'])->save();
 
     // Create a node that goes through various default/pending revision stages.
     $node = Node::create([
@@ -56,26 +40,26 @@ protected function setUp($import_test_views = TRUE) {
       'type' => 'article',
     ]);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
 
     $node->setTitle('First node - v2 - pending');
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(FALSE);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
 
     $node->setTitle('First node - v3 - default');
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(TRUE);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
 
     $node->setTitle('First node - v4 - pending');
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(TRUE);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
-    $this->latestRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
+    $latest_revisions[$node->getRevisionId()] = $node;
 
     // Create a node that has a default and a pending revision.
     $node = Node::create([
@@ -83,14 +67,14 @@ protected function setUp($import_test_views = TRUE) {
       'type' => 'article',
     ]);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
 
     $node->setTitle('Second node - v2 - pending');
     $node->setNewRevision(TRUE);
     $node->isDefaultRevision(FALSE);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
-    $this->latestRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
+    $latest_revisions[$node->getRevisionId()] = $node;
 
     // Create a node that only has a default revision.
     $node = Node::create([
@@ -98,8 +82,8 @@ protected function setUp($import_test_views = TRUE) {
       'type' => 'article',
     ]);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
-    $this->latestRevisions[$node->getRevisionId()] = $node;
+    $all_revisions[$node->getRevisionId()] = $node;
+    $latest_revisions[$node->getRevisionId()] = $node;
 
     // Create a node that only has a pending revision.
     $node = Node::create([
@@ -108,24 +92,19 @@ protected function setUp($import_test_views = TRUE) {
     ]);
     $node->isDefaultRevision(FALSE);
     $node->save();
-    $this->allRevisions[$node->getRevisionId()] = $node;
-    $this->latestRevisions[$node->getRevisionId()] = $node;
-  }
+    $all_revisions[$node->getRevisionId()] = $node;
+    $latest_revisions[$node->getRevisionId()] = $node;
 
-  /**
-   * Tests the 'Latest revision' filter.
-   */
-  public function testLatestRevisionFilter() {
     $view = Views::getView('test_latest_revision_filter');
 
     $this->executeView($view);
 
     // Check that we have all the results.
-    $this->assertCount(count($this->latestRevisions), $view->result);
+    $this->assertCount(count($latest_revisions), $view->result);
 
     $expected = $not_expected = [];
-    foreach ($this->allRevisions as $revision_id => $revision) {
-      if (isset($this->latestRevisions[$revision_id])) {
+    foreach ($all_revisions as $revision_id => $revision) {
+      if (isset($latest_revisions[$revision_id])) {
         $expected[] = [
           'vid' => $revision_id,
           'title' => $revision->label(),
@@ -136,25 +115,23 @@ public function testLatestRevisionFilter() {
       }
     }
     $this->assertIdenticalResultset($view, $expected, ['vid' => 'vid', 'title' => 'title'], 'The test view only shows the latest revisions.');
-    $this->assertNotInResultSet($view, $not_expected, 'Non-latest revisions are not shown by the view.');
+    $this->assertNotInResultSet($view, $not_expected);
     $view->destroy();
   }
 
   /**
-   * Verifies that a list of revision IDs are not in the result.
+   * Asserts that a list of revision IDs are not in the result.
    *
    * @param \Drupal\views\ViewExecutable $view
    *   An executed View.
    * @param array $not_expected_revision_ids
    *   An array of revision IDs which should not be part of the result set.
-   * @param string $message
-   *   (optional) A custom message to display with the assertion.
    */
-  protected function assertNotInResultSet(ViewExecutable $view, array $not_expected_revision_ids, $message = '') {
+  protected function assertNotInResultSet(ViewExecutable $view, array $not_expected_revision_ids) {
     $found_revision_ids = array_filter($view->result, function ($row) use ($not_expected_revision_ids) {
       return in_array($row->vid, $not_expected_revision_ids);
     });
-    $this->assertFalse($found_revision_ids, $message);
+    $this->assertFalse($found_revision_ids);
   }
 
 }
-- 
GitLab