You are here

CronKeyCangeTest.php in Cron key change 8

Same filename and directory in other branches
  1. 2.x tests/src/Functional/CronKeyCangeTest.php

File

tests/src/Functional/CronKeyCangeTest.php
View source
<?php

namespace Drupal\Tests\cronkeychange\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests the change cron key.
 *
 * @group cronkeychange
 */
class CronKeyCangeTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'cronkeychange',
  ];

  /**
   * The user for the test.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * Set up a privileged user.
   */
  public function setUp() : void {
    parent::setUp();

    // Create and log in our privileged user.
    $this->adminUser = $this
      ->drupalCreateUser([
      'administer site configuration',
    ]);
    $this
      ->drupalLogin($this->adminUser);
  }

  /**
   * Tests the change cron key.
   */
  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.');
  }

}

Classes

Namesort descending Description
CronKeyCangeTest Tests the change cron key.