diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 9d2bf6a..dfe2b32 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -26,6 +26,7 @@ use Drupal\Core\Test\AssertMailTrait; use Drupal\Core\Url; use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; +use Drupal\Tests\Traits\Core\CronRunTrait; use Drupal\Tests\TestFileCreationTrait; use Drupal\Tests\XdebugRequestTrait; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -52,6 +53,7 @@ use ContentTypeCreationTrait { createContentType as drupalCreateContentType; } + use CronRunTrait; use AssertMailTrait { getMails as drupalGetMails; } @@ -1953,13 +1955,6 @@ protected function translatePostValues(array $values) { } /** - * Runs cron in the Drupal installed by Simpletest. - */ - protected function cronRun() { - $this->drupalGet('cron/' . \Drupal::state()->get('system.cron_key')); - } - - /** * Checks for meta refresh tag and if found call drupalGet() recursively. * * This function looks for the http-equiv attribute to be set to "Refresh" and diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index eb315af..17ea731 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\Traits\Core\CronRunTrait; /** * Tests BrowserTestBase functionality. @@ -13,6 +14,8 @@ */ class BrowserTestBaseTest extends BrowserTestBase { + use CronRunTrait; + /** * Modules to enable. * @@ -144,4 +147,16 @@ public function testLegacyAsserts() { $this->assertText($sanitized); } + /** + * Tests the ::cronRun() method. + */ + public function testCronRun() { + $last_cron_time = \Drupal::state()->get('system.cron_last'); + $this->cronRun(); + $this->assertSession()->statusCodeEquals(204); + $next_cron_time = \Drupal::state()->get('system.cron_last'); + + $this->assertGreaterThan($last_cron_time, $next_cron_time); + } + } diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 5d9af8e..1768c17 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -32,6 +32,7 @@ use Drupal\simpletest\BlockCreationTrait; use Drupal\simpletest\NodeCreationTrait; use Drupal\simpletest\UserCreationTrait; +use Drupal\Tests\Traits\Core\CronRunTrait; use Symfony\Component\CssSelector\CssSelectorConverter; use Symfony\Component\HttpFoundation\Request; use Psr\Http\Message\RequestInterface; diff --git a/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php b/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php new file mode 100644 index 0000000..17ca9fc --- /dev/null +++ b/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php @@ -0,0 +1,17 @@ +drupalGet('cron/' . \Drupal::state()->get('system.cron_key')); + } + +}