diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index a7938657cc32c2ecf109426bf76241f3a111191a..c3098e16a890c172484286c72567be502620ae60 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -19,6 +19,7 @@ use Drupal\Core\Test\FunctionalTestSetupTrait; 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 Zend\Diactoros\Uri; @@ -43,6 +44,7 @@ abstract class WebTestBase extends TestBase { use ContentTypeCreationTrait { createContentType as drupalCreateContentType; } + use CronRunTrait; use AssertMailTrait { getMails as drupalGetMails; } @@ -1566,13 +1568,6 @@ protected function translatePostValues(array $values) { return $edit; } - /** - * 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. * diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index ef9c6b59ef64b04f878a90b6d3ac5e53e3407bef..7241fe4916473fdb8b824004b80fc19f5625e13d 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. * @@ -162,4 +165,16 @@ public function testLegacyXPathAsserts() { $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); } + /** + * 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/Traits/Core/CronRunTrait.php b/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..17ca9fcdb6f132a91b5c73d111db5124974caf71 --- /dev/null +++ b/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php @@ -0,0 +1,17 @@ +drupalGet('cron/' . \Drupal::state()->get('system.cron_key')); + } + +}