Commit b8d54eea authored by alexpott's avatar alexpott

Issue #2795037 by jhedstrom, shashikant_chauhan, gnuget, dawehner: BTB: Add cronRun function

parent fb338941
......@@ -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.
*
......
......@@ -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);
}
}
<?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'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment