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 43f48a1e44ab60f426d76ad7bd831881aef20329..ab2f30b5449018718afb93b637a25f91720576b4 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 f046621d01da80efa22c1eeb890395cdcc180e73..e2475c3237afea5e13262d75d632a4f548658bee 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 d32e1ab66ab6cc6889cccfdd1eddd98d50c8a608..31fcb066aa1b6210a53d67f585b17f7f6aa68934 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; } /**