You are here

class ContactLanguageTest in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/contact/tests/src/Functional/ContactLanguageTest.php \Drupal\Tests\contact\Functional\ContactLanguageTest
  2. 9 core/modules/contact/tests/src/Functional/ContactLanguageTest.php \Drupal\Tests\contact\Functional\ContactLanguageTest

Tests contact messages with language module.

This is to ensure that a contact form by default does not show the language select, but it does so when it's enabled from the content language settings page.

@group contact

Hierarchy

Expanded class hierarchy of ContactLanguageTest

File

core/modules/contact/tests/src/Functional/ContactLanguageTest.php, line 16

Namespace

Drupal\Tests\contact\Functional
View source
class ContactLanguageTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'contact',
    'language',
    'contact_test',
  ];

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

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();

    // Create and log in administrative user.
    $admin_user = $this
      ->drupalCreateUser([
      'access site-wide contact form',
      'administer languages',
    ]);
    $this
      ->drupalLogin($admin_user);
  }

  /**
   * Tests configuration options with language enabled.
   */
  public function testContactLanguage() {

    // Ensure that contact form by default does not show the language select.
    $this
      ->drupalGet('contact');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSession()
      ->fieldNotExists('edit-langcode-0-value');

    // Enable language select from content language settings page.
    $settings_path = 'admin/config/regional/content-language';
    $edit['entity_types[contact_message]'] = TRUE;
    $edit['settings[contact_message][feedback][settings][language][language_alterable]'] = TRUE;
    $this
      ->drupalGet($settings_path);
    $this
      ->submitForm($edit, 'Save configuration');

    // Ensure that contact form now shows the language select.
    $this
      ->drupalGet('contact');
    $this
      ->assertSession()
      ->statusCodeEquals(200);
    $this
      ->assertSession()
      ->fieldExists('edit-langcode-0-value');
  }

}

Members