public function ExcludedContentTest::testExcludingContent in Search Exclude (Node) 2.0.x
Test exclusion of appropriate content.
Throws
\Behat\Mink\Exception\ResponseTextException
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Functional/ ExcludedContentTest.php, line 40
Class
- ExcludedContentTest
- Tests content is appropriately excluded from search results.
Namespace
Drupal\Tests\search_exclude\FunctionalCode
public function testExcludingContent() {
$this
->drupalCreateContentType([
'type' => 'included',
'name' => 'Included Content',
]);
$this
->drupalCreateContentType([
'type' => 'excluded',
'name' => 'Excluded Content',
]);
$this
->drupalCreateNode([
'type' => 'included',
'title' => 'Included Content',
]);
$this
->drupalCreateNode([
'type' => 'excluded',
'title' => 'Excluded Content',
]);
$account = $this
->drupalCreateUser([
'search content',
]);
$this
->drupalLogin($account);
// Configure the search exclude to exclude content of type excluded.
$config = \Drupal::configFactory()
->getEditable('search.page.content_exclude_');
$config
->set('langcode', 'en');
$config
->set('status', TRUE);
$config
->set('dependencies', [
"module" => [
"search_exclude",
],
]);
$config
->set('id', 'content_exclude_');
$config
->set('label', 'Content (Exclude)');
$config
->set('path', 'exclude');
$config
->set('weight', 0);
$config
->set('plugin', 'search_exclude_node_search');
$config
->set('configuration', [
'rankings' => [],
"excluded_bundles" => [
"excluded" => "excluded",
],
]);
$config
->save();
\Drupal::service("router.builder")
->rebuild();
// Update the search index for the search exclude plugin.
$searchPluginManager = $this->container
->get('plugin.manager.search');
$searchPluginManager
->clearCachedDefinitions();
$searchPluginManager
->createInstance('search_exclude_node_search', $config
->get('configuration'))
->updateIndex();
// Finally search for the content types to verify inclusion/exclusion
// appropriately.
$this
->drupalPostForm('search/exclude', [
'keys' => '"Included Content"',
], t('Search'));
$this
->assertSession()
->pageTextNotContains('Your search yielded no results');
$this
->drupalPostForm('search/exclude', [
'keys' => '"Excluded Content"',
], t('Search'));
$this
->assertSession()
->pageTextContains('Your search yielded no results');
}