Commit 5c080bcc authored by Florian Weber's avatar Florian Weber Committed by Florian Weber
Browse files

Issue #3287690 by Project Update Bot, webflo: Automated Drupal 10 compatibility fixes

parent 1f2e49e6
Loading
Loading
Loading
Loading
+26 −24
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
   *
   * @var array
   */
  public static $modules = ['friendlycaptcha', 'captcha'];
  protected static $modules = ['friendlycaptcha', 'captcha'];

  /**
   * {@inheritdoc}
@@ -45,9 +45,9 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();
    module_load_include('inc', 'captcha');
    \Drupal::moduleHandler()->loadInclude('captcha', 'inc');

    // Create a normal user.
    $permissions = [
@@ -60,7 +60,6 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
      'administer CAPTCHA settings',
      'skip CAPTCHA',
      'administer permissions',
      'administer content types',
      'administer friendlycaptcha',
    ];
    $this->adminUser = $this->drupalCreateUser($permissions);
@@ -94,7 +93,7 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
  public function testFriendlycaptchaSettingsAdminAccess() {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/config/people/captcha/friendlycaptcha');
    $this->assertSession()->pageTextNotContains($this->t('Access denied'), 'Admin users should be able to access the Friendlycaptcha admin page', 'Friendlycaptcha');
    $this->assertSession()->pageTextNotContains($this->t('Access denied'));
    $this->drupalLogout();
  }

@@ -111,21 +110,23 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
    // Check form validation.
    $edit['friendlycaptcha_site_key'] = '';
    $edit['friendlycaptcha_api_key'] = '';
    $this->drupalPostForm('admin/config/people/captcha/friendlycaptcha', $edit, $this->t('Save configuration'));
    $this->drupalGet('admin/config/people/captcha/friendlycaptcha');
    $this->submitForm($edit, $this->t('Save configuration'));

    $this->assertSession()->responseContains($this->t('Site key field is required.'), '[testFriendlycaptchaAdminSettingsForm]: Empty site key detected.');
    $this->assertSession()->responseContains($this->t('API key field is required.'), '[testFriendlycaptchaAdminSettingsForm]: Empty api key detected.');
    $this->assertSession()->responseContains($this->t('Site key field is required.'));
    $this->assertSession()->responseContains($this->t('API key field is required.'));

    // Save form with valid values.
    $edit['friendlycaptcha_site_key'] = $site_key;
    $edit['friendlycaptcha_api_key'] = $api_key;
    $edit['friendlycaptcha_api_endpoint'] = $endpoint;
    $this->drupalPostForm('admin/config/people/captcha/friendlycaptcha', $edit, $this->t('Save configuration'));
    $this->assertSession()->responseContains($this->t('The configuration options have been saved.'), '[testFriendlycaptchaAdminSettingsForm]: The configuration options have been saved.');
    $this->drupalGet('admin/config/people/captcha/friendlycaptcha');
    $this->submitForm($edit, $this->t('Save configuration'));
    $this->assertSession()->responseContains($this->t('The configuration options have been saved.'));

    $this->assertSession()->responseNotContains($this->t('Site key field is required.'), '[testFriendlycaptchaAdminSettingsForm]: Site key was not empty.');
    $this->assertSession()->responseNotContains($this->t('Secret key field is required.'), '[testFriendlycaptchaAdminSettingsForm]: Secret key was not empty.');
    $this->assertSession()->responseNotContains($this->t('The tabindex must be an integer.'), '[testFriendlycaptchaAdminSettingsForm]: Tab index had a valid input.');
    $this->assertSession()->responseNotContains($this->t('Site key field is required.'));
    $this->assertSession()->responseNotContains($this->t('Secret key field is required.'));
    $this->assertSession()->responseNotContains($this->t('The tabindex must be an integer.'));

    $this->drupalLogout();
  }
@@ -145,27 +146,27 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
    $this->drupalLogout();

    $this->drupalGet('user/login');
    $this->assertSession()->responseNotContains($friendlyCaptchaHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is not shown on form.');
    $this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is not shown on form.');
    $this->assertSession()->responseNotContains($friendlyCaptchaHtml);
    $this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml);

    // Enable 'captcha/Math' CAPTCHA on login form.
    captcha_set_form_id_setting('user_login_form', 'captcha/Math');

    $this->drupalGet('user/login');
    $this->assertSession()->responseNotContains($friendlyCaptchaHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is not shown on form.');
    $this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is not shown on form.');
    $this->assertSession()->responseNotContains($friendlyCaptchaHtml);
    $this->assertSession()->responseNotContains($friendlyCaptchaNoScriptHtml);

    // Enable 'friendlycaptcha/friendlycaptcha' on login form.
    captcha_set_form_id_setting('user_login_form', 'friendlycaptcha/friendlycaptcha');
    $result = captcha_get_form_id_setting('user_login_form');
    $this->assertNotNull($result, 'A configuration has been found for CAPTCHA point: user_login_form', 'Friendlycaptcha');
    $this->assertNotNull($result, 'A configuration has been found for CAPTCHA point: user_login_form');
    $this->assertEquals($result->getCaptchaType(), 'friendlycaptcha/friendlycaptcha', 'Friendlycaptcha type has been configured for CAPTCHA point: user_login_form');

    // Check if a Math CAPTCHA is still shown on the login form. The site key
    // and security key have not yet configured for Friendlycaptcha.
    // The module needs to fall back to math captcha.
    $this->drupalGet('user/login');
    $this->assertSession()->responseContains($this->t('Math question'), '[testFriendlycaptchaOnLoginForm]: Math CAPTCHA is shown on form.');
    $this->assertSession()->responseContains($this->t('Math question'));

    // Configure site key and security key to show Friendlycaptcha
    // and no fall back.
@@ -176,9 +177,9 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {

    // Check if there is a Friendlycaptcha on the login form.
    $this->drupalGet('user/login');
    $this->assertSession()->responseContains($friendlyCaptchaHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha is shown on form.');
    $this->assertSession()->responseContains('friendly-challenge/widget.min.js', '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha widget JS is present.');
    $this->assertSession()->responseContains($friendlyCaptchaNoScriptHtml, '[testFriendlycaptchaOnLoginForm]: Friendlycaptcha NoScript is shown on form.');
    $this->assertSession()->responseContains($friendlyCaptchaHtml);
    $this->assertSession()->responseContains('friendly-challenge/widget.min.js');
    $this->assertSession()->responseContains($friendlyCaptchaNoScriptHtml);

    // @todo Check that the widget is not only present, but also loaded!
    // Try to log in, which should fail.
@@ -188,10 +189,11 @@ class FriendlyCaptchaBasicTest extends BrowserTestBase {
    $this->assertSession()
      ->hiddenFieldExists('captcha_response')
      ->setValue('?');
    $this->drupalGet('user/login');

    $this->drupalPostForm('user/login', $edit, $this->t('Log in'));
    $this->submitForm($edit, $this->t('Log in'));
    // Check for error message.
    $this->assertSession()->pageTextContains($this->t('The answer you entered for the CAPTCHA was not correct.'), 'CAPTCHA should block user login form', 'Friendlycaptcha');
    $this->assertSession()->pageTextContains($this->t('The answer you entered for the CAPTCHA was not correct.'));

    // And make sure that user is not logged in: check for name and password
    // fields on "?q=user".