1 search.test SearchLanguageTestCase::testLanguages()

File

core/modules/search/tests/search.test, line 1970
Tests for search.module.

Class

SearchLanguageTestCase
Test node search with multiple languages.

Code

function testLanguages() {
  // Check that there are initially no languages displayed.
  $this->backdropGet('search/node');
  $this->assertNoText(t('Languages'), 'No languages to choose from.');

  // Add predefined language.
  $edit = array('predefined_langcode' => 'fr');
  $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
  $this->assertText('French', 'Language added successfully.');

  // Now we should have languages displayed.
  $this->backdropGet('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->backdropPost('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->backdropPost('search/node', $edit, t('Advanced search'));
  $this->assertFieldByXPath('//input[@name="keys"]', 'langcode:fr', 'Language filter added to query.');

  // Change the default language and disable English.
  $path = 'admin/config/regional/language';
  $this->backdropGet($path);
  $this->assertFieldChecked('edit-site-default-en', 'English is the default language.');
  $edit = array('site_default' => 'fr');
  $this->backdropPost(NULL, $edit, t('Save configuration'));
  $this->assertNoFieldChecked('edit-site-default-en', 'Default language updated.');
  $edit = array('languages[en][enabled]' => FALSE);
  $this->backdropPost('admin/config/regional/language', $edit, t('Save configuration'));
  $this->assertNoFieldChecked('edit-languages-en-enabled', 'Language disabled.');

  // Check that there are again no languages displayed.
  $this->backdropGet('search/node');
  $this->assertNoText(t('Languages'), 'No languages to choose from.');
}