From 5c832d2e3ee99ca0f9a4ec1aba15c3c9cbe1de0a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Mon, 13 Jan 2020 17:55:22 +0000
Subject: [PATCH] Issue #3102059 by alexpott, Berdir, longwave: Make tests of
 the update system use UpdatePathTestTrait instead of UpdatePathTestBase

---
 .../update/drupal-8.entity-test-initial.php   | 24 -------
 .../entity_test_update.info.yml               |  2 +
 .../Update/EntityUpdateInitialTest.php        | 40 +++++++++---
 .../UpdatePathWithBrokenRoutingFilledTest.php | 50 ---------------
 .../Update/ActiveWorkspaceUpdateTest.php      | 63 +++++++++++++++++++
 .../Update/WorkspacesUpdateTest.php           | 22 -------
 6 files changed, 97 insertions(+), 104 deletions(-)
 delete mode 100644 core/modules/system/tests/fixtures/update/drupal-8.entity-test-initial.php
 delete mode 100644 core/modules/system/tests/src/Functional/Update/UpdatePathWithBrokenRoutingFilledTest.php
 create mode 100644 core/modules/workspaces/tests/src/Functional/Update/ActiveWorkspaceUpdateTest.php

diff --git a/core/modules/system/tests/fixtures/update/drupal-8.entity-test-initial.php b/core/modules/system/tests/fixtures/update/drupal-8.entity-test-initial.php
deleted file mode 100644
index e7ab6961e647..000000000000
--- a/core/modules/system/tests/fixtures/update/drupal-8.entity-test-initial.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-// @codingStandardsIgnoreFile
-
-use Drupal\Core\Database\Database;
-
-$connection = Database::getConnection();
-
-// Simulate an entity type that had previously set an initial key schema for a
-// field.
-$schema = $connection->select('key_value')
-  ->fields('key_value', ['value'])
-  ->condition('collection', 'entity.storage_schema.sql')
-  ->condition('name', 'entity_test_update.field_schema_data.name')
-  ->execute()
-  ->fetchField();
-
-$schema = unserialize($schema);
-$schema['entity_test_update']['fields']['name']['initial'] = 'test';
-
-$connection->update('key_value')
-  ->fields(['value' => serialize($schema)])
-  ->condition('collection', 'entity.storage_schema.sql')
-  ->condition('name', 'entity_test_update.field_schema_data.name')
-  ->execute();
diff --git a/core/modules/system/tests/modules/entity_test_update/entity_test_update.info.yml b/core/modules/system/tests/modules/entity_test_update/entity_test_update.info.yml
index def242322ca3..3ae369e701a7 100644
--- a/core/modules/system/tests/modules/entity_test_update/entity_test_update.info.yml
+++ b/core/modules/system/tests/modules/entity_test_update/entity_test_update.info.yml
@@ -3,3 +3,5 @@ type: module
 description: 'Provides an entity type for testing definition and schema updates.'
 package: Testing
 version: VERSION
+dependencies:
+  - drupal:field
diff --git a/core/modules/system/tests/src/Functional/Update/EntityUpdateInitialTest.php b/core/modules/system/tests/src/Functional/Update/EntityUpdateInitialTest.php
index 1d9a698b1b44..338202609e3d 100644
--- a/core/modules/system/tests/src/Functional/Update/EntityUpdateInitialTest.php
+++ b/core/modules/system/tests/src/Functional/Update/EntityUpdateInitialTest.php
@@ -2,7 +2,9 @@
 
 namespace Drupal\Tests\system\Functional\Update;
 
-use Drupal\FunctionalTests\Update\UpdatePathTestBase;
+use Drupal\Core\Database\Database;
+use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\UpdatePathTestTrait;
 
 /**
  * Tests handling of existing initial keys during updates.
@@ -10,9 +12,9 @@
  * @see https://www.drupal.org/project/drupal/issues/2925550
  *
  * @group Update
- * @group legacy
  */
-class EntityUpdateInitialTest extends UpdatePathTestBase {
+class EntityUpdateInitialTest extends BrowserTestBase {
+  use UpdatePathTestTrait;
 
   /**
    * {@inheritdoc}
@@ -22,11 +24,33 @@ class EntityUpdateInitialTest extends UpdatePathTestBase {
   /**
    * {@inheritdoc}
    */
-  protected function setDatabaseDumpFiles() {
-    $this->databaseDumpFiles = [
-      __DIR__ . '/../../../fixtures/update/drupal-8.0.0-rc1-filled.standard.entity_test_update.php.gz',
-      __DIR__ . '/../../../fixtures/update/drupal-8.entity-test-initial.php',
-    ];
+  protected static $modules = ['entity_test_update'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->ensureUpdatesToRun();
+    $connection = Database::getConnection();
+
+    // Simulate an entity type that had previously set an initial key schema for
+    // a field.
+    $schema = $connection->select('key_value')
+      ->fields('key_value', ['value'])
+      ->condition('collection', 'entity.storage_schema.sql')
+      ->condition('name', 'entity_test_update.field_schema_data.name')
+      ->execute()
+      ->fetchField();
+
+    $schema = unserialize($schema);
+    $schema['entity_test_update']['fields']['name']['initial'] = 'test';
+
+    $connection->update('key_value')
+      ->fields(['value' => serialize($schema)])
+      ->condition('collection', 'entity.storage_schema.sql')
+      ->condition('name', 'entity_test_update.field_schema_data.name')
+      ->execute();
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Update/UpdatePathWithBrokenRoutingFilledTest.php b/core/modules/system/tests/src/Functional/Update/UpdatePathWithBrokenRoutingFilledTest.php
deleted file mode 100644
index 2f3287a3b3ce..000000000000
--- a/core/modules/system/tests/src/Functional/Update/UpdatePathWithBrokenRoutingFilledTest.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-
-namespace Drupal\Tests\system\Functional\Update;
-
-use Drupal\FunctionalTests\Update\UpdatePathTestBase;
-
-/**
- * Runs UpdatePathWithBrokenRoutingTest with a dump filled with content.
- *
- * @group Update
- * @group legacy
- */
-class UpdatePathWithBrokenRoutingFilledTest extends UpdatePathTestBase {
-
-  /**
-   * {@inheritdoc}
-   */
-  protected $defaultTheme = 'stark';
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function setDatabaseDumpFiles() {
-    $this->databaseDumpFiles = [
-      __DIR__ . '/../../../../tests/fixtures/update/drupal-8.8.0.filled.standard.php.gz',
-      __DIR__ . '/../../../../tests/fixtures/update/drupal-8.broken_routing.php',
-    ];
-  }
-
-  /**
-   * Tests running update.php with some form of broken routing.
-   */
-  public function testWithBrokenRouting() {
-    // Simulate a broken router, and make sure the front page is
-    // inaccessible.
-    \Drupal::state()->set('update_script_test_broken_inbound', TRUE);
-    \Drupal::service('cache_tags.invalidator')->invalidateTags(['route_match', 'rendered']);
-    $this->drupalGet('<front>');
-    $this->assertResponse(500);
-
-    $this->runUpdates();
-
-    // Remove the simulation of the broken router, and make sure we can get to
-    // the front page again.
-    \Drupal::state()->set('update_script_test_broken_inbound', FALSE);
-    $this->drupalGet('<front>');
-    $this->assertResponse(200);
-  }
-
-}
diff --git a/core/modules/workspaces/tests/src/Functional/Update/ActiveWorkspaceUpdateTest.php b/core/modules/workspaces/tests/src/Functional/Update/ActiveWorkspaceUpdateTest.php
new file mode 100644
index 000000000000..d61de4cfc83f
--- /dev/null
+++ b/core/modules/workspaces/tests/src/Functional/Update/ActiveWorkspaceUpdateTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Drupal\Tests\workspaces\Functional\Update;
+
+use Drupal\Tests\BrowserTestBase;
+use Drupal\Tests\UpdatePathTestTrait;
+
+/**
+ * Tests that there is no active workspace during database updates.
+ *
+ * @group workspaces
+ * @group Update
+ */
+class ActiveWorkspaceUpdateTest extends BrowserTestBase {
+  use UpdatePathTestTrait;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['workspaces', 'workspace_update_test'];
+
+  /**
+   * {@inheritdoc}
+   */
+  protected $defaultTheme = 'stark';
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    // Ensure the workspace_update_test_post_update_check_active_workspace()
+    // update runs.
+    $existing_updates = \Drupal::keyValue('post_update')->get('existing_updates', []);
+    $index = array_search('workspace_update_test_post_update_check_active_workspace', $existing_updates);
+    unset($existing_updates[$index]);
+    \Drupal::keyValue('post_update')->set('existing_updates', $existing_updates);
+  }
+
+  /**
+   * Tests that there is no active workspace during database updates.
+   */
+  public function testActiveWorkspaceDuringUpdate() {
+    /** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
+    $workspace_manager = \Drupal::service('workspaces.manager');
+
+    // Check that we have an active workspace before running the updates.
+    $this->assertTrue($workspace_manager->hasActiveWorkspace());
+    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
+
+    $this->runUpdates();
+
+    // Check that we didn't have an active workspace while running the updates.
+    // @see workspace_update_test_post_update_check_active_workspace()
+    $this->assertFalse(\Drupal::state()->get('workspace_update_test.has_active_workspace'));
+
+    // Check that we have an active workspace after running the updates.
+    $workspace_manager = \Drupal::service('workspaces.manager');
+    $this->assertTrue($workspace_manager->hasActiveWorkspace());
+    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
+  }
+
+}
diff --git a/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php
index 30062be1c7df..a518434163e3 100644
--- a/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php
+++ b/core/modules/workspaces/tests/src/Functional/Update/WorkspacesUpdateTest.php
@@ -127,28 +127,6 @@ public function testWorkspaceParentField() {
     $this->assertNull($form_display->getComponent('parent'));
   }
 
-  /**
-   * Tests that there is no active workspace during database updates.
-   */
-  public function testActiveWorkspaceDuringUpdate() {
-    /** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
-    $workspace_manager = \Drupal::service('workspaces.manager');
-
-    // Check that we have an active workspace before running the updates.
-    $this->assertTrue($workspace_manager->hasActiveWorkspace());
-    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
-
-    $this->runUpdates();
-
-    // Check that we didn't have an active workspace while running the updates.
-    // @see workspace_update_test_post_update_check_active_workspace()
-    $this->assertFalse(\Drupal::state()->get('workspace_update_test.has_active_workspace'));
-
-    // Check that we have an active workspace after running the updates.
-    $this->assertTrue($workspace_manager->hasActiveWorkspace());
-    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
-  }
-
   /**
    * {@inheritdoc}
    */
-- 
GitLab