View source
<?php
namespace Drupal\Tests\search_exclude\Functional;
use Drupal\Tests\BrowserTestBase;
class ExcludedContentTest extends BrowserTestBase {
protected static $modules = [
'node',
'search_exclude',
];
protected $defaultTheme = 'stark';
protected $strictConfigSchema = FALSE;
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);
$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();
$searchPluginManager = $this->container
->get('plugin.manager.search');
$searchPluginManager
->clearCachedDefinitions();
$searchPluginManager
->createInstance('search_exclude_node_search', $config
->get('configuration'))
->updateIndex();
$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');
}
}