CronKeyCangeTest.php in Cron key change 8
File
tests/src/Functional/CronKeyCangeTest.php
View source
<?php
namespace Drupal\Tests\cronkeychange\Functional;
use Drupal\Tests\BrowserTestBase;
class CronKeyCangeTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'cronkeychange',
];
protected $adminUser;
public function setUp() : void {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($this->adminUser);
}
public function testCronKeyChange() {
$original_cron_key = \Drupal::state()
->get('system.cron_key');
$this
->drupalGet('/admin/config/system/cron');
$visible_cron_key = trim($this
->getSession()
->getPage()
->find('xpath', '//*[@id="edit-current"]/text()[2]')
->getText());
$this
->assertEquals($original_cron_key, $visible_cron_key, 'Original value show correctly.');
$this
->drupalPostForm('admin/config/system/cron', [], t('Generate new key'));
$visible_cron_key = trim($this
->getSession()
->getPage()
->find('xpath', '//*[@id="edit-current"]/text()[2]')
->getText());
$this
->assertNotSame($visible_cron_key, '', 'Generated cron key is not null.');
$this
->assertNotEquals($original_cron_key, $visible_cron_key, 'Cron key is changed.');
}
}