function SearchLanguageTestCase::testLanguages

File

modules/search/search.test, line 2001

Class

SearchLanguageTestCase
Test node search with multiple languages.

Code

function testLanguages() {
    // Check that there are initially no languages displayed.
    $this->drupalGet('search/node');
    $this->assertNoText(t('Languages'), 'No languages to choose from.');
    // Add predefined language.
    $edit = array(
        'langcode' => 'fr',
    );
    $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
    $this->assertText('fr', 'Language added successfully.');
    // Now we should have languages displayed.
    $this->drupalGet('search/node');
    $this->assertText(t('Languages'), 'Languages displayed to choose from.');
    $this->assertText(t('English'), 'English is a possible choice.');
    $this->assertText(t('French'), 'French is a possible choice.');
    // Ensure selecting no language does not make the query different.
    $this->drupalPost('search/node', array(), t('Advanced search'));
    $this->assertEqual($this->getUrl(), url('search/node/', array(
        'absolute' => TRUE,
    )), 'Correct page redirection, no language filtering.');
    // Pick French and ensure it is selected.
    $edit = array(
        'language[fr]' => TRUE,
    );
    $this->drupalPost('search/node', $edit, t('Advanced search'));
    $this->assertFieldByXPath('//input[@name="keys"]', 'language:fr', 'Language filter added to query.');
    // Change the default language and disable English.
    $path = 'admin/config/regional/language';
    $this->drupalGet($path);
    $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
    $edit = array(
        'site_default' => 'fr',
    );
    $this->drupalPost(NULL, $edit, t('Save configuration'));
    $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
    $edit = array(
        'enabled[en]' => FALSE,
    );
    $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
    $this->assertNoFieldChecked('edit-enabled-en', 'Language disabled.');
    // Check that there are again no languages displayed.
    $this->drupalGet('search/node');
    $this->assertNoText(t('Languages'), 'No languages to choose from.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.