function SearchLanguageTest::testLanguages in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Tests/SearchLanguageTest.php \Drupal\search\Tests\SearchLanguageTest::testLanguages()
File
- core/
modules/ search/ src/ Tests/ SearchLanguageTest.php, line 94 - Contains \Drupal\search\Tests\SearchLanguageTest.
Class
- SearchLanguageTest
- Tests advanced search with different languages added.
Namespace
Drupal\search\TestsCode
function testLanguages() {
// Add predefined language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
$this
->assertText('French', '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
->drupalPostForm('search/node', array(), t('Advanced search'));
$this
->assertUrl(\Drupal::url('search.view_node_search', [], [
'query' => [
'keys' => '',
],
'absolute' => TRUE,
]), [], 'Correct page redirection, no language filtering.');
// Pick French and ensure it is selected.
$edit = array(
'language[fr]' => TRUE,
);
$this
->drupalPostForm('search/node', $edit, t('Advanced search'));
// Get the redirected URL.
$url = $this
->getUrl();
$parts = parse_url($url);
$query_string = isset($parts['query']) ? rawurldecode($parts['query']) : '';
$this
->assertTrue(strpos($query_string, '=language:fr') !== FALSE, 'Language filter language:fr add to the query string.');
// Search for keyword node and language filter as Spanish.
$edit = array(
'keys' => 'node',
'language[es]' => TRUE,
);
$this
->drupalPostForm('search/node', $edit, t('Advanced search'));
// Check for Spanish results.
$this
->assertLink('Second node this is the Spanish title', 0, 'Second node Spanish title found in search results');
$this
->assertLink('Third node es', 0, 'Third node Spanish found in search results');
// Ensure that results doesn't contain other language nodes.
$this
->assertNoLink('First node en', 'Search results does not contain first English node');
$this
->assertNoLink('Second node en', 'Search results does not contain second English node');
$this
->assertNoLink('Third node en', 'Search results does not contain third English node');
// Change the default language and delete English.
$path = 'admin/config/regional/language';
$this
->drupalGet($path);
$this
->assertFieldChecked('edit-site-default-language-en', 'Default language updated.');
$edit = array(
'site_default_language' => 'fr',
);
$this
->drupalPostForm($path, $edit, t('Save configuration'));
$this
->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.');
$this
->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
}