- <?php
-
- * @file
- * Tests for language.module.
- *
- * The test file includes:
- * - a functional test for the language configuration forms;
- */
-
-
- * Functional tests for the language list configuration forms.
- */
- class LanguageListTest extends BackdropWebTestCase {
- function setUp() {
- parent::setUp('language');
- }
-
-
- * Functional tests for adding, configuring, and deleting languages.
- */
- function testLanguageList() {
- global $base_url;
-
-
- $admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
- $this->backdropLogin($admin_user);
-
-
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('French', t('Language added successfully.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
-
- $langcode = 'xx';
- $name = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
- $this->assertRaw('"edit-site-default-' . $langcode .'"', t('Language code found.'));
- $this->assertText(t($name), t('Test language added.'));
-
-
- $path = 'admin/config/regional/language';
- $this->backdropGet($path);
- $this->assertFieldChecked('edit-site-default-en', t('English is the default language.'));
-
- $edit = array(
- 'site_default' => $langcode,
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-site-default-en', t('Default language updated.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
-
- $this->backdropGet('admin/config/regional/language/delete/' . $langcode);
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
- $this->assertText(t('The default language cannot be deleted.'), t('Failed to delete the default language.'));
-
-
- $edit = array(
- 'languages[en][enabled]' => FALSE,
- );
- $this->backdropPost($path, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-languages-en-enabled', t('Language disabled.'));
-
-
- $edit = array(
- 'site_default' => 'en',
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->assertFieldChecked('edit-languages-en-enabled', t('Default language re-enabled.'));
-
-
- $this->clickLink(t('Configure'));
- $this->assertTitle(t('Configure language | Backdrop CMS'), t('Page title is "Configure language".'));
-
- $name = $this->randomName(16);
- $edit = array(
- 'name' => $name,
- 'native' => $name,
- );
- $this->backdropPost('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language'));
- $this->assertRaw($name, t('The language has been updated.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
-
- $this->backdropGet('admin/config/regional/language');
- $this->clickLink(t('Delete'));
- $this->assertText(t('Are you sure you want to delete the language'), t('"delete" link is correct.'));
-
- $this->backdropGet('admin/config/regional/language/delete/' . $langcode);
-
- $this->clickLink(t('Cancel'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
- $this->assertRaw($name, t('The language was not deleted.'));
-
-
- $this->backdropPost('admin/config/regional/language/delete/' . $langcode, array(), t('Delete'));
-
- $t_args = array('%language' => $name, '%langcode' => $langcode);
- $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), t('The test language has been removed.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
- $this->backdropGet('admin/config/regional/language/delete/' . $langcode);
- $this->assertResponse(404, t('Language no longer found.'));
-
- backdrop_static_reset('language_list');
- $enabled_languages = language_list(TRUE);
- $this->assertEqual(config_get('system.core', 'language_count'), count($enabled_languages), t('Language count is correct.'));
-
-
- $edit = array(
- 'languages[fr][enabled]' => FALSE,
- );
- $this->backdropPost($path, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-languages-fr-enabled', t('French language disabled.'));
-
- backdrop_static_reset('language_list');
- $enabled_languages = language_list(TRUE);
-
- $this->backdropPost('admin/config/regional/language/delete/fr', array(), t('Delete'));
-
- $t_args = array('%language' => 'French', '%langcode' => 'fr');
- $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), t('Disabled language has been removed.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
- $this->backdropGet('admin/config/regional/language/delete/fr');
- $this->assertResponse(404, t('Language no longer found.'));
-
- $this->assertEqual(config_get('system.core', 'language_count'), count($enabled_languages), t('Language count is correct.'));
-
-
-
-
- $langcode = 'xx';
- $name = $this->randomName(16);
- $edit = array(
- 'predefined_langcode' => 'custom',
- 'langcode' => $langcode,
- 'name' => $name,
- 'native' => $name,
- 'direction' => '0',
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
- $this->assertText($name, t('Name found.'));
-
-
- $path = 'admin/config/regional/language';
- $this->backdropGet($path);
- $this->assertFieldChecked('edit-site-default-en', t('English is the default language.'));
-
- $edit = array(
- 'site_default' => $langcode,
- );
- $this->backdropPost(NULL, $edit, t('Save configuration'));
- $this->assertNoFieldChecked('edit-site-default-en', t('Default language updated.'));
- $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
-
- $this->backdropPost('admin/config/regional/language/delete/en', array(), t('Delete'));
-
- $t_args = array('%language' => 'English', '%langcode' => 'en');
- $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), t('The English language has been removed.'));
- }
- }