summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-01-11 14:21:35 (GMT)
committerAlex Pott2017-01-11 14:21:35 (GMT)
commitb8d54eea186fc03ab4658c6330cf5e4eb2f9c52c (patch)
tree39702f11f1aad234aeade8fc3be4e65cd0d0311f
parentfb3389418b5703001ef374c84b65b200da84930d (diff)
Issue #2795037 by jhedstrom, shashikant_chauhan, gnuget, dawehner: BTB: Add cronRun function
-rw-r--r--core/modules/simpletest/src/WebTestBase.php9
-rw-r--r--core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php15
-rw-r--r--core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php17
3 files changed, 34 insertions, 7 deletions
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index a793865..c3098e1 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -19,6 +19,7 @@ use Drupal\Core\Test\AssertMailTrait;
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;
}
@@ -1567,13 +1569,6 @@ abstract class WebTestBase extends TestBase {
}
/**
- * 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 ef9c6b5..7241fe4 100644
--- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -5,6 +5,7 @@ namespace Drupal\FunctionalTests;
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 @@ use Drupal\Tests\BrowserTestBase;
*/
class BrowserTestBaseTest extends BrowserTestBase {
+ use CronRunTrait;
+
/**
* Modules to enable.
*
@@ -162,4 +165,16 @@ class BrowserTestBaseTest extends BrowserTestBase {
$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 0000000..17ca9fc
--- /dev/null
+++ b/core/tests/Drupal/Tests/Traits/Core/CronRunTrait.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Drupal\Tests\Traits\Core;
+
+/**
+ * Adds ability to run cron from tests.
+ */
+trait CronRunTrait {
+
+ /**
+ * Runs cron on the test site.
+ */
+ protected function cronRun() {
+ $this->drupalGet('cron/' . \Drupal::state()->get('system.cron_key'));
+ }
+
+}