1 locale.test LocaleLanguageNegotiationInfoFunctionalTest::testInfoAlterations()

Tests alterations to language types/negotiation info.


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


Functional test for language types/negotiation info.


function testInfoAlterations() {
  // Enable language type/negotiation info alterations.
  state_set('locale_test_language_types', TRUE);
  state_set('locale_test_language_negotiation_info', TRUE);

  // Make the content language type configurable by updating the language
  // negotiation settings with the proper flag enabled.
  state_set('locale_test_content_language_type', TRUE);

  $language_types = language_types_get_configurable();
  $this->assertTrue(in_array($type, $language_types), 'Content language type is configurable.');

  // Enable some core and custom language providers. The test language type is
  // supposed to be configurable.
  $test_type = 'test_language_type';
  $test_provider = 'test_language_provider';
  $form_field = $type . '[' . $provider . '][enabled]';
  $edit = array(
    $form_field => TRUE,
    $type . '[' . $test_provider . '][enabled]' => TRUE,
    $test_type . '[' . $test_provider . '][enabled]' => TRUE,
  $this->backdropPost('admin/config/regional/language/detection', $edit, t('Save settings'));

  // Remove the interface language provider by updating the language
  // negotiation settings with the proper flag enabled.
  state_set('locale_test_language_negotiation_info_alter', TRUE);
  $negotiation = (array) config_get('language.settings', "language_negotiation.$type");
  $this->assertFalse(isset($negotiation[$provider]), 'Interface language provider removed from the stored settings.');
  $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, 'Interface language provider unavailable.');

  // Check that type-specific language providers can be assigned only to the
  // corresponding language types.
  foreach (language_types_get_configurable() as $type) {
    $form_field = $type . '[test_language_provider_ts][enabled]';
    if ($type == $test_type) {
      $this->assertFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider available for %type.', array('%type' => $type)));
    else {
      $this->assertNoFieldByXPath("//input[@name=\"$form_field\"]", NULL, format_string('Type-specific test language provider unavailable for %type.', array('%type' => $type)));

  // Check language negotiation results.
  $last = state_get('locale_test_language_negotiation_last', array());
  foreach (language_types_info() as $type_name => $type_info) {
    $langcode = $last[$type_name];
    $value = ($type_name == LANGUAGE_TYPE_CONTENT || strpos($type_name, 'test') !== FALSE) ? 'it' : 'en';
    $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type_name, '%language' => $langcode)));

  // Disable locale_test and check that everything is set back to the original
  // status.

  // Check that only the core language types are available.
  foreach (language_types_info() as $type_name => $type_info) {
    $this->assertTrue(strpos($type_name, 'test') === FALSE, format_string('The %type language is still available', array('%type' => $type_name)));

  // Check that unavailable language providers are not present in the
  // negotiation settings.
  $negotiation = (array) config_get('language.settings', "language_negotiation.$type");
  $this->assertFalse(isset($negotiation[$test_provider]), 'The disabled test language provider is not part of the content language negotiation settings.');

  // Check that configuration page presents the correct options and settings.
  $this->assertNoRaw(t('Test language detection'), 'No test language type configuration available.');
  $this->assertNoRaw(t('This is a test language provider'), 'No test language provider available.');