Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -2,6 +2,7 @@ id: d6_search_settings
|
|||
label: Search configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
constants:
|
||||
|
@ -10,6 +11,7 @@ source:
|
|||
- minimum_word_size
|
||||
- overlap_cjk
|
||||
- search_cron_limit
|
||||
source_module: search
|
||||
process:
|
||||
'index/minimum_word_size': minimum_word_size
|
||||
'index/overlap_cjk': overlap_cjk
|
|
@ -2,6 +2,7 @@ id: d7_search_settings
|
|||
label: Search configuration
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
constants:
|
||||
|
@ -13,6 +14,7 @@ source:
|
|||
- search_tag_weights
|
||||
- search_and_or_limit
|
||||
- search_default_module
|
||||
source_module: search
|
||||
process:
|
||||
'index/minimum_word_size': minimum_word_size
|
||||
'index/overlap_cjk': overlap_cjk
|
|
@ -3,6 +3,7 @@ label: Search page configuration
|
|||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
|
@ -16,6 +17,7 @@ source:
|
|||
id: node_search
|
||||
path: node
|
||||
plugin: node_search
|
||||
source_module: search
|
||||
process:
|
||||
id: 'constants/id'
|
||||
path: 'constants/path'
|
|
@ -8,6 +8,7 @@
|
|||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
|
@ -105,6 +106,13 @@ function search_theme() {
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function search_theme_suggestions_search_result(array $variables) {
|
||||
return ['search_result__' . $variables['plugin_id']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for block templates.
|
||||
*/
|
||||
|
@ -218,7 +226,7 @@ function search_update_totals() {
|
|||
// search_total. We use a LEFT JOIN between the two tables and keep only the
|
||||
// rows which fail to join.
|
||||
$result = db_query("SELECT t.word AS realword, i.word FROM {search_total} t LEFT JOIN {search_index} i ON t.word = i.word WHERE i.word IS NULL", [], ['target' => 'replica']);
|
||||
$or = db_or();
|
||||
$or = new Condition('OR');
|
||||
foreach ($result as $word) {
|
||||
$or->condition('word', $word->realword);
|
||||
}
|
||||
|
@ -257,7 +265,7 @@ function search_simplify($text, $langcode = NULL) {
|
|||
$text = Html::decodeEntities($text);
|
||||
|
||||
// Lowercase
|
||||
$text = Unicode::strtolower($text);
|
||||
$text = mb_strtolower($text);
|
||||
|
||||
// Remove diacritics.
|
||||
$text = \Drupal::service('transliteration')->removeDiacritics($text);
|
||||
|
@ -322,7 +330,7 @@ function search_simplify($text, $langcode = NULL) {
|
|||
function search_expand_cjk($matches) {
|
||||
$min = \Drupal::config('search.settings')->get('index.minimum_word_size');
|
||||
$str = $matches[0];
|
||||
$length = Unicode::strlen($str);
|
||||
$length = mb_strlen($str);
|
||||
// If the text is shorter than the minimum word size, don't tokenize it.
|
||||
if ($length <= $min) {
|
||||
return ' ' . $str . ' ';
|
||||
|
@ -332,7 +340,7 @@ function search_expand_cjk($matches) {
|
|||
$chars = [];
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
// Add the next character off the beginning of the string to the queue.
|
||||
$current = Unicode::substr($str, 0, 1);
|
||||
$current = mb_substr($str, 0, 1);
|
||||
$str = substr($str, strlen($current));
|
||||
$chars[] = $current;
|
||||
if ($i >= $min - 1) {
|
||||
|
@ -445,20 +453,27 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
// Note: PHP ensures the array consists of alternating delimiters and literals
|
||||
// and begins and ends with a literal (inserting $null as required).
|
||||
|
||||
$tag = FALSE; // Odd/even counter. Tag or no tag.
|
||||
$score = 1; // Starting score per word
|
||||
$accum = ' '; // Accumulator for cleaned up data
|
||||
$tagstack = []; // Stack with open tags
|
||||
$tagwords = 0; // Counter for consecutive words
|
||||
$focus = 1; // Focus state
|
||||
// Odd/even counter. Tag or no tag.
|
||||
$tag = FALSE;
|
||||
// Starting score per word.
|
||||
$score = 1;
|
||||
// Accumulator for cleaned up data.
|
||||
$accum = ' ';
|
||||
// Stack with open tags.
|
||||
$tagstack = [];
|
||||
// Counter for consecutive words.
|
||||
$tagwords = 0;
|
||||
// Focus state.
|
||||
$focus = 1;
|
||||
|
||||
$scored_words = []; // Accumulator for words for index
|
||||
// Accumulator for words for index.
|
||||
$scored_words = [];
|
||||
|
||||
foreach ($split as $value) {
|
||||
if ($tag) {
|
||||
// Increase or decrease score per word based on tag
|
||||
list($tagname) = explode(' ', $value, 2);
|
||||
$tagname = Unicode::strtolower($tagname);
|
||||
$tagname = mb_strtolower($tagname);
|
||||
// Closing or opening tag?
|
||||
if ($tagname[0] == '/') {
|
||||
$tagname = substr($tagname, 1);
|
||||
|
@ -495,8 +510,8 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
foreach ($words as $word) {
|
||||
// Add word to accumulator
|
||||
$accum .= $word . ' ';
|
||||
// Check wordlength
|
||||
if (is_numeric($word) || Unicode::strlen($word) >= $minimum_word_size) {
|
||||
// Check word length.
|
||||
if (is_numeric($word) || mb_strlen($word) >= $minimum_word_size) {
|
||||
if (!isset($scored_words[$word])) {
|
||||
$scored_words[$word] = 0;
|
||||
}
|
||||
|
@ -782,7 +797,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
$text = trim(preg_replace('/' . $preceded_by_boundary . '(?:' . implode('|', $keys) . ')' . $followed_by_boundary . '/iu', '<strong>\0</strong>', ' ' . $text . ' '));
|
||||
return [
|
||||
'#markup' => $text,
|
||||
'#allowed_tags' => ['strong']
|
||||
'#allowed_tags' => ['strong'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -826,13 +841,13 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
|
|||
|
||||
// See if there is a match after lower-casing and removing diacritics in
|
||||
// both, which should preserve the string length.
|
||||
$new_text = Unicode::strtolower($text);
|
||||
$new_text = mb_strtolower($text);
|
||||
$new_text = \Drupal::service('transliteration')->removeDiacritics($new_text);
|
||||
$new_key = Unicode::strtolower($temp);
|
||||
$new_key = mb_strtolower($temp);
|
||||
$new_key = \Drupal::service('transliteration')->removeDiacritics($new_key);
|
||||
if (preg_match('/' . $preceded_by_boundary . preg_quote($new_key, '/') . $followed_by_boundary . '/u', ' ' . $new_text . ' ')) {
|
||||
$position = Unicode::strpos($new_text, $new_key);
|
||||
return Unicode::substr($text, $position, Unicode::strlen($new_key));
|
||||
$position = mb_strpos($new_text, $new_key);
|
||||
return mb_substr($text, $position, mb_strlen($new_key));
|
||||
}
|
||||
|
||||
// Run both text and key through search_simplify.
|
||||
|
@ -861,7 +876,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
|
|||
$proposed_end_index = floor(($max_end_index + $min_end_index) / 2);
|
||||
$proposed_end_pos = $words[$proposed_end_index][1];
|
||||
// Since the split was done with preg_split(), the positions are byte counts
|
||||
// not character counts, so use substr() not Unicode::substr() here.
|
||||
// not character counts, so use substr() not mb_substr() here.
|
||||
$trial_text = trim(search_simplify(substr($text, $start_pos, $proposed_end_pos - $start_pos), $langcode));
|
||||
if (strpos($trial_text, $simplified_key) !== FALSE) {
|
||||
// The proposed endpoint is fine, text still matches.
|
||||
|
@ -887,7 +902,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
|
|||
$proposed_start_index = ceil(($max_start_index + $min_start_index) / 2);
|
||||
$proposed_start_pos = $words[$proposed_start_index][1];
|
||||
// Since the split was done with preg_split(), the positions are byte counts
|
||||
// not character counts, so use substr() not Unicode::substr() here.
|
||||
// not character counts, so use substr() not mb_substr() here.
|
||||
$trial_text = trim(search_simplify(substr($text, $proposed_start_pos, $end_pos - $proposed_start_pos), $langcode));
|
||||
if (strpos($trial_text, $simplified_key) !== FALSE) {
|
||||
// The proposed start point is fine, text still matches.
|
||||
|
@ -902,9 +917,8 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
|
|||
$start_index = $max_start_index;
|
||||
|
||||
// Return the matching text. We need to use substr() here and not the
|
||||
// Unicode::substr() function, because the indices in $words came from
|
||||
// preg_split(), so they are Unicode-safe byte positions, not character
|
||||
// positions.
|
||||
// mb_substr() function, because the indices in $words came from preg_split(),
|
||||
// so they are Unicode-safe byte positions, not character positions.
|
||||
return trim(substr($text, $words[$start_index][1], $words[$end_index][1] - $words[$start_index][1]));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,13 +8,6 @@
|
|||
use Drupal\Component\Utility\UrlHelper;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function search_theme_suggestions_search_result(array $variables) {
|
||||
return ['search_result__' . $variables['plugin_id']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares variables for individual search result templates.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\search\Controller;
|
|||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\search\Form\SearchPageForm;
|
||||
use Drupal\search\SearchPageInterface;
|
||||
use Drupal\search\SearchPageRepositoryInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
@ -84,7 +85,7 @@ class SearchController extends ControllerBase {
|
|||
}
|
||||
|
||||
$build['#title'] = $plugin->suggestedTitle();
|
||||
$build['search_form'] = $this->entityFormBuilder()->getForm($entity, 'search');
|
||||
$build['search_form'] = $this->formBuilder()->getForm(SearchPageForm::class, $entity);
|
||||
|
||||
// Build search results, if keywords or other search parameters are in the
|
||||
// GET parameters. Note that we need to try the search if 'keys' is in
|
||||
|
@ -103,7 +104,7 @@ class SearchController extends ControllerBase {
|
|||
else {
|
||||
// The search not being executable means that no keywords or other
|
||||
// conditions were entered.
|
||||
drupal_set_message($this->t('Please enter some keywords.'), 'error');
|
||||
$this->messenger()->addError($this->t('Please enter some keywords.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,8 +149,6 @@ class SearchController extends ControllerBase {
|
|||
/**
|
||||
* Creates a render array for the search help page.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The request object.
|
||||
* @param \Drupal\search\SearchPageInterface $entity
|
||||
* The search page entity.
|
||||
*
|
||||
|
@ -207,10 +206,10 @@ class SearchController extends ControllerBase {
|
|||
$search_page->$op()->save();
|
||||
|
||||
if ($op == 'enable') {
|
||||
drupal_set_message($this->t('The %label search page has been enabled.', ['%label' => $search_page->label()]));
|
||||
$this->messenger()->addStatus($this->t('The %label search page has been enabled.', ['%label' => $search_page->label()]));
|
||||
}
|
||||
elseif ($op == 'disable') {
|
||||
drupal_set_message($this->t('The %label search page has been disabled.', ['%label' => $search_page->label()]));
|
||||
$this->messenger()->addStatus($this->t('The %label search page has been disabled.', ['%label' => $search_page->label()]));
|
||||
}
|
||||
|
||||
$url = $search_page->urlInfo('collection');
|
||||
|
@ -230,7 +229,7 @@ class SearchController extends ControllerBase {
|
|||
// Set the default page to this search page.
|
||||
$this->searchPageRepository->setDefaultSearchPage($search_page);
|
||||
|
||||
drupal_set_message($this->t('The default search page is now %label. Be sure to check the ordering of your search pages.', ['%label' => $search_page->label()]));
|
||||
$this->messenger()->addStatus($this->t('The default search page is now %label. Be sure to check the ordering of your search pages.', ['%label' => $search_page->label()]));
|
||||
return $this->redirect('entity.search_page.collection');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,19 @@ use Drupal\search\SearchPageInterface;
|
|||
* @ConfigEntityType(
|
||||
* id = "search_page",
|
||||
* label = @Translation("Search page"),
|
||||
* label_collection = @Translation("Search pages"),
|
||||
* label_singular = @Translation("search page"),
|
||||
* label_plural = @Translation("search pages"),
|
||||
* label_count = @PluralTranslation(
|
||||
* singular = "@count search page",
|
||||
* plural = "@count search pages",
|
||||
* ),
|
||||
* handlers = {
|
||||
* "access" = "Drupal\search\SearchPageAccessControlHandler",
|
||||
* "list_builder" = "Drupal\search\SearchPageListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\search\Form\SearchPageAddForm",
|
||||
* "edit" = "Drupal\search\Form\SearchPageEditForm",
|
||||
* "search" = "Drupal\search\Form\SearchPageForm",
|
||||
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
|
||||
* }
|
||||
* },
|
||||
|
|
|
@ -8,6 +8,8 @@ use Drupal\Core\Url;
|
|||
|
||||
/**
|
||||
* Provides the search reindex confirmation form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ReindexConfirm extends ConfirmFormBase {
|
||||
|
||||
|
@ -63,7 +65,7 @@ class ReindexConfirm extends ConfirmFormBase {
|
|||
foreach ($search_page_repository->getIndexableSearchPages() as $entity) {
|
||||
$entity->getPlugin()->markForReindex();
|
||||
}
|
||||
drupal_set_message($this->t('All search indexes will be rebuilt.'));
|
||||
$this->messenger()->addStatus($this->t('All search indexes will be rebuilt.'));
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Builds the search form for the search block.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SearchBlockForm extends FormBase {
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Provides a form for adding a search page.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SearchPageAddForm extends SearchPageFormBase {
|
||||
|
||||
|
@ -39,7 +41,7 @@ class SearchPageAddForm extends SearchPageFormBase {
|
|||
|
||||
parent::save($form, $form_state);
|
||||
|
||||
drupal_set_message($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
|
||||
$this->messenger()->addStatus($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Provides a form for editing a search page.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SearchPageEditForm extends SearchPageFormBase {
|
||||
|
||||
|
@ -24,7 +26,7 @@ class SearchPageEditForm extends SearchPageFormBase {
|
|||
public function save(array $form, FormStateInterface $form_state) {
|
||||
parent::save($form, $form_state);
|
||||
|
||||
drupal_set_message($this->t('The %label search page has been updated.', ['%label' => $this->entity->label()]));
|
||||
$this->messenger()->addStatus($this->t('The %label search page has been updated.', ['%label' => $this->entity->label()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace Drupal\search\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\search\SearchPageInterface;
|
||||
|
||||
/**
|
||||
* Provides a search form for site wide search.
|
||||
|
@ -14,11 +15,13 @@ use Drupal\Core\Url;
|
|||
* submit, making sure to redirect with a GET parameter of 'keys' included, to
|
||||
* trigger the search being processed by the controller, and adding in any
|
||||
* additional query parameters they need to execute search.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SearchPageForm extends EntityForm {
|
||||
class SearchPageForm extends FormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* The search page entity.
|
||||
*
|
||||
* @var \Drupal\search\SearchPageInterface
|
||||
*/
|
||||
|
@ -34,7 +37,9 @@ class SearchPageForm extends EntityForm {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
public function buildForm(array $form, FormStateInterface $form_state, SearchPageInterface $search_page = NULL) {
|
||||
$this->entity = $search_page;
|
||||
|
||||
$plugin = $this->entity->getPlugin();
|
||||
$form_state->set('search_page_id', $this->entity->id());
|
||||
|
||||
|
@ -72,16 +77,7 @@ class SearchPageForm extends EntityForm {
|
|||
|
||||
// Allow the plugin to add to or alter the search form.
|
||||
$plugin->searchFormAlter($form, $form_state);
|
||||
|
||||
return parent::form($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
// The submit button is added in the form directly.
|
||||
return [];
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements
|
|||
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
|
||||
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $this->configuration);
|
||||
$this->setConfiguration($configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setConfiguration(array $configuration) {
|
||||
$this->configuration = $configuration;
|
||||
$this->configuration = NestedArray::mergeDeep($this->defaultConfiguration(), $configuration);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,7 +110,7 @@ interface SearchInterface extends PluginInspectionInterface {
|
|||
*
|
||||
* The core search module only invokes this method on active module plugins
|
||||
* when building a form for them in
|
||||
* \Drupal\search\Form\SearchPageForm::form(). A plugin implementing this
|
||||
* \Drupal\search\Form\SearchPageForm::buildForm(). A plugin implementing this
|
||||
* will also need to implement the buildSearchUrlQuery() method.
|
||||
*
|
||||
* @param array $form
|
||||
|
|
|
@ -146,16 +146,18 @@ abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPl
|
|||
public function getHelp() {
|
||||
// This default search help is appropriate for plugins like NodeSearch
|
||||
// that use the SearchQuery class.
|
||||
$help = ['list' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [
|
||||
$this->t('Search looks for exact, case-insensitive keywords; keywords shorter than a minimum length are ignored.'),
|
||||
$this->t('Use upper-case OR to get more results. Example: cat OR dog (content contains either "cat" or "dog").'),
|
||||
$this->t('You can use upper-case AND to require all words, but this is the same as the default behavior. Example: cat AND dog (same as cat dog, content must contain both "cat" and "dog").'),
|
||||
$this->t('Use quotes to search for a phrase. Example: "the cat eats mice".'),
|
||||
$this->t('You can precede keywords by - to exclude them; you must still have at least one "positive" keyword. Example: cat -dog (content must contain cat and cannot contain dog).'),
|
||||
$help = [
|
||||
'list' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [
|
||||
$this->t('Search looks for exact, case-insensitive keywords; keywords shorter than a minimum length are ignored.'),
|
||||
$this->t('Use upper-case OR to get more results. Example: cat OR dog (content contains either "cat" or "dog").'),
|
||||
$this->t('You can use upper-case AND to require all words, but this is the same as the default behavior. Example: cat AND dog (same as cat dog, content must contain both "cat" and "dog").'),
|
||||
$this->t('Use quotes to search for a phrase. Example: "the cat eats mice".'),
|
||||
$this->t('You can precede keywords by - to exclude them; you must still have at least one "positive" keyword. Example: cat -dog (content must contain cat and cannot contain dog).'),
|
||||
],
|
||||
],
|
||||
]];
|
||||
];
|
||||
|
||||
return $help;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\search\Plugin\views\argument;
|
||||
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\ViewExecutable;
|
||||
|
@ -76,7 +77,7 @@ class Search extends ArgumentPluginBase {
|
|||
else {
|
||||
$search_index = $this->ensureMyTable();
|
||||
|
||||
$search_condition = db_and();
|
||||
$search_condition = new Condition('AND');
|
||||
|
||||
// Create a new join to relate the 'search_total' table to our current 'search_index' table.
|
||||
$definition = [
|
||||
|
@ -96,7 +97,7 @@ class Search extends ArgumentPluginBase {
|
|||
$search_dataset = $this->query->addTable('node_search_dataset');
|
||||
$conditions = $this->searchQuery->conditions();
|
||||
$condition_conditions =& $conditions->conditions();
|
||||
foreach ($condition_conditions as $key => &$condition) {
|
||||
foreach ($condition_conditions as $key => &$condition) {
|
||||
// Make sure we just look at real conditions.
|
||||
if (is_numeric($key)) {
|
||||
// Replace the conditions with the table alias of views.
|
||||
|
@ -109,7 +110,7 @@ class Search extends ArgumentPluginBase {
|
|||
// Add the keyword conditions, as is done in
|
||||
// SearchQuery::prepareAndNormalize(), but simplified because we are
|
||||
// only concerned with relevance ranking so we do not need to normalize.
|
||||
$or = db_or();
|
||||
$or = new Condition('OR');
|
||||
foreach ($words as $word) {
|
||||
$or->condition("$search_index.word", $word);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\search\Plugin\views\filter;
|
||||
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\views\Plugin\views\filter\FilterPluginBase;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
|
@ -33,6 +34,8 @@ class Search extends FilterPluginBase {
|
|||
|
||||
/**
|
||||
* TRUE if the search query has been parsed.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $parsed = FALSE;
|
||||
|
||||
|
@ -150,7 +153,7 @@ class Search extends FilterPluginBase {
|
|||
else {
|
||||
$search_index = $this->ensureMyTable();
|
||||
|
||||
$search_condition = db_and();
|
||||
$search_condition = new Condition('AND');
|
||||
|
||||
// Create a new join to relate the 'search_total' table to our current
|
||||
// 'search_index' table.
|
||||
|
@ -171,7 +174,7 @@ class Search extends FilterPluginBase {
|
|||
$search_dataset = $this->query->addTable('node_search_dataset');
|
||||
$conditions = $this->searchQuery->conditions();
|
||||
$condition_conditions =& $conditions->conditions();
|
||||
foreach ($condition_conditions as $key => &$condition) {
|
||||
foreach ($condition_conditions as $key => &$condition) {
|
||||
// Make sure we just look at real conditions.
|
||||
if (is_numeric($key)) {
|
||||
// Replace the conditions with the table alias of views.
|
||||
|
@ -184,7 +187,7 @@ class Search extends FilterPluginBase {
|
|||
// Add the keyword conditions, as is done in
|
||||
// SearchQuery::prepareAndNormalize(), but simplified because we are
|
||||
// only concerned with relevance ranking so we do not need to normalize.
|
||||
$or = db_or();
|
||||
$or = new Condition('OR');
|
||||
foreach ($words as $word) {
|
||||
$or->condition("$search_index.word", $word);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
|||
use Drupal\Core\Form\ConfigFormBaseTrait;
|
||||
use Drupal\Core\Form\FormInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Messenger\MessengerInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -42,6 +43,13 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
*/
|
||||
protected $searchManager;
|
||||
|
||||
/**
|
||||
* The messenger.
|
||||
*
|
||||
* @var \Drupal\Core\Messenger\MessengerInterface
|
||||
*/
|
||||
protected $messenger;
|
||||
|
||||
/**
|
||||
* Constructs a new SearchPageListBuilder object.
|
||||
*
|
||||
|
@ -53,11 +61,14 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
* The search plugin manager.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The factory for configuration objects.
|
||||
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
|
||||
* The messenger.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, SearchPluginManager $search_manager, ConfigFactoryInterface $config_factory) {
|
||||
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, SearchPluginManager $search_manager, ConfigFactoryInterface $config_factory, MessengerInterface $messenger) {
|
||||
parent::__construct($entity_type, $storage);
|
||||
$this->configFactory = $config_factory;
|
||||
$this->searchManager = $search_manager;
|
||||
$this->messenger = $messenger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,7 +79,8 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
$entity_type,
|
||||
$container->get('entity.manager')->getStorage($entity_type->id()),
|
||||
$container->get('plugin.manager.search'),
|
||||
$container->get('config.factory')
|
||||
$container->get('config.factory'),
|
||||
$container->get('messenger')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -145,7 +157,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
$status = $entity->getPlugin()->indexStatus();
|
||||
$row['progress']['#markup'] = $this->t('%num_indexed of %num_total indexed', [
|
||||
'%num_indexed' => $status['total'] - $status['remaining'],
|
||||
'%num_total' => $status['total']
|
||||
'%num_total' => $status['total'],
|
||||
]);
|
||||
}
|
||||
else {
|
||||
|
@ -215,7 +227,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
'#open' => TRUE,
|
||||
];
|
||||
$form['indexing_settings']['info'] = [
|
||||
'#markup' => $this->t("<p>Search pages that use an index may use the default index provided by the Search module, or they may use a different indexing mechanism. These settings are for the default index. <em>Changing these settings will cause the default search index to be rebuilt to reflect the new settings. Searching will continue to work, based on the existing index, but new content won't be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>")
|
||||
'#markup' => $this->t("<p>Search pages that use an index may use the default index provided by the Search module, or they may use a different indexing mechanism. These settings are for the default index. <em>Changing these settings will cause the default search index to be rebuilt to reflect the new settings. Searching will continue to work, based on the existing index, but new content won't be indexed until all existing content has been re-indexed.</em></p><p><em>The default settings should be appropriate for the majority of sites.</em></p>"),
|
||||
];
|
||||
$form['indexing_settings']['minimum_word_size'] = [
|
||||
'#type' => 'number',
|
||||
|
@ -229,7 +241,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Simple CJK handling'),
|
||||
'#default_value' => $search_settings->get('index.overlap_cjk'),
|
||||
'#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.')
|
||||
'#description' => $this->t('Whether to apply a simple Chinese/Japanese/Korean tokenizer based on overlapping sequences. Turn this off if you want to use an external preprocessor for this instead. Does not affect other languages.'),
|
||||
];
|
||||
|
||||
// Indexing settings:
|
||||
|
@ -333,7 +345,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
$search_settings->set('index.overlap_cjk', $form_state->getValue('overlap_cjk'));
|
||||
// Specifically mark items in the default index for reindexing, since
|
||||
// these settings are used in the search_index() function.
|
||||
drupal_set_message($this->t('The default search index will be rebuilt.'));
|
||||
$this->messenger->addStatus($this->t('The default search index will be rebuilt.'));
|
||||
search_mark_for_reindex();
|
||||
}
|
||||
|
||||
|
@ -342,7 +354,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
->set('logging', $form_state->getValue('logging'))
|
||||
->save();
|
||||
|
||||
drupal_set_message($this->t('The configuration options have been saved.'));
|
||||
$this->messenger->addStatus($this->t('The configuration options have been saved.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\search;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Database\Query\Condition;
|
||||
use Drupal\Core\Database\Query\SelectExtender;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
|
||||
|
@ -205,7 +205,7 @@ class SearchQuery extends SelectExtender {
|
|||
$this->addTag('search_' . $type);
|
||||
|
||||
// Initialize conditions and status.
|
||||
$this->conditions = db_and();
|
||||
$this->conditions = new Condition('AND');
|
||||
$this->status = 0;
|
||||
|
||||
return $this;
|
||||
|
@ -313,7 +313,7 @@ class SearchQuery extends SelectExtender {
|
|||
}
|
||||
$has_or = TRUE;
|
||||
$has_new_scores = FALSE;
|
||||
$queryor = db_or();
|
||||
$queryor = new Condition('OR');
|
||||
foreach ($key as $or) {
|
||||
list($num_new_scores) = $this->parseWord($or);
|
||||
$has_new_scores |= $num_new_scores;
|
||||
|
@ -363,7 +363,7 @@ class SearchQuery extends SelectExtender {
|
|||
$split = explode(' ', $word);
|
||||
foreach ($split as $s) {
|
||||
$num = is_numeric($s);
|
||||
if ($num || Unicode::strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) {
|
||||
if ($num || mb_strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) {
|
||||
if (!isset($this->words[$s])) {
|
||||
$this->words[$s] = $s;
|
||||
$num_new_scores++;
|
||||
|
@ -401,7 +401,7 @@ class SearchQuery extends SelectExtender {
|
|||
}
|
||||
|
||||
// Build the basic search query: match the entered keywords.
|
||||
$or = db_or();
|
||||
$or = new Condition('OR');
|
||||
foreach ($this->words as $word) {
|
||||
$or->condition('i.word', $word);
|
||||
}
|
||||
|
@ -570,10 +570,9 @@ class SearchQuery extends SelectExtender {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Add arguments for the keyword relevance normalization number.
|
||||
$normalization = 1.0 / $this->normalize;
|
||||
for ($i = 0; $i < $this->relevance_count; $i++ ) {
|
||||
for ($i = 0; $i < $this->relevance_count; $i++) {
|
||||
$this->scoresArguments[':normalization_' . $i] = $normalization;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\search\Tests;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
|
||||
/**
|
||||
* Defines the common search test code.
|
||||
|
@ -85,7 +85,7 @@ abstract class SearchTestBase extends WebTestBase {
|
|||
// We have not found a form which contained all fields of $edit and
|
||||
// the submit button.
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
$this->fail(new FormattableMarkup('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
}
|
||||
$this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit]));
|
||||
$this->fail(format_string('Found the requested form fields at @path', ['@path' => $path]));
|
||||
|
|
|
@ -74,8 +74,8 @@ class ViewsSearchQuery extends SearchQuery {
|
|||
$conditions =& $condition['field']->conditions();
|
||||
foreach ($conditions as $key => &$subcondition) {
|
||||
if (is_numeric($key)) {
|
||||
// As conditions can have subconditions, for example db_or(), the
|
||||
// function has to be called recursively.
|
||||
// As conditions can be nested, the function has to be called
|
||||
// recursively.
|
||||
$this->conditionReplaceString($search, $replace, $subcondition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
|
||||
/**
|
||||
* Form controller for search_embedded_form form.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SearchEmbeddedForm extends FormBase {
|
||||
|
||||
|
@ -48,7 +50,7 @@ class SearchEmbeddedForm extends FormBase {
|
|||
$state = \Drupal::state();
|
||||
$submit_count = (int) $state->get('search_embedded_form.submit_count');
|
||||
$state->set('search_embedded_form.submit_count', $submit_count + 1);
|
||||
drupal_set_message($this->t('Test form was submitted'));
|
||||
$this->messenger()->addStatus($this->t('Test form was submitted'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,5 +5,4 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- test_page_test
|
||||
|
||||
- drupal:test_page_test
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\search_extra_type\Plugin\Search;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Render\FormattableMarkup;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\UrlGeneratorTrait;
|
||||
use Drupal\Core\Url;
|
||||
|
@ -59,7 +59,7 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
'link' => Url::fromRoute('test_page_test.test_page')->toString(),
|
||||
'type' => 'Dummy result type',
|
||||
'title' => 'Dummy title',
|
||||
'snippet' => SafeMarkup::format("Dummy search snippet to display. Keywords: @keywords\n\nConditions: @search_parameters", ['@keywords' => $this->keywords, '@search_parameters' => print_r($this->searchParameters, TRUE)]),
|
||||
'snippet' => new FormattableMarkup("Dummy search snippet to display. Keywords: @keywords\n\nConditions: @search_parameters", ['@keywords' => $this->keywords, '@search_parameters' => print_r($this->searchParameters, TRUE)]),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
$pager = [
|
||||
'#type' => 'pager',
|
||||
];
|
||||
$output['suffix']['#markup'] = '</ol>' . drupal_render($pager);
|
||||
$output['suffix']['#markup'] = '</ol>' . \Drupal::service('renderer')->render($pager);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ function search_langcode_test_search_preprocess($text, $langcode = NULL) {
|
|||
// Prints the langcode for testPreprocessLangcode() and adds some
|
||||
// extra text.
|
||||
else {
|
||||
drupal_set_message('Langcode Preprocess Test: ' . $langcode);
|
||||
\Drupal::messenger()->addStatus('Langcode Preprocess Test: ' . $langcode);
|
||||
$text .= 'Additional text';
|
||||
}
|
||||
}
|
||||
// Prints the langcode for testPreprocessLangcode().
|
||||
elseif (isset($langcode)) {
|
||||
drupal_set_message('Langcode Preprocess Test: ' . $langcode);
|
||||
\Drupal::messenger()->addStatus('Langcode Preprocess Test: ' . $langcode);
|
||||
|
||||
// Preprocessing for the excerpt test.
|
||||
if ($langcode == 'ex') {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\search\Functional\Rest\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonAnonTest extends SearchPageResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\search\Functional\Rest\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonBasicAuthTest extends SearchPageResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal', 'basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Hal;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\search\Functional\Rest\SearchPageResourceTestBase;
|
||||
|
||||
/**
|
||||
* @group hal
|
||||
*/
|
||||
class SearchPageHalJsonCookieTest extends SearchPageResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['hal'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'hal_json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/hal+json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageJsonAnonTest extends SearchPageResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageJsonBasicAuthTest extends SearchPageResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageJsonCookieTest extends SearchPageResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'application/json';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
|
||||
|
||||
abstract class SearchPageResourceTestBase extends EntityResourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $entityTypeId = 'search_page';
|
||||
|
||||
/**
|
||||
* @var \Drupal\search\SearchPageInterface
|
||||
*/
|
||||
protected $entity;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUpAuthorization($method) {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$this->grantPermissionsToTestedRole(['access content']);
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
case 'PATCH':
|
||||
case 'DELETE':
|
||||
$this->grantPermissionsToTestedRole(['administer search']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createEntity() {
|
||||
$search_page = SearchPage::create([
|
||||
'id' => 'hinode_search',
|
||||
'plugin' => 'node_search',
|
||||
'label' => 'Search of magnetic activity of the Sun',
|
||||
'path' => 'sun',
|
||||
]);
|
||||
$search_page->save();
|
||||
return $search_page;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedNormalizedEntity() {
|
||||
return [
|
||||
'configuration' => [
|
||||
'rankings' => [],
|
||||
],
|
||||
'dependencies' => [
|
||||
'module' => ['node'],
|
||||
],
|
||||
'id' => 'hinode_search',
|
||||
'label' => 'Search of magnetic activity of the Sun',
|
||||
'langcode' => 'en',
|
||||
'path' => 'sun',
|
||||
'plugin' => 'node_search',
|
||||
'status' => TRUE,
|
||||
'uuid' => $this->entity->uuid(),
|
||||
'weight' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getNormalizedPostEntity() {
|
||||
// @todo Update in https://www.drupal.org/node/2300677.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessMessage($method) {
|
||||
if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
return "The 'access content' permission is required.";
|
||||
|
||||
default:
|
||||
return parent::getExpectedUnauthorizedAccessMessage($method);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExpectedUnauthorizedAccessCacheability() {
|
||||
// @see \Drupal\search\SearchPageAccessControlHandler::checkAccess()
|
||||
return parent::getExpectedUnauthorizedAccessCacheability()
|
||||
->addCacheTags(['config:search.page.hinode_search']);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageXmlAnonTest extends SearchPageResourceTestBase {
|
||||
|
||||
use AnonResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageXmlBasicAuthTest extends SearchPageResourceTestBase {
|
||||
|
||||
use BasicAuthResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['basic_auth'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'basic_auth';
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional\Rest;
|
||||
|
||||
use Drupal\Tests\rest\Functional\CookieResourceTestTrait;
|
||||
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* @group rest
|
||||
*/
|
||||
class SearchPageXmlCookieTest extends SearchPageResourceTestBase {
|
||||
|
||||
use CookieResourceTestTrait;
|
||||
use XmlEntityNormalizationQuirksTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $format = 'xml';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $mimeType = 'text/xml; charset=UTF-8';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $auth = 'cookie';
|
||||
|
||||
}
|
|
@ -1,13 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Indexes content and tests the advanced search form.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchAdvancedSearchFormTest extends SearchTestBase {
|
||||
class SearchAdvancedSearchFormTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'search', 'dblog'];
|
||||
|
||||
/**
|
||||
* A node to use for testing.
|
||||
|
@ -18,6 +25,10 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
@ -53,14 +64,14 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
|
||||
// Search for the title of the node with a POST query.
|
||||
$edit = ['or' => $this->node->label()];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
$this->assertText($this->node->label(), 'Basic page node is found with POST query.');
|
||||
|
||||
// Search by node type.
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[page]' => 'page']), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[page]' => 'page']), 'edit-submit--2');
|
||||
$this->assertText($this->node->label(), 'Basic page node is found with POST query and type:page.');
|
||||
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[article]' => 'article']), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[article]' => 'article']), 'edit-submit--2');
|
||||
$this->assertText('search yielded no results', 'Article node is not found with POST query and type:article.');
|
||||
}
|
||||
|
||||
|
@ -75,7 +86,7 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
'negative' => 'fish snake',
|
||||
'type[page]' => 'page',
|
||||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
|
||||
// Test that the encoded query appears in the page title. Only test the
|
||||
// part not including the quote, because assertText() cannot seem to find
|
||||
|
@ -86,11 +97,11 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
foreach ($edit as $key => $value) {
|
||||
if ($key != 'type[page]') {
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertTrue(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is set to $value");
|
||||
$this->assertTrue(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is set to $value");
|
||||
}
|
||||
else {
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), "Field $key is checked");
|
||||
$this->assertTrue(isset($elements[0]) && !empty($elements[0]->getAttribute('checked')), "Field $key is checked");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,12 +109,12 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
// search box, and verify that the advanced form is not filled out.
|
||||
// (It shouldn't be filled out unless you submit values in those fields.)
|
||||
$edit2 = ['keys' => 'cat dog OR gerbil -fish -snake'];
|
||||
$this->drupalPostForm('search/node', $edit2, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit2, 'edit-submit--2');
|
||||
$this->assertText('Search for cat dog OR gerbil -fish -snake');
|
||||
foreach ($edit as $key => $value) {
|
||||
if ($key != 'type[page]') {
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertFalse(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is not set to $value");
|
||||
$this->assertFalse(isset($elements[0]) && $elements[0]->getValue() == $value, "Field $key is not set to $value");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests if the search form block is available.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchBlockTest extends SearchTestBase {
|
||||
class SearchBlockTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block'];
|
||||
protected static $modules = ['block', 'node', 'search', 'dblog'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -31,7 +31,7 @@ class SearchBlockTest extends SearchTestBase {
|
|||
|
||||
// Test availability of the search block in the admin "Place blocks" list.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->clickLinkPartialName('Place block');
|
||||
$this->getSession()->getPage()->findLink('Place block')->click();
|
||||
$this->assertLinkByHref('/admin/structure/block/add/search_form_block/classy', 0,
|
||||
'Did not find the search block in block candidate list.');
|
||||
|
||||
|
@ -47,14 +47,14 @@ class SearchBlockTest extends SearchTestBase {
|
|||
|
||||
// Test a normal search via the block form, from the front page.
|
||||
$terms = ['keys' => 'test'];
|
||||
$this->submitGetForm('', $terms, t('Search'));
|
||||
$this->drupalPostForm('', $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Your search yielded no results');
|
||||
|
||||
// Test a search from the block on a 404 page.
|
||||
$this->drupalGet('foo');
|
||||
$this->assertResponse(404);
|
||||
$this->submitGetForm(NULL, $terms, t('Search'));
|
||||
$this->drupalPostForm(NULL, $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Your search yielded no results');
|
||||
|
||||
|
@ -62,7 +62,7 @@ class SearchBlockTest extends SearchTestBase {
|
|||
$visibility['request_path']['pages'] = 'search';
|
||||
$block->setVisibilityConfig('request_path', $visibility['request_path']);
|
||||
|
||||
$this->submitGetForm('', $terms, t('Search'));
|
||||
$this->drupalPostForm('', $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Your search yielded no results');
|
||||
|
||||
|
@ -78,7 +78,7 @@ class SearchBlockTest extends SearchTestBase {
|
|||
|
||||
// Test an empty search via the block form, from the front page.
|
||||
$terms = ['keys' => ''];
|
||||
$this->submitGetForm('', $terms, t('Search'));
|
||||
$this->drupalPostForm('', $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Please enter some keywords');
|
||||
|
||||
|
@ -92,16 +92,16 @@ class SearchBlockTest extends SearchTestBase {
|
|||
|
||||
// Test that after entering a too-short keyword in the form, you can then
|
||||
// search again with a longer keyword. First test using the block form.
|
||||
$this->submitGetForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
|
||||
$this->drupalPostForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
|
||||
$this->assertText('You must include at least one keyword to match in the content', 'Keyword message is displayed when searching for short word');
|
||||
$this->assertNoText(t('Please enter some keywords'), 'With short word entered, no keywords message is not displayed');
|
||||
$this->submitGetForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), 'search-block-form');
|
||||
$this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], 'search-block-form');
|
||||
$this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
|
||||
|
||||
// Same test again, using the search page form for the second search this
|
||||
// time.
|
||||
$this->submitGetForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
|
||||
$this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], [], 'search-form');
|
||||
$this->drupalPostForm('node', ['keys' => $this->randomMachineName(1)], t('Search'));
|
||||
$this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'), [], 'search-form');
|
||||
$this->assertNoText('You must include at least one keyword to match in the content', 'Keyword message is not displayed when searching for long word after short word search');
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace Drupal\Tests\search\Functional;
|
|||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that comment count display toggles properly on comment status of node.
|
||||
|
@ -17,16 +18,14 @@ use Drupal\comment\Tests\CommentTestTrait;
|
|||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchCommentCountToggleTest extends SearchTestBase {
|
||||
class SearchCommentCountToggleTest extends BrowserTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'comment'];
|
||||
protected static $modules = ['node', 'comment', 'search', 'dblog'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
|
@ -45,6 +44,8 @@ class SearchCommentCountToggleTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Create searching user.
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'post comments', 'skip comment approval']);
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Behat\Mink\Exception\ResponseTextException;
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
use Drupal\user\RoleInterface;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
|
@ -13,16 +16,15 @@ use Drupal\filter\Entity\FilterFormat;
|
|||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchCommentTest extends SearchTestBase {
|
||||
class SearchCommentTest extends BrowserTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['filter', 'node', 'comment'];
|
||||
protected static $modules = ['filter', 'node', 'comment', 'search'];
|
||||
|
||||
/**
|
||||
* Test subject for comments.
|
||||
|
@ -55,6 +57,9 @@ class SearchCommentTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
$full_html_format = FilterFormat::create([
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
|
@ -298,15 +303,18 @@ class SearchCommentTest extends SearchTestBase {
|
|||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
|
||||
if ($assume_access) {
|
||||
$expected_node_result = $this->assertText($this->node->label());
|
||||
$expected_comment_result = $this->assertText($this->commentSubject);
|
||||
try {
|
||||
if ($assume_access) {
|
||||
$this->assertSession()->pageTextContains($this->node->label());
|
||||
$this->assertSession()->pageTextContains($this->commentSubject);
|
||||
}
|
||||
else {
|
||||
$this->assertSession()->pageTextContains(t('Your search yielded no results.'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$expected_node_result = $this->assertText(t('Your search yielded no results.'));
|
||||
$expected_comment_result = $this->assertText(t('Your search yielded no results.'));
|
||||
catch (ResponseTextException $exception) {
|
||||
$this->fail($message);
|
||||
}
|
||||
$this->assertTrue($expected_node_result && $expected_comment_result, $message);
|
||||
}
|
||||
|
||||
/**
|
|
@ -1,23 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verify the search config settings form.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchConfigSettingsFormTest extends SearchTestBase {
|
||||
class SearchConfigSettingsFormTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['block', 'search_extra_type', 'test_page_test'];
|
||||
protected static $modules = ['block', 'dblog', 'node', 'search', 'search_extra_type', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* User who can search and administer search.
|
||||
|
@ -36,6 +35,8 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Log in as a user that can create and search content.
|
||||
$this->searchUser = $this->drupalCreateUser(['search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks', 'access site reports']);
|
||||
$this->drupalLogin($this->searchUser);
|
||||
|
@ -47,7 +48,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
// also needs the word "pizza" so we can use it as the search keyword.
|
||||
$body_key = 'body[0][value]';
|
||||
$edit[$body_key] = \Drupal::l($node->label(), $node->urlInfo()) . ' pizza sandwich';
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
|
||||
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
search_update_totals();
|
||||
|
@ -174,10 +175,10 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
// Run a search from the search block on the node page. Verify you get
|
||||
// to this plugin's search results page.
|
||||
$terms = ['keys' => $info['keys']];
|
||||
$this->submitGetForm('node', $terms, t('Search'));
|
||||
$this->drupalPostForm('node', $terms, t('Search'));
|
||||
$current = $this->getURL();
|
||||
$expected = \Drupal::url('search.view_' . $entity->id(), [], ['query' => ['keys' => $info['keys']], 'absolute' => TRUE]);
|
||||
$this->assertEqual( $current, $expected, 'Block redirected to right search page');
|
||||
$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');
|
||||
|
@ -217,9 +218,9 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
public function testDefaultSearchPageOrdering() {
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
|
||||
$this->assertIdentical((string) $elements[0]['href'], \Drupal::url('search.view_node_search'));
|
||||
$this->assertIdentical((string) $elements[1]['href'], \Drupal::url('search.view_dummy_search_type'));
|
||||
$this->assertIdentical((string) $elements[2]['href'], \Drupal::url('search.view_user_search'));
|
||||
$this->assertIdentical($elements[0]->getAttribute('href'), \Drupal::url('search.view_node_search'));
|
||||
$this->assertIdentical($elements[1]->getAttribute('href'), \Drupal::url('search.view_dummy_search_type'));
|
||||
$this->assertIdentical($elements[2]->getAttribute('href'), \Drupal::url('search.view_user_search'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,8 +273,8 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
// Ensure both search pages have their tabs displayed.
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
|
||||
$this->assertIdentical((string) $elements[0]['href'], Url::fromRoute('search.view_' . $first_id)->toString());
|
||||
$this->assertIdentical((string) $elements[1]['href'], Url::fromRoute('search.view_' . $second_id)->toString());
|
||||
$this->assertIdentical($elements[0]->getAttribute('href'), Url::fromRoute('search.view_' . $first_id)->toString());
|
||||
$this->assertIdentical($elements[1]->getAttribute('href'), Url::fromRoute('search.view_' . $second_id)->toString());
|
||||
|
||||
// Switch the weight of the search pages and check the order of the tabs.
|
||||
$edit = [
|
||||
|
@ -283,8 +284,8 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
$this->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', [':class' => 'tabs primary']);
|
||||
$this->assertIdentical((string) $elements[0]['href'], Url::fromRoute('search.view_' . $second_id)->toString());
|
||||
$this->assertIdentical((string) $elements[1]['href'], Url::fromRoute('search.view_' . $first_id)->toString());
|
||||
$this->assertIdentical($elements[0]->getAttribute('href'), Url::fromRoute('search.view_' . $second_id)->toString());
|
||||
$this->assertIdentical($elements[1]->getAttribute('href'), Url::fromRoute('search.view_' . $first_id)->toString());
|
||||
|
||||
// Check the initial state of the search pages.
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
|
@ -396,7 +397,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
*/
|
||||
protected function setDefaultThroughUi($entity_id) {
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
preg_match('|href="([^"]+' . $entity_id . '/set-default[^"]+)"|', $this->getRawContent(), $matches);
|
||||
preg_match('|href="([^"]+' . $entity_id . '/set-default[^"]+)"|', $this->getSession()->getPage()->getContent(), $matches);
|
||||
|
||||
$this->drupalGet($this->getAbsoluteUrl($matches[1]));
|
||||
}
|
|
@ -3,24 +3,25 @@
|
|||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests searching with date filters that exclude some translations.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchDateIntervalTest extends SearchTestBase {
|
||||
class SearchDateIntervalTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language', 'search_date_query_alter'];
|
||||
protected static $modules = ['language', 'search_date_query_alter', 'node', 'search'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verifies that a form embedded in search results works.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchEmbedFormTest extends SearchTestBase {
|
||||
class SearchEmbedFormTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['search_embedded_form'];
|
||||
protected static $modules = ['node', 'search', 'search_embedded_form'];
|
||||
|
||||
/**
|
||||
* Node used for testing.
|
||||
|
@ -33,6 +33,8 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create a user and a node, and update the search index.
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'administer nodes']);
|
||||
$this->drupalLogin($test_user);
|
|
@ -2,16 +2,26 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that searching for a phrase gets the correct page count.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchExactTest extends SearchTestBase {
|
||||
class SearchExactTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* Tests that the correct number of pager links are found for both keywords and phrases.
|
||||
*/
|
||||
public function testExactQuery() {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Log in with sufficient privileges.
|
||||
$user = $this->drupalCreateUser(['create page content', 'search content']);
|
||||
$this->drupalLogin($user);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Verify the search without keywords set and extra conditions.
|
||||
|
@ -13,14 +14,12 @@ use Drupal\Component\Utility\Html;
|
|||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchKeywordsConditionsTest extends SearchTestBase {
|
||||
class SearchKeywordsConditionsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment', 'search_extra_type', 'test_page_test'];
|
||||
protected static $modules = ['comment', 'search', 'search_extra_type', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests advanced search with different languages added.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchLanguageTest extends SearchTestBase {
|
||||
class SearchLanguageTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
protected static $modules = ['language', 'node', 'search'];
|
||||
|
||||
/**
|
||||
* Array of nodes available to search.
|
||||
|
@ -29,6 +28,8 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
@ -99,12 +100,12 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
$this->assertText(t('French'), 'French is a possible choice.');
|
||||
|
||||
// Ensure selecting no language does not make the query different.
|
||||
$this->drupalPostForm('search/node', [], t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', [], 'edit-submit--2');
|
||||
$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 = ['language[fr]' => TRUE];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
// Get the redirected URL.
|
||||
$url = $this->getUrl();
|
||||
$parts = parse_url($url);
|
||||
|
@ -113,7 +114,7 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
|
||||
// Search for keyword node and language filter as Spanish.
|
||||
$edit = ['keys' => 'node', 'language[es]' => TRUE];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
// 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');
|
|
@ -4,13 +4,14 @@ namespace Drupal\Tests\search\Functional;
|
|||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests entities with multilingual fields.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchMultilingualEntityTest extends SearchTestBase {
|
||||
class SearchMultilingualEntityTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* List of searchable nodes.
|
||||
|
@ -26,11 +27,16 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
*/
|
||||
protected $plugin;
|
||||
|
||||
public static $modules = ['language', 'locale', 'comment'];
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['language', 'locale', 'comment', 'node', 'search'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create a user who can administer search, do searches, see the status
|
||||
// report, and administer cron. Log in.
|
||||
$user = $this->drupalCreateUser(['administer search', 'search content', 'use advanced search', 'access content', 'access site reports', 'administer site configuration']);
|
||||
|
@ -78,16 +84,11 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
// After the third node, we don't care what the settings are. But we
|
||||
// need to have at least 5 to make sure the throttling is working
|
||||
// correctly. So, let's make 8 total.
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
];
|
||||
$this->searchableNodes = [];
|
||||
foreach ($nodes as $setting) {
|
||||
|
|
|
@ -2,12 +2,19 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests search functionality with diacritics.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNodeDiacriticsTest extends SearchTestBase {
|
||||
class SearchNodeDiacriticsTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to use advanced search.
|
||||
|
@ -18,6 +25,9 @@ class SearchNodeDiacriticsTest extends SearchTestBase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
node_access_rebuild();
|
||||
|
||||
// Create a test user and log in.
|
||||
|
|
|
@ -2,12 +2,19 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests search functionality with punctuation and HTML entities.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNodePunctuationTest extends SearchTestBase {
|
||||
class SearchNodePunctuationTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to use advanced search.
|
||||
|
@ -18,8 +25,10 @@ class SearchNodePunctuationTest extends SearchTestBase {
|
|||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
node_access_rebuild();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
node_access_rebuild();
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests search index is updated properly when nodes are removed or updated.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
||||
class SearchNodeUpdateAndDeletionTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [];
|
||||
protected static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to access and search content.
|
||||
|
@ -26,6 +26,8 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
@ -39,7 +41,8 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
$node = $this->drupalCreateNode([
|
||||
'title' => 'Someone who says Ni!',
|
||||
'body' => [['value' => "We are the knights who say Ni!"]],
|
||||
'type' => 'page']);
|
||||
'type' => 'page',
|
||||
]);
|
||||
|
||||
$node_search_plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Update the search index.
|
||||
|
@ -73,7 +76,8 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
$node = $this->drupalCreateNode([
|
||||
'title' => 'No dragons here',
|
||||
'body' => [['value' => 'Again: No dragons here']],
|
||||
'type' => 'page']);
|
||||
'type' => 'page',
|
||||
]);
|
||||
|
||||
$node_search_plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Update the search index.
|
|
@ -1,15 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests that numbers can be searched with more complex matching.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNumberMatchingTest extends SearchTestBase {
|
||||
class SearchNumberMatchingTest extends BrowserTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['dblog', 'node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer nodes.
|
||||
*
|
||||
|
@ -47,6 +57,8 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
|
@ -1,15 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Tests that numbers can be searched.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNumbersTest extends SearchTestBase {
|
||||
class SearchNumbersTest extends BrowserTestBase {
|
||||
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['dblog', 'node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer nodes.
|
||||
*
|
||||
|
@ -53,6 +63,8 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
|
@ -1,15 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Tests the search_page entity cache tags on the search results pages.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchPageCacheTagsTest extends SearchTestBase {
|
||||
class SearchPageCacheTagsTest extends BrowserTestBase {
|
||||
|
||||
use AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -36,6 +45,8 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create user.
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access user profiles']);
|
||||
|
||||
|
@ -100,8 +111,8 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->drupalGet('search/user');
|
||||
$this->assertCacheTag('config:search.page.user_search');
|
||||
$this->assertCacheTag('user_list');
|
||||
$this->assertNoCacheTag('search_index');
|
||||
$this->assertNoCacheTag('search_index:user_search');
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index');
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search');
|
||||
|
||||
// User search results.
|
||||
$edit['keys'] = $this->searchingUser->getUsername();
|
||||
|
@ -109,8 +120,8 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->assertCacheTag('config:search.page.user_search');
|
||||
$this->assertCacheTag('user_list');
|
||||
$this->assertCacheTag('user:2');
|
||||
$this->assertNoCacheTag('search_index');
|
||||
$this->assertNoCacheTag('search_index:user_search');
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index');
|
||||
$this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'search_index:user_search');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,7 +133,6 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->container->get('module_installer')->install(['field_ui', 'entity_reference']);
|
||||
$this->resetAll();
|
||||
|
||||
|
||||
// Creates a new content type that will have an entity reference.
|
||||
$type_name = 'entity_reference_test';
|
||||
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
|
||||
|
@ -154,7 +164,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
// reference field.
|
||||
$edit = [
|
||||
'title[0][value]' => 'Llama shop',
|
||||
'field_test__ref[0][target_id]' => $this->node->getTitle()
|
||||
'field_test__ref[0][target_id]' => $this->node->getTitle(),
|
||||
];
|
||||
$this->drupalPostForm('node/add/' . $type->id(), $edit, t('Save'));
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests if the result page can be overridden.
|
||||
*
|
||||
|
@ -10,14 +12,12 @@ namespace Drupal\Tests\search\Functional;
|
|||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchPageOverrideTest extends SearchTestBase {
|
||||
class SearchPageOverrideTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['search_extra_type'];
|
||||
protected static $modules = ['search', 'search_extra_type'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer search.
|
||||
|
|
|
@ -1,16 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests the search help text and search page text.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchPageTextTest extends SearchTestBase {
|
||||
class SearchPageTextTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['block', 'node', 'search'];
|
||||
|
||||
/**
|
||||
* A user with permission to use advanced search.
|
||||
*
|
||||
|
@ -18,19 +25,14 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
*/
|
||||
protected $searchingUser;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['block'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create user.
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access user profiles', 'use advanced search']);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
|
@ -90,7 +92,7 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
$search_terms = 'Hear nothing > "see nothing" `feel' . " '1982.";
|
||||
$edit['keys'] = $search_terms;
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$actual_title = (string) current($this->xpath('//title'));
|
||||
$actual_title = $this->xpath('//title')[0]->getText();
|
||||
$this->assertEqual($actual_title, Html::decodeEntities(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)])), 'Search page title is correct');
|
||||
|
||||
$edit['keys'] = $this->searchingUser->getUsername();
|
||||
|
@ -133,9 +135,9 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
|
||||
// Make sure the "Please enter some keywords" message is NOT displayed if
|
||||
// you use "or" words or phrases in Advanced Search.
|
||||
$this->drupalPostForm('search/node', ['or' => $this->randomMachineName() . ' ' . $this->randomMachineName()], t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', ['or' => $this->randomMachineName() . ' ' . $this->randomMachineName()], 'edit-submit--2');
|
||||
$this->assertNoText(t('Please enter some keywords'), 'With advanced OR keywords entered, no keywords message is not displayed on node page');
|
||||
$this->drupalPostForm('search/node', ['phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'], t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', ['phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'], 'edit-submit--2');
|
||||
$this->assertNoText(t('Please enter some keywords'), 'With advanced phrase entered, no keywords message is not displayed on node page');
|
||||
|
||||
// Verify that if you search for a too-short keyword, you get the right
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the search preprocessing uses the correct language code.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchPreprocessLangcodeTest extends SearchTestBase {
|
||||
class SearchPreprocessLangcodeTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['search_langcode_test'];
|
||||
protected static $modules = ['node', 'search', 'search_langcode_test'];
|
||||
|
||||
/**
|
||||
* Test node for searching.
|
||||
|
@ -26,6 +26,8 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
$web_user = $this->drupalCreateUser([
|
||||
'create page content',
|
||||
'edit own page content',
|
||||
|
@ -54,7 +56,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
// function. If you search for text that is in the node, preprocess is
|
||||
// not invoked on the node during the search excerpt generation.
|
||||
$edit = ['or' => 'Additional text'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
|
||||
// Checks if the langcode message has been set by hook_search_preprocess().
|
||||
$this->assertText('Langcode Preprocess Test: en');
|
||||
|
@ -81,7 +83,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
|
||||
// Search for the title of the node with a POST query.
|
||||
$edit = ['or' => 'testing'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
|
||||
// Check if the node has been found.
|
||||
$this->assertText('Search results');
|
||||
|
@ -89,7 +91,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
|
||||
// Search for the same node using a different query.
|
||||
$edit = ['or' => 'test'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', $edit, 'edit-submit--2');
|
||||
|
||||
// Check if the node has been found.
|
||||
$this->assertText('Search results');
|
|
@ -1,24 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the node search query can be altered via the query alter hook.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchQueryAlterTest extends SearchTestBase {
|
||||
class SearchQueryAlterTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['search_query_alter'];
|
||||
protected static $modules = ['node', 'search', 'search_query_alter'];
|
||||
|
||||
/**
|
||||
* Tests that the query alter works.
|
||||
*/
|
||||
public function testQueryAlter() {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->drupalCreateUser(['create page content', 'search content']));
|
||||
|
|
@ -1,21 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\search\Entity\SearchPage;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\Traits\Core\CronRunTrait;
|
||||
|
||||
/**
|
||||
* Indexes content and tests ranking factors.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchRankingTest extends SearchTestBase {
|
||||
class SearchRankingTest extends BrowserTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
use CronRunTrait;
|
||||
|
||||
/**
|
||||
* The node search page.
|
||||
|
@ -25,15 +28,15 @@ class SearchRankingTest extends SearchTestBase {
|
|||
protected $nodeSearch;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['statistics', 'comment'];
|
||||
protected static $modules = ['node', 'search', 'statistics', 'comment'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create a plugin instance.
|
||||
$this->nodeSearch = SearchPage::load('node_search');
|
||||
|
||||
|
@ -53,9 +56,9 @@ class SearchRankingTest extends SearchTestBase {
|
|||
foreach ($node_ranks as $node_rank) {
|
||||
$settings = [
|
||||
'type' => 'page',
|
||||
'comment' => [[
|
||||
'status' => CommentItemInterface::HIDDEN,
|
||||
]],
|
||||
'comment' => [
|
||||
['status' => CommentItemInterface::HIDDEN],
|
||||
],
|
||||
'title' => 'Drupal rocks',
|
||||
'body' => [['value' => "Drupal's search rocks"]],
|
||||
// Node is one day old.
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that search works with numeric locale settings.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchSetLocaleTest extends SearchTestBase {
|
||||
class SearchSetLocaleTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['comment'];
|
||||
protected static $modules = ['comment', 'node', 'search'];
|
||||
|
||||
/**
|
||||
* A node search plugin instance.
|
||||
|
@ -26,6 +26,8 @@ class SearchSetLocaleTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
|
||||
// Create a plugin instance.
|
||||
$this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Create a node with a very simple body.
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that the search_simply() function works as intended.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchSimplifyTest extends SearchTestBase {
|
||||
class SearchSimplifyTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['search'];
|
||||
|
||||
/**
|
||||
* Tests that all Unicode characters simplify correctly.
|
||||
*/
|
||||
|
@ -20,7 +27,7 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
// their own lines). So the even-numbered lines should simplify to nothing,
|
||||
// and the odd-numbered lines we need to split into shorter chunks and
|
||||
// verify that simplification doesn't lose any characters.
|
||||
$input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt');
|
||||
$input = file_get_contents($this->root . '/core/modules/search/tests/UnicodeTest.txt');
|
||||
$basestrings = explode(chr(10), $input);
|
||||
$strings = [];
|
||||
foreach ($basestrings as $key => $string) {
|
||||
|
@ -34,8 +41,8 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
// Split this into 30-character chunks, so we don't run into limits
|
||||
// of truncation in search_simplify().
|
||||
$start = 0;
|
||||
while ($start < Unicode::strlen($string)) {
|
||||
$newstr = Unicode::substr($string, $start, 30);
|
||||
while ($start < mb_strlen($string)) {
|
||||
$newstr = mb_substr($string, $start, 30);
|
||||
// Special case: leading zeros are removed from numeric strings,
|
||||
// and there's one string in this file that is numbers starting with
|
||||
// zero, so prepend a 1 on that string.
|
||||
|
@ -49,7 +56,7 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
}
|
||||
foreach ($strings as $key => $string) {
|
||||
$simplified = search_simplify($string);
|
||||
$this->assertTrue(Unicode::strlen($simplified) >= Unicode::strlen($string), "Nothing is removed from string $key.");
|
||||
$this->assertTrue(mb_strlen($simplified) >= mb_strlen($string), "Nothing is removed from string $key.");
|
||||
}
|
||||
|
||||
// Test the low-numbered ASCII control characters separately. They are not
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
@trigger_error(__NAMESPACE__ . '\SearchTestBase is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\BrowserTestBase. See https://www.drupal.org/node/2979950.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Defines the common search test code.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.0 and will be removed in Drupal 9.0.0. Use
|
||||
* \Drupal\Tests\BrowserTestBase instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2979950
|
||||
*/
|
||||
abstract class SearchTestBase extends BrowserTestBase {
|
||||
|
||||
|
@ -28,17 +34,7 @@ abstract class SearchTestBase extends BrowserTestBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Simulates submission of a form using GET instead of POST.
|
||||
*
|
||||
* Forms that use the GET method cannot be submitted with
|
||||
* WebTestBase::drupalPostForm(), which explicitly uses POST to submit the
|
||||
* form. So this method finds the form, verifies that it has input fields and
|
||||
* a submit button matching the inputs to this method, and then calls
|
||||
* WebTestBase::drupalGet() to simulate the form submission to the 'action'
|
||||
* URL of the form (if set, or the current URL if not).
|
||||
*
|
||||
* See WebTestBase::drupalPostForm() for more detailed documentation of the
|
||||
* function parameters.
|
||||
* Submission of a form via press submit button.
|
||||
*
|
||||
* @param string $path
|
||||
* Location of the form to be submitted: either a Drupal path, absolute
|
||||
|
@ -51,42 +47,15 @@ abstract class SearchTestBase extends BrowserTestBase {
|
|||
* this does not support AJAX.
|
||||
* @param string $form_html_id
|
||||
* (optional) HTML ID of the form, to disambiguate.
|
||||
*
|
||||
* @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\Tests\BrowserTestBase::drupalPostForm() instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2979950
|
||||
*/
|
||||
protected function submitGetForm($path, $edit, $submit, $form_html_id = NULL) {
|
||||
if (isset($path)) {
|
||||
$this->drupalGet($path);
|
||||
}
|
||||
|
||||
if ($this->parse()) {
|
||||
// Iterate over forms to find one that matches $edit and $submit.
|
||||
$edit_save = $edit;
|
||||
$xpath = '//form';
|
||||
if (!empty($form_html_id)) {
|
||||
$xpath .= "[@id='" . $form_html_id . "']";
|
||||
}
|
||||
$forms = $this->xpath($xpath);
|
||||
foreach ($forms as $form) {
|
||||
// Try to set the fields of this form as specified in $edit.
|
||||
$edit = $edit_save;
|
||||
$post = [];
|
||||
$upload = [];
|
||||
$submit_matches = $this->handleForm($post, $edit, $upload, $submit, $form);
|
||||
if (!$edit && $submit_matches) {
|
||||
// Everything matched, so "submit" the form.
|
||||
$action = isset($form['action']) ? $this->getAbsoluteUrl((string) $form['action']) : NULL;
|
||||
$this->drupalGet($action, ['query' => $post]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// We have not found a form which contained all fields of $edit and
|
||||
// the submit button.
|
||||
foreach ($edit as $name => $value) {
|
||||
$this->fail(SafeMarkup::format('Failed to set field @name to @value', ['@name' => $name, '@value' => $value]));
|
||||
}
|
||||
$this->assertTrue($submit_matches, format_string('Found the @submit button', ['@submit' => $submit]));
|
||||
$this->fail(format_string('Found the requested form fields at @path', ['@path' => $path]));
|
||||
}
|
||||
@trigger_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated in Drupal 8.6.x, for removal before the Drupal 9.0.0 release. Use \Drupal\Tests\BrowserTestBase::drupalPostForm() instead. See https://www.drupal.org/node/2979950.', E_USER_DEPRECATED);
|
||||
$this->drupalPostForm($path, $edit, $submit, [], $form_html_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Tests that CJK tokenizer works as intended.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchTokenizerTest extends SearchTestBase {
|
||||
class SearchTokenizerTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static $modules = ['search'];
|
||||
|
||||
/**
|
||||
* Verifies that strings of CJK characters are tokenized.
|
||||
|
@ -94,7 +100,7 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
// Merge into a string and tokenize.
|
||||
$string = implode('', $chars);
|
||||
$out = trim(search_simplify($string));
|
||||
$expected = Unicode::strtolower(implode(' ', $chars));
|
||||
$expected = mb_strtolower(implode(' ', $chars));
|
||||
|
||||
// Verify that the output matches what we expect.
|
||||
$this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters');
|
||||
|
@ -124,9 +130,9 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
/**
|
||||
* Like PHP chr() function, but for unicode characters.
|
||||
*
|
||||
* chr() only works for ASCII characters up to character 255. This function
|
||||
* converts a number to the corresponding unicode character. Adapted from
|
||||
* functions supplied in comments on several functions on php.net.
|
||||
* Function chr() only works for ASCII characters up to character 255. This
|
||||
* function converts a number to the corresponding unicode character. Adapted
|
||||
* from functions supplied in comments on several functions on php.net.
|
||||
*/
|
||||
public function code2utf($num) {
|
||||
if ($num < 128) {
|
||||
|
|
|
@ -156,7 +156,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
'"am minim veniam" -"cillum dolore"' => [5, 6],
|
||||
'"am minim veniam" -"dolore cillum"' => [5, 6, 7],
|
||||
'xxxxx "minim am veniam es" OR dolore' => [],
|
||||
'xx "minim am veniam es" OR dolore' => []
|
||||
'xx "minim am veniam es" OR dolore' => [],
|
||||
];
|
||||
foreach ($queries as $query => $results) {
|
||||
$result = db_select('search_index', 'i')
|
||||
|
|
|
@ -273,11 +273,13 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
class TestSearchPage extends SearchPage {
|
||||
|
||||
public function __construct(array $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function label($langcode = NULL) {
|
||||
return $this->label;
|
||||
}
|
||||
|
|
Reference in a new issue