diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index aef1c89..1ca4c1a 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -9,6 +9,7 @@ use Drupal\dblog\Controller\DbLogController; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\Traits\Core\CronRunTrait; +use Drupal\Tests\Traits\Core\MetaRefreshTrait; /** * Generate events and verify dblog entries; verify user access to log reports @@ -18,6 +19,7 @@ */ class DbLogTest extends BrowserTestBase { use CronRunTrait; + use MetaRefreshTrait; /** * Modules to enable. @@ -406,6 +408,9 @@ private function doUser() { // Delete the user created at the start of this test. // We need to POST here to invoke batch_process() in the internal browser. $this->drupalPostForm('user/' . $user->id() . '/cancel', ['user_cancel_method' => 'user_cancel_reassign'], t('Cancel account')); + while ($this->checkForMetaRefresh()) { + // While until batch proccess ends. + } // View the database log report. $this->drupalGet('admin/reports/dblog'); @@ -428,16 +433,13 @@ private function doUser() { if ($links = $this->xpath('//a[text()="' . $message_text . '"]')) { // Found link with the message text. $links = array_shift($links); - foreach ($links->attributes() as $attr => $value) { - if ($attr == 'href') { - // Extract link to details page. - $link = Unicode::substr($value, strpos($value, 'admin/reports/dblog/event/')); - $this->drupalGet($link); - // Check for full message text on the details page. - $this->assertRaw($message, 'DBLog event details was found: [delete user]'); - break; - } - } + $value = $links->getAttribute('href'); + + // Extract link to details page. + $link = Unicode::substr($value, strpos($value, 'admin/reports/dblog/event/')); + $this->drupalGet($link); + // Check for full message text on the details page. + $this->assertRaw($message, 'DBLog event details was found: [delete user]'); } $this->assertTrue($link, 'DBLog event was recorded: [delete user]'); // Visit random URL (to generate page not found event). diff --git a/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php b/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php new file mode 100644 index 0000000..b891ec2 --- /dev/null +++ b/core/tests/Drupal/Tests/Traits/Core/MetaRefreshTrait.php @@ -0,0 +1,48 @@ +cssSelect('meta[http-equiv="Refresh"]'); + if (!empty($refresh) && (!isset($this->maximumMetaRefreshCount) || $this->metaRefreshCount < $this->maximumMetaRefreshCount)) { + // Parse the content attribute of the meta tag for the format: + // "[delay]: URL=[page_to_redirect_to]". + if (preg_match('/\d+;\s*URL=(?.*)/i', $refresh[0]->getAttribute('content'), $match)) { + $this->metaRefreshCount++; + return $this->drupalGet($this->getAbsoluteUrl(Html::decodeEntities($match['url']))); + } + } + return FALSE; + } + +}