From a9046450f2719a66197a99d5036f845c5b1a69cc Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Tue, 6 Feb 2024 10:15:02 +0000 Subject: [PATCH] Issue #3082211 by quietone, Pooja Ganjage, smustgrave, danflanagan8, Spokje, benjifisher, mikelutz, Wim Leers: Migrate UI upgrade tests should provide the complete log --- .../MigrateUpgradeExecuteTestBase.php | 64 +++++++++++++++++++ .../tests/src/Functional/d6/Upgrade6Test.php | 5 ++ .../tests/src/Functional/d7/Upgrade7Test.php | 5 ++ 3 files changed, 74 insertions(+) diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php index 43f48a1e44ab..ab2f30b54490 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\migrate_drupal_ui\Functional; use Drupal\Core\Entity\ContentEntityStorageInterface; +use Drupal\Core\Logger\RfcLogLevel; use Drupal\Tests\migrate_drupal\Traits\CreateTestContentEntitiesTrait; /** @@ -12,6 +13,27 @@ abstract class MigrateUpgradeExecuteTestBase extends MigrateUpgradeTestBase { use CreateTestContentEntitiesTrait; + /** + * Indicates if the watchdog logs should be output. + * + * @var bool + */ + protected bool $outputLogs = FALSE; + + /** + * The admin username after the migration. + * + * @var string + */ + protected string $migratedAdminUserName = 'admin'; + + /** + * The number of expected logged errors of type migrate_drupal_ui. + * + * @var int + */ + protected int $expectedLoggedErrors = 0; + /** * {@inheritdoc} */ @@ -23,6 +45,17 @@ protected function setUp(): void { } + /** + * {@inheritdoc} + */ + protected function tearDown(): void { + if ($this->outputLogs) { + $this->outputLogs($this->migratedAdminUserName); + $this->assertLogError(); + } + parent::tearDown(); + } + /** * Executes an upgrade and then an incremental upgrade. */ @@ -108,4 +141,35 @@ protected function assertEntityRevisionsCount(string $content_entity_type_id, in ); } + /** + * Asserts log errors. + */ + public function assertLogError(): void { + $db = \Drupal::service('database'); + $num_errors = $db->select('watchdog', 'w') + ->fields('w') + ->condition('type', 'migrate_drupal_ui') + ->condition('severity', RfcLogLevel::ERROR) + ->countQuery() + ->execute() + ->fetchField(); + $this->assertSame($this->expectedLoggedErrors, (int) $num_errors); + } + + /** + * Preserve the logs pages. + */ + public function outputLogs(string $username): void { + // Ensure user 1 is accessing the admin log. Change the username because + // the migration changes the username of user 1 but not the password. + if (\Drupal::currentUser()->id() != 1) { + $this->rootUser->name = $username; + $this->drupalLogin($this->rootUser); + } + $this->drupalGet('/admin/reports/dblog'); + while ($next_link = $this->getSession()->getPage()->findLink('Next page')) { + $next_link->click(); + } + } + } diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/Upgrade6Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/Upgrade6Test.php index f046621d01da..e2475c3237af 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d6/Upgrade6Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/Upgrade6Test.php @@ -51,6 +51,11 @@ protected function setUp(): void { $this->nodeStorage->delete($this->nodeStorage->loadMultiple()); $this->loadFixture($this->getModulePath('migrate_drupal') . '/tests/fixtures/drupal6.php'); + + // Enable saving the logs and set the post migration admin user name. + $this->outputLogs = TRUE; + $this->migratedAdminUserName = 'root'; + $this->expectedLoggedErrors = 39; } /** diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php index d32e1ab66ab6..31fcb066aa1b 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php @@ -54,6 +54,11 @@ protected function setUp(): void { $this->nodeStorage->delete($this->nodeStorage->loadMultiple()); $this->loadFixture($this->getModulePath('migrate_drupal') . '/tests/fixtures/drupal7.php'); + + // Enable saving the logs and set the post migration admin user name. + $this->outputLogs = TRUE; + $this->migratedAdminUserName = 'admin'; + $this->expectedLoggedErrors = 27; } /** -- GitLab