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

8.3.x
Alex Pott 2017-01-11 14:21:35 +00:00
parent fb3389418b
commit b8d54eea18
3 changed files with 34 additions and 7 deletions

View File

@ -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;
}
@ -1566,13 +1568,6 @@ abstract class WebTestBase extends TestBase {
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.
*

View File

@ -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);
}
}

View File

@ -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'));
}
}