function SearchConfigSettingsFormTest::testSearchModuleDisabling in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Tests/SearchConfigSettingsFormTest.php \Drupal\search\Tests\SearchConfigSettingsFormTest::testSearchModuleDisabling()
Verifies that you can disable individual search plugins.
File
- core/
modules/ search/ src/ Tests/ SearchConfigSettingsFormTest.php, line 134 - Contains \Drupal\search\Tests\SearchConfigSettingsFormTest.
Class
- SearchConfigSettingsFormTest
- Verify the search config settings form.
Namespace
Drupal\search\TestsCode
function testSearchModuleDisabling() {
// Array of search plugins to test: 'keys' are the keywords to search for,
// and 'text' is the text to assert is on the results page.
$plugin_info = array(
'node_search' => array(
'keys' => 'pizza',
'text' => $this->searchNode
->label(),
),
'user_search' => array(
'keys' => $this->searchUser
->getUsername(),
'text' => $this->searchUser
->getEmail(),
),
'dummy_search_type' => array(
'keys' => 'foo',
'text' => 'Dummy search snippet to display',
),
);
$plugins = array_keys($plugin_info);
/** @var $entities \Drupal\search\SearchPageInterface[] */
$entities = entity_load_multiple('search_page');
// Disable all of the search pages.
foreach ($entities as $entity) {
$entity
->disable()
->save();
}
// Test each plugin if it's enabled as the only search plugin.
foreach ($entities as $entity_id => $entity) {
// Set this as default.
$this
->drupalGet("admin/config/search/pages/manage/{$entity_id}/set-default");
// Run a search from the correct search URL.
$info = $plugin_info[$entity_id];
$this
->drupalGet('search/' . $entity
->getPath(), array(
'query' => array(
'keys' => $info['keys'],
),
));
$this
->assertResponse(200);
$this
->assertNoText('no results', $entity
->label() . ' search found results');
$this
->assertText($info['text'], 'Correct search text found');
// Verify that other plugin search tab labels are not visible.
foreach ($plugins as $other) {
if ($other != $entity_id) {
$label = $entities[$other]
->label();
$this
->assertNoText($label, $label . ' search tab is not shown');
}
}
// Run a search from the search block on the node page. Verify you get
// to this plugin's search results page.
$terms = array(
'keys' => $info['keys'],
);
$this
->submitGetForm('node', $terms, t('Search'));
$current = $this
->getURL();
$expected = \Drupal::url('search.view_' . $entity
->id(), array(), array(
'query' => array(
'keys' => $info['keys'],
),
'absolute' => TRUE,
));
$this
->assertEqual($current, $expected, 'Block redirected to right search page');
// Try an invalid search path, which should 404.
$this
->drupalGet('search/not_a_plugin_path');
$this
->assertResponse(404);
$entity
->disable()
->save();
}
// Test with all search plugins enabled. When you go to the search
// page or run search, all plugins should be shown.
foreach ($entities as $entity) {
$entity
->enable()
->save();
}
// Set the node search as default.
$this
->drupalGet('admin/config/search/pages/manage/node_search/set-default');
$paths = array(
array(
'path' => 'search/node',
'options' => array(
'query' => array(
'keys' => 'pizza',
),
),
),
array(
'path' => 'search/node',
'options' => array(),
),
);
foreach ($paths as $item) {
$this
->drupalGet($item['path'], $item['options']);
foreach ($plugins as $entity_id) {
$label = $entities[$entity_id]
->label();
$this
->assertText($label, format_string('%label search tab is shown', array(
'%label' => $label,
)));
}
}
}