1 locale.test LocaleConfigurationTest::testLanguageConfiguration()

Functional tests for adding, editing and deleting languages.

File

core/modules/locale/tests/locale.test, line 18
Tests for locale.module.

Class

LocaleConfigurationTest
Functional tests for language configuration's effect on negotiation setup.

Code

function testLanguageConfiguration() {
  global $base_url;

  // User to add and remove language.
  $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
  $this->backdropLogin($admin_user);

  // Check if the Default English language has no path prefix.
  $this->backdropGet('admin/config/regional/language/detection/url');
  $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');

  // Add predefined language.
  $edit = array(
    'predefined_langcode' => 'fr',
  );
  $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
  $this->assertText('French', 'Language added successfully.');
  $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');

  // Check if the Default English language has no path prefix.
  $this->backdropGet('admin/config/regional/language/detection/url');
  $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
  // Check if French has a path prefix.
  $this->backdropGet('admin/config/regional/language/detection/url');
  $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');

  // Check if we can change the default language.
  $this->backdropGet('admin/config/regional/language');
  $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
  // Change the default language.
  $edit = array(
    'site_default' => 'fr',
  );
  $this->backdropPost(NULL, $edit, t('Save configuration'));
  $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
  $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.');

  // Check if a valid language prefix is added after changing the default
  // language.
  $this->backdropGet('admin/config/regional/language/detection/url');
  $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
  // Check if French still has a path prefix.
  $this->backdropGet('admin/config/regional/language/detection/url');
  $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
}