1.20.x locale.test | LocaleLanguageNegotiationInfoFunctionalTest::testInfoAlterations() |
Tests alterations to language types/negotiation info.
File
- modules/
locale/ tests/ locale.test, line 2804 - Tests for locale.module.
Class
- LocaleLanguageNegotiationInfoFunctionalTest
- Functional test for language types/negotiation info.
Code
function testInfoAlterations() {
// Enable language type/negotiation info alterations.
state_set('locale_test_language_types', TRUE);
state_set('locale_test_language_negotiation_info', TRUE);
$this->languageNegotiationUpdate();
// 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);
$this->languageNegotiationUpdate();
$type = LANGUAGE_TYPE_CONTENT;
$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';
$provider = LANGUAGE_NEGOTIATION_INTERFACE;
$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);
$this->languageNegotiationUpdate();
$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.
$this->backdropGet('');
$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.
$this->languageNegotiationUpdate('disable');
// 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.');
}