Namespace
Drupal\Tests\cron_example\Functional
File
-
modules/cron_example/tests/src/Functional/CronExampleTest.php
View source
<?php
namespace Drupal\Tests\cron_example\Functional;
use Drupal\Core\Url;
use Drupal\Tests\examples\Functional\ExamplesBrowserTestBase;
class CronExampleTest extends ExamplesBrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'cron_example',
'node',
];
protected function setUp() : void {
parent::setUp();
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
'access content',
]));
}
public function testCronExampleBasic() {
$assert = $this->assertSession();
$cron_form = Url::fromRoute('cron_example.description');
$this->container
->get('state')
->set('cron_example.next_execution', 0);
$this->drupalGet($cron_form);
$post = [];
$this->drupalGet($cron_form);
$this->submitForm($post, 'Run cron now');
$assert->pageTextContains('cron_example executed at');
$post['cron_reset'] = TRUE;
$this->submitForm($post, 'Run cron now');
$assert->pageTextContains('cron_example executed at');
$post['cron_reset'] = FALSE;
$this->submitForm($post, 'Run cron now');
$assert->statusCodeEquals(200);
$assert->pageTextNotContains('cron_example executed at');
$assert->pageTextContains('There are currently 0 items in queue 1 and 0 items in queue 2');
$post = [
'num_items' => 5,
'queue' => 'cron_example_queue_1',
];
$this->submitForm($post, 'Add jobs to queue');
$assert->pageTextContains('There are currently 5 items in queue 1 and 0 items in queue 2');
$post = [
'num_items' => 100,
'queue' => 'cron_example_queue_2',
];
$this->submitForm($post, 'Add jobs to queue');
$assert->pageTextContains('There are currently 5 items in queue 1 and 100 items in queue 2');
$this->drupalGet($cron_form);
$this->submitForm([], 'Run cron now');
$assert->responseMatches('/Queue 1 worker processed item with sequence 5 /');
$assert->responseMatches('/Queue 2 worker processed item with sequence 100 /');
}
}
Classes
| Title |
Deprecated |
Summary |
| CronExampleTest |
|
Test the functionality for the Cron Example. |