public function SchedulerLightweightCronTest::testLightweightCronSettingsForm in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerLightweightCronTest.php \Drupal\Tests\scheduler\Functional\SchedulerLightweightCronTest::testLightweightCronSettingsForm()
Test the lightweight cron settings form.
File
- tests/
src/ Functional/ SchedulerLightweightCronTest.php, line 50
Class
- SchedulerLightweightCronTest
- Tests the Scheduler lightweight cron urls and admin form.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testLightweightCronSettingsForm() {
// Log in.
$this
->drupalLogin($this->adminUser);
// Check that the cron key has an initial value, created during install.
$this
->drupalGet($this->routeCronForm);
$key_xpath = $this
->xpath('//input[@id="edit-lightweight-access-key"]/@value');
$key = $key_xpath[0]
->getText();
$this
->assertNotEmpty($key, 'The default lightweight cron key field should not be empty');
$this
->assertEquals(20, strlen($key), 'The default lightweight cron key string length should be 20');
// Check that a new random key can be generated.
$this
->drupalGet($this->routeCronForm);
$this
->submitForm([], 'Generate new random key');
$new_key_xpath = $this
->xpath('//input[@id="edit-lightweight-access-key"]/@value');
$new_key = $new_key_xpath[0]
->getText();
$this
->assertNotEmpty($new_key, 'The lightweight cron key field should not be empty after generating a new key');
$this
->assertEquals(20, strlen($new_key), 'The new lightweight cron key string length should be 20');
$this
->assertNotEquals($new_key, $key, 'The new lightweight cron key should be different from the previous key.');
// Check that the 'run lightweight cron' button works.
$this
->drupalGet($this->routeCronForm);
$this
->submitForm([], "Run Scheduler's lightweight cron now");
$this
->assertSession()
->pageTextContains('Lightweight cron run completed.');
// Check that the form cannot be saved if the cron key is blank.
$this
->drupalGet($this->routeCronForm);
$this
->submitForm([
'lightweight_access_key' => '',
], 'Save configuration');
$this
->assertSession()
->pageTextContains('Lightweight cron access key field is required.');
$this
->assertSession()
->pageTextNotContains('The configuration options have been saved.');
}