function LanguageConfigurationTest::testLanguageConfiguration

Functional tests for adding, editing and deleting languages.

File

drupal/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php, line 36
Definition of Drupal\language\Tests\LanguageConfigurationTest.

Class

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

Namespace

Drupal\language\Tests

Code

function testLanguageConfiguration() {
  global $base_url;

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

  // Check if the Default English language has no path prefix.
  $this
    ->drupalGet('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
    ->drupalPost('admin/config/regional/language/add', $edit, 'Add language');
  $this
    ->assertText('French');
  $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
    ->drupalGet('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
    ->drupalGet('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
    ->drupalGet('admin/config/regional/settings');
  $this
    ->assertOptionSelected('edit-site-default-language', 'en', 'English is the default language.');

  // Change the default language.
  $edit = array(
    'site_default_language' => 'fr',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertOptionSelected('edit-site-default-language', 'fr', 'Default language updated.');
  $this
    ->assertEqual($this
    ->getUrl(), url('admin/config/regional/settings', array(
    'absolute' => TRUE,
  )), 'Correct page redirection.');

  // Check if a valid language prefix is added after changing the default
  // language.
  $this
    ->drupalGet('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
    ->drupalGet('admin/config/regional/language/detection/url');
  $this
    ->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');

  // Check that prefix can be changed.
  $edit = array(
    'prefix[fr]' => 'french',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.');

  // Check that prefix of non default language cannot be changed to
  // empty string.
  $edit = array(
    'prefix[en]' => '',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertText(t('The prefix may only be left blank for the default language.'), 'English prefix cannot be changed to empty string.');

  //  Check that prefix cannot be changed to contain a slash.
  $edit = array(
    'prefix[en]' => 'foo/bar',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertText(t('The prefix may not contain a slash.'), 'English prefix cannot be changed to contain a slash.');
}