From c5e634873af03afd69aec1f0c7bb1a1196c6c954 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Sat, 3 Feb 2024 17:16:27 +0000 Subject: [PATCH] Issue #3416074 by catch, longwave: UpdatePathTestBaseFilledTest is mostly pointless --- .../src/Functional/ShortcutLinksTest.php | 1 + .../tests/src/Functional/Theme/ThemeTest.php | 1 + .../UpdatePathTestBaseFilledTest.php | 18 ++++-- .../tests/src/Functional/TermTest.php | 1 + .../Views/TaxonomyIndexTidUiTest.php | 1 + .../src/Functional/TelephoneFieldTest.php | 1 + .../tests/src/Functional/TextFieldTest.php | 1 + .../Update/UpdatePathTestBase.php | 55 +++++++++++++++++++ .../Update/UpdatePathTestBaseTest.php | 52 +----------------- 9 files changed, 76 insertions(+), 55 deletions(-) diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php index 4838b4b4d51f..7f652abc8808 100644 --- a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php @@ -15,6 +15,7 @@ * Create, view, edit, delete, and change shortcut links. * * @group shortcut + * @group #slow */ class ShortcutLinksTest extends ShortcutTestBase { diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeTest.php index 5d7162f0e3c8..aa517b52cae7 100644 --- a/core/modules/system/tests/src/Functional/Theme/ThemeTest.php +++ b/core/modules/system/tests/src/Functional/Theme/ThemeTest.php @@ -12,6 +12,7 @@ * Tests low-level theme functions. * * @group Theme + * @group #slow */ class ThemeTest extends BrowserTestBase { diff --git a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathTestBaseFilledTest.php b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathTestBaseFilledTest.php index d9653f20126d..b35d3574edf9 100644 --- a/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathTestBaseFilledTest.php +++ b/core/modules/system/tests/src/Functional/UpdateSystem/UpdatePathTestBaseFilledTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\system\Functional\UpdateSystem; -use Drupal\FunctionalTests\Update\UpdatePathTestBaseTest; +use Drupal\FunctionalTests\Update\UpdatePathTestBase; use Drupal\node\Entity\Node; use Drupal\node\Entity\NodeType; use Drupal\user\Entity\User; @@ -10,12 +10,12 @@ // cspell:ignore hola usuario /** - * Runs UpdatePathTestBaseTest with a dump filled with content. + * Runs UpdatePathTestBase with a dump filled with content. * * @group #slow * @group Update */ -class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest { +class UpdatePathTestBaseFilledTest extends UpdatePathTestBase { /** * {@inheritdoc} @@ -26,8 +26,9 @@ class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest { * {@inheritdoc} */ protected function setDatabaseDumpFiles() { - parent::setDatabaseDumpFiles(); - $this->databaseDumpFiles[0] = __DIR__ . '/../../../../tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz'; + $this->databaseDumpFiles[] = __DIR__ . '/../../../../tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz'; + $this->databaseDumpFiles[] = __DIR__ . '/../../../../tests/fixtures/update/drupal-8.update-test-schema-enabled.php'; + $this->databaseDumpFiles[] = __DIR__ . '/../../../../tests/fixtures/update/drupal-8.update-test-semver-update-n-enabled.php'; } /** @@ -417,4 +418,11 @@ protected function replaceUser1() { // Do not replace the user from our dump. } + /** + * Tests that the database was properly loaded. + */ + public function testDatabaseProperlyLoaded() { + $this->testDatabaseLoaded(); + } + } diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php index 0c7bf2f0dadf..c01b6e742507 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php @@ -13,6 +13,7 @@ * Tests load, save and delete for taxonomy terms. * * @group taxonomy + * @group #slow */ class TermTest extends TaxonomyTestBase { diff --git a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php index d0b2ae2a403e..7e49395d42a5 100644 --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyIndexTidUiTest.php @@ -13,6 +13,7 @@ * Tests the taxonomy index filter handler UI. * * @group taxonomy + * @group #slow * @see \Drupal\taxonomy\Plugin\views\field\TaxonomyIndexTid */ class TaxonomyIndexTidUiTest extends UITestBase { diff --git a/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php b/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php index 3c4e7506575f..6ef20bc9f062 100644 --- a/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php +++ b/core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php @@ -11,6 +11,7 @@ * Tests the creation of telephone fields. * * @group telephone + * @group #slow */ class TelephoneFieldTest extends BrowserTestBase { diff --git a/core/modules/text/tests/src/Functional/TextFieldTest.php b/core/modules/text/tests/src/Functional/TextFieldTest.php index 292e7d65273d..68d29bf2a767 100644 --- a/core/modules/text/tests/src/Functional/TextFieldTest.php +++ b/core/modules/text/tests/src/Functional/TextFieldTest.php @@ -15,6 +15,7 @@ * Tests the creation of text fields. * * @group text + * @group #slow */ class TextFieldTest extends StringFieldTest { diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index 1a57e5539a22..df09ec21954a 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -3,6 +3,7 @@ namespace Drupal\FunctionalTests\Update; use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\Html; use Drupal\Core\Site\Settings; use Drupal\Tests\BrowserTestBase; use Drupal\Core\Database\Database; @@ -241,4 +242,58 @@ protected function replaceUser1() { $account->save(); } + /** + * Tests that the database was properly loaded. + */ + protected function testDatabaseLoaded() { + // Set a value in the cache to prove caches are cleared. + \Drupal::service('cache.default')->set(__CLASS__, 'Test'); + + /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ + $update_registry = \Drupal::service('update.update_hook_registry'); + foreach (['user' => 9301, 'node' => 8700, 'system' => 8901, 'update_test_schema' => 8000] as $module => $schema) { + $this->assertEquals($schema, $update_registry->getInstalledVersion($module), "Module $module schema is $schema"); + } + + // Ensure that all {router} entries can be unserialized. If they cannot be + // unserialized a notice will be thrown by PHP. + + $result = \Drupal::database()->select('router', 'r') + ->fields('r', ['name', 'route']) + ->execute() + ->fetchAllKeyed(0, 1); + // For the purpose of fetching the notices and displaying more helpful error + // messages, let's override the error handler temporarily. + set_error_handler(function ($severity, $message, $filename, $lineno) { + throw new \ErrorException($message, 0, $severity, $filename, $lineno); + }); + foreach ($result as $route_name => $route) { + try { + unserialize($route); + } + catch (\Exception $e) { + $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name))); + } + } + restore_error_handler(); + + // Before accessing the site we need to run updates first or the site might + // be broken. + $this->runUpdates(); + $this->assertEquals('standard', \Drupal::config('core.extension')->get('profile')); + $this->assertEquals('Site-Install', \Drupal::config('system.site')->get('name')); + $this->drupalGet('<front>'); + $this->assertSession()->pageTextContains('Site-Install'); + + // Ensure that the database tasks have been run during set up. Neither MySQL + // nor SQLite make changes that are testable. + $database = $this->container->get('database'); + if ($database->driver() == 'pgsql') { + $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField()); + $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField()); + } + // Ensure the test runners cache has been cleared. + $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); + } + } diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php index 053b88ee13e2..c6a6874fe1d0 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBaseTest.php @@ -2,7 +2,6 @@ namespace Drupal\FunctionalTests\Update; -use Drupal\Component\Utility\Html; use Drupal\Core\Database\Database; use Drupal\Core\Site\Settings; @@ -31,55 +30,8 @@ protected function setDatabaseDumpFiles() { /** * Tests that the database was properly loaded. */ - public function testDatabaseLoaded() { - // Set a value in the cache to prove caches are cleared. - \Drupal::service('cache.default')->set(__CLASS__, 'Test'); - - /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ - $update_registry = \Drupal::service('update.update_hook_registry'); - foreach (['user' => 9301, 'node' => 8700, 'system' => 8901, 'update_test_schema' => 8000] as $module => $schema) { - $this->assertEquals($schema, $update_registry->getInstalledVersion($module), "Module $module schema is $schema"); - } - - // Ensure that all {router} entries can be unserialized. If they cannot be - // unserialized a notice will be thrown by PHP. - - $result = \Drupal::database()->select('router', 'r') - ->fields('r', ['name', 'route']) - ->execute() - ->fetchAllKeyed(0, 1); - // For the purpose of fetching the notices and displaying more helpful error - // messages, let's override the error handler temporarily. - set_error_handler(function ($severity, $message, $filename, $lineno) { - throw new \ErrorException($message, 0, $severity, $filename, $lineno); - }); - foreach ($result as $route_name => $route) { - try { - unserialize($route); - } - catch (\Exception $e) { - $this->fail(sprintf('Error "%s" while unserializing route %s', $e->getMessage(), Html::escape($route_name))); - } - } - restore_error_handler(); - - // Before accessing the site we need to run updates first or the site might - // be broken. - $this->runUpdates(); - $this->assertEquals('standard', \Drupal::config('core.extension')->get('profile')); - $this->assertEquals('Site-Install', \Drupal::config('system.site')->get('name')); - $this->drupalGet('<front>'); - $this->assertSession()->pageTextContains('Site-Install'); - - // Ensure that the database tasks have been run during set up. Neither MySQL - // nor SQLite make changes that are testable. - $database = $this->container->get('database'); - if ($database->driver() == 'pgsql') { - $this->assertEquals('on', $database->query("SHOW standard_conforming_strings")->fetchField()); - $this->assertEquals('escape', $database->query("SHOW bytea_output")->fetchField()); - } - // Ensure the test runners cache has been cleared. - $this->assertFalse(\Drupal::service('cache.default')->get(__CLASS__)); + public function testDatabaseProperlyLoaded() { + $this->testDatabaseLoaded(); } /** -- GitLab