Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -9,116 +9,116 @@
|
|||
* Implements hook_schema().
|
||||
*/
|
||||
function search_schema() {
|
||||
$schema['search_dataset'] = array(
|
||||
$schema['search_dataset'] = [
|
||||
'description' => 'Stores items that will be searched.',
|
||||
'fields' => array(
|
||||
'sid' => array(
|
||||
'fields' => [
|
||||
'sid' => [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Search item ID, e.g. node ID for nodes.',
|
||||
),
|
||||
'langcode' => array(
|
||||
],
|
||||
'langcode' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => '12',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The {languages}.langcode of the item variant.',
|
||||
'default' => '',
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Type of item, e.g. node.',
|
||||
),
|
||||
'data' => array(
|
||||
],
|
||||
'data' => [
|
||||
'type' => 'text',
|
||||
'not null' => TRUE,
|
||||
'size' => 'big',
|
||||
'description' => 'List of space-separated words from the item.',
|
||||
),
|
||||
'reindex' => array(
|
||||
],
|
||||
'reindex' => [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'Set to force node reindexing.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('sid', 'langcode', 'type'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['sid', 'langcode', 'type'],
|
||||
];
|
||||
|
||||
$schema['search_index'] = array(
|
||||
$schema['search_index'] = [
|
||||
'description' => 'Stores the search index, associating words, items and scores.',
|
||||
'fields' => array(
|
||||
'word' => array(
|
||||
'fields' => [
|
||||
'word' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'The {search_total}.word that is associated with the search item.',
|
||||
),
|
||||
'sid' => array(
|
||||
],
|
||||
'sid' => [
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The {search_dataset}.sid of the searchable item to which the word belongs.',
|
||||
),
|
||||
'langcode' => array(
|
||||
],
|
||||
'langcode' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => '12',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The {languages}.langcode of the item variant.',
|
||||
'default' => '',
|
||||
),
|
||||
'type' => array(
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'description' => 'The {search_dataset}.type of the searchable item to which the word belongs.',
|
||||
),
|
||||
'score' => array(
|
||||
],
|
||||
'score' => [
|
||||
'type' => 'float',
|
||||
'not null' => FALSE,
|
||||
'description' => 'The numeric score of the word, higher being more important.',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'sid_type' => array('sid', 'langcode', 'type'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'search_dataset' => array(
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'sid_type' => ['sid', 'langcode', 'type'],
|
||||
],
|
||||
'foreign keys' => [
|
||||
'search_dataset' => [
|
||||
'table' => 'search_dataset',
|
||||
'columns' => array(
|
||||
'columns' => [
|
||||
'sid' => 'sid',
|
||||
'langcode' => 'langcode',
|
||||
'type' => 'type',
|
||||
),
|
||||
),
|
||||
),
|
||||
'primary key' => array('word', 'sid', 'langcode', 'type'),
|
||||
);
|
||||
],
|
||||
],
|
||||
],
|
||||
'primary key' => ['word', 'sid', 'langcode', 'type'],
|
||||
];
|
||||
|
||||
$schema['search_total'] = array(
|
||||
$schema['search_total'] = [
|
||||
'description' => 'Stores search totals for words.',
|
||||
'fields' => array(
|
||||
'word' => array(
|
||||
'fields' => [
|
||||
'word' => [
|
||||
'description' => 'Primary Key: Unique word in the search index.',
|
||||
'type' => 'varchar',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'count' => array(
|
||||
],
|
||||
'count' => [
|
||||
'description' => "The count of the word in the index using Zipf's law to equalize the probability distribution.",
|
||||
'type' => 'float',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('word'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['word'],
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ function search_schema() {
|
|||
* For the Status Report, return information about search index status.
|
||||
*/
|
||||
function search_requirements($phase) {
|
||||
$requirements = array();
|
||||
$requirements = [];
|
||||
|
||||
if ($phase == 'runtime') {
|
||||
$remaining = 0;
|
||||
|
@ -145,11 +145,11 @@ function search_requirements($phase) {
|
|||
// Use floor() to calculate the percentage, so if it is not quite 100%, it
|
||||
// will show as 99%, to indicate "almost done".
|
||||
$percent = ($total > 0 ? floor(100 * $done / $total) : 100);
|
||||
$requirements['search_status'] = array(
|
||||
$requirements['search_status'] = [
|
||||
'title' => t('Search index progress'),
|
||||
'value' => t('@percent% (@remaining remaining)', array('@percent' => $percent, '@remaining' => $remaining)),
|
||||
'value' => t('@percent% (@remaining remaining)', ['@percent' => $percent, '@remaining' => $remaining]),
|
||||
'severity' => REQUIREMENT_INFO,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
|
|
|
@ -74,20 +74,20 @@ function search_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.search':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', array(':search-module' => 'https://www.drupal.org/documentation/modules/search')) . '</p>';
|
||||
$output .= '<p>' . t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', [':search-module' => 'https://www.drupal.org/documentation/modules/search']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Configuring search pages') . '</dt>';
|
||||
$output .= '<dd>' . t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', array(':search-settings' => \Drupal::url('entity.search_page.collection'), ':search-url' => \Drupal::url('search.view'))) . '</dd>';
|
||||
$output .= '<dd>' . t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [':search-settings' => \Drupal::url('entity.search_page.collection'), ':search-url' => \Drupal::url('search.view')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Managing the search index') . '</dt>';
|
||||
$output .= '<dd>' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', array(':cron' => \Drupal::url('system.cron_settings'), ':search-settings' => \Drupal::url('entity.search_page.collection'))) . '</dd>';
|
||||
$output .= '<dd>' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', array(':search-settings' => \Drupal::url('entity.search_page.collection'))) . '</dd>';
|
||||
$output .= '<dd>' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', [':cron' => \Drupal::url('system.cron_settings'), ':search-settings' => \Drupal::url('entity.search_page.collection')]) . '</dd>';
|
||||
$output .= '<dd>' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', [':search-settings' => \Drupal::url('entity.search_page.collection')]) . '</dd>';
|
||||
$output .= '<dt>' . t('Displaying the Search block') . '</dt>';
|
||||
$output .= '<dd>' . t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module enabled; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', array(':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':search_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-search')))) . '</dd>';
|
||||
$output .= '<dd>' . t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module enabled; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#', ':search_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-search'])]) . '</dd>';
|
||||
$output .= '<dt>' . t('Searching your site') . '</dt>';
|
||||
$output .= '<dd>' . t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', array(':search' => \Drupal::url('search.view'), ':search_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-search')), ':node_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-node')), ':user_permission' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-user')))) . '</dd>';
|
||||
$output .= '<dd>' . t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', [':search' => \Drupal::url('search.view'), ':search_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-search']), ':node_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-node']), ':user_permission' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-user'])]) . '</dd>';
|
||||
$output .= '<dt>' . t('Extending the Search module') . '</dt>';
|
||||
$output .= '<dd>' . t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', array(':contrib-search' => 'https://www.drupal.org/project/project_module?f[2]=im_vid_3%3A105', ':porterstemmer_url' => 'https://www.drupal.org/project/porterstemmer', ':solr_url' => 'https://www.drupal.org/project/apachesolr', ':sphinx_url' => 'https://www.drupal.org/project/sphinx')) . '</dd>';
|
||||
$output .= '<dd>' . t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', [':contrib-search' => 'https://www.drupal.org/project/project_module?f[2]=im_vid_3%3A105', ':porterstemmer_url' => 'https://www.drupal.org/project/porterstemmer', ':solr_url' => 'https://www.drupal.org/project/apachesolr', ':sphinx_url' => 'https://www.drupal.org/project/sphinx']) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ function search_help($route_name, RouteMatchInterface $route_match) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function search_theme() {
|
||||
return array(
|
||||
'search_result' => array(
|
||||
'variables' => array('result' => NULL, 'plugin_id' => NULL),
|
||||
return [
|
||||
'search_result' => [
|
||||
'variables' => ['result' => NULL, 'plugin_id' => NULL],
|
||||
'file' => 'search.pages.inc',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +167,7 @@ function search_index_clear($type = NULL, $sid = NULL, $langcode = NULL) {
|
|||
* total counts in the search_total table, and need to be recounted.
|
||||
*/
|
||||
function search_dirty($word = NULL) {
|
||||
$dirty = &drupal_static(__FUNCTION__, array());
|
||||
$dirty = &drupal_static(__FUNCTION__, []);
|
||||
if ($word !== NULL) {
|
||||
$dirty[$word] = TRUE;
|
||||
}
|
||||
|
@ -206,18 +206,18 @@ function search_update_totals() {
|
|||
// Update word IDF (Inverse Document Frequency) counts for new/changed words.
|
||||
foreach (search_dirty() as $word => $dummy) {
|
||||
// Get total count
|
||||
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", array(':word' => $word), array('target' => 'replica'))->fetchField();
|
||||
$total = db_query("SELECT SUM(score) FROM {search_index} WHERE word = :word", [':word' => $word], ['target' => 'replica'])->fetchField();
|
||||
// Apply Zipf's law to equalize the probability distribution.
|
||||
$total = log10(1 + 1 / (max(1, $total)));
|
||||
db_merge('search_total')
|
||||
->key('word', $word)
|
||||
->fields(array('count' => $total))
|
||||
->fields(['count' => $total])
|
||||
->execute();
|
||||
}
|
||||
// Find words that were deleted from search_index, but are still in
|
||||
// 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", array(), array('target' => 'replica'));
|
||||
$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();
|
||||
foreach ($result as $word) {
|
||||
$or->condition('word', $word->realword);
|
||||
|
@ -329,7 +329,7 @@ function search_expand_cjk($matches) {
|
|||
}
|
||||
$tokens = ' ';
|
||||
// Build a FIFO queue of characters.
|
||||
$chars = array();
|
||||
$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);
|
||||
|
@ -382,7 +382,7 @@ function search_index_split($text, $langcode = NULL) {
|
|||
function _search_index_truncate(&$text) {
|
||||
// Use a static array to avoid re-truncating text we've done before.
|
||||
// The same words may often be passed in during excerpt generation.
|
||||
static $truncated = array();
|
||||
static $truncated = [];
|
||||
if (isset($truncated[$text])) {
|
||||
$text = $truncated[$text];
|
||||
return;
|
||||
|
@ -408,7 +408,7 @@ function _search_index_truncate(&$text) {
|
|||
*/
|
||||
function search_invoke_preprocess(&$text, $langcode = NULL) {
|
||||
foreach (\Drupal::moduleHandler()->getImplementations('search_preprocess') as $module) {
|
||||
$text = \Drupal::moduleHandler()->invoke($module, 'search_preprocess', array($text, $langcode));
|
||||
$text = \Drupal::moduleHandler()->invoke($module, 'search_preprocess', [$text, $langcode]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
|
||||
// Strip off all ignored tags to speed up processing, but insert space before
|
||||
// and after them to keep word boundaries.
|
||||
$text = str_replace(array('<', '>'), array(' <', '> '), $text);
|
||||
$text = str_replace(['<', '>'], [' <', '> '], $text);
|
||||
$text = strip_tags($text, '<' . implode('><', array_keys($tags)) . '>');
|
||||
|
||||
// Split HTML tags from plain text.
|
||||
|
@ -448,11 +448,11 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
$tag = FALSE; // Odd/even counter. Tag or no tag.
|
||||
$score = 1; // Starting score per word
|
||||
$accum = ' '; // Accumulator for cleaned up data
|
||||
$tagstack = array(); // Stack with open tags
|
||||
$tagstack = []; // Stack with open tags
|
||||
$tagwords = 0; // Counter for consecutive words
|
||||
$focus = 1; // Focus state
|
||||
|
||||
$scored_words = array(); // Accumulator for words for index
|
||||
$scored_words = []; // Accumulator for words for index
|
||||
|
||||
foreach ($split as $value) {
|
||||
if ($tag) {
|
||||
|
@ -464,7 +464,7 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
$tagname = substr($tagname, 1);
|
||||
// If we encounter unexpected tags, reset score to avoid incorrect boosting.
|
||||
if (!count($tagstack) || $tagstack[0] != $tagname) {
|
||||
$tagstack = array();
|
||||
$tagstack = [];
|
||||
$score = 1;
|
||||
}
|
||||
else {
|
||||
|
@ -476,7 +476,7 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
if (isset($tagstack[0]) && $tagstack[0] == $tagname) {
|
||||
// None of the tags we look for make sense when nested identically.
|
||||
// If they are, it's probably broken HTML.
|
||||
$tagstack = array();
|
||||
$tagstack = [];
|
||||
$score = 1;
|
||||
}
|
||||
else {
|
||||
|
@ -508,7 +508,7 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
$tagwords++;
|
||||
// Too many words inside a single tag probably mean a tag was accidentally left open.
|
||||
if (count($tagstack) && $tagwords >= 15) {
|
||||
$tagstack = array();
|
||||
$tagstack = [];
|
||||
$score = 1;
|
||||
}
|
||||
}
|
||||
|
@ -523,13 +523,13 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
|
||||
// Insert cleaned up data into dataset
|
||||
db_insert('search_dataset')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'sid' => $sid,
|
||||
'langcode' => $langcode,
|
||||
'type' => $type,
|
||||
'data' => $accum,
|
||||
'reindex' => 0,
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
|
||||
// Insert results into search index
|
||||
|
@ -538,14 +538,14 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
// appropriately. If not, we create a new record with the appropriate
|
||||
// starting score.
|
||||
db_merge('search_index')
|
||||
->keys(array(
|
||||
->keys([
|
||||
'word' => $word,
|
||||
'sid' => $sid,
|
||||
'langcode' => $langcode,
|
||||
'type' => $type,
|
||||
))
|
||||
->fields(array('score' => $score))
|
||||
->expression('score', 'score + :score', array(':score' => $score))
|
||||
])
|
||||
->fields(['score' => $score])
|
||||
->expression('score', 'score + :score', [':score' => $score])
|
||||
->execute();
|
||||
search_dirty($word);
|
||||
}
|
||||
|
@ -571,7 +571,7 @@ function search_index($type, $sid, $langcode, $text) {
|
|||
*/
|
||||
function search_mark_for_reindex($type = NULL, $sid = NULL, $langcode = NULL) {
|
||||
$query = db_update('search_dataset')
|
||||
->fields(array('reindex' => REQUEST_TIME))
|
||||
->fields(['reindex' => REQUEST_TIME])
|
||||
// Only mark items that were not previously marked for reindex, so that
|
||||
// marked items maintain their priority by request time.
|
||||
->condition('reindex', 0);
|
||||
|
@ -650,14 +650,14 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
$keys = array_merge($matches[2], $matches[3]);
|
||||
|
||||
// Prepare text by stripping HTML tags and decoding HTML entities.
|
||||
$text = strip_tags(str_replace(array('<', '>'), array(' <', '> '), $text));
|
||||
$text = strip_tags(str_replace(['<', '>'], [' <', '> '], $text));
|
||||
$text = Html::decodeEntities($text);
|
||||
$text_length = strlen($text);
|
||||
|
||||
// Make a list of unique keywords that are actually found in the text,
|
||||
// which could be items in $keys or replacements that are equivalent through
|
||||
// search_simplify().
|
||||
$temp_keys = array();
|
||||
$temp_keys = [];
|
||||
foreach ($keys as $key) {
|
||||
$key = _search_find_match_with_simplify($key, $text, $boundary_character, $langcode);
|
||||
if (isset($key)) {
|
||||
|
@ -672,13 +672,13 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
// Extract fragments of about 60 characters around keywords, bounded by word
|
||||
// boundary characters. Try to reach 256 characters, using second occurrences
|
||||
// if necessary.
|
||||
$ranges = array();
|
||||
$ranges = [];
|
||||
$length = 0;
|
||||
$look_start = array();
|
||||
$look_start = [];
|
||||
$remaining_keys = $keys;
|
||||
|
||||
while ($length < 256 && !empty($remaining_keys)) {
|
||||
$found_keys = array();
|
||||
$found_keys = [];
|
||||
foreach ($remaining_keys as $key) {
|
||||
if ($length >= 256) {
|
||||
break;
|
||||
|
@ -693,7 +693,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
// See if we can find $key after where we found it the last time. Since
|
||||
// we are requiring a match on a word boundary, make sure $text starts
|
||||
// and ends with a space.
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
if (preg_match('/' . $preceded_by_boundary . $key . $followed_by_boundary . '/iu', ' ' . $text . ' ', $matches, PREG_OFFSET_CAPTURE, $look_start[$key])) {
|
||||
$found_position = $matches[0][1];
|
||||
$look_start[$key] = $found_position + 1;
|
||||
|
@ -741,7 +741,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
ksort($ranges);
|
||||
|
||||
// Collapse overlapping text ranges into one. The sorting makes it O(n).
|
||||
$new_ranges = array();
|
||||
$new_ranges = [];
|
||||
$max_end = 0;
|
||||
foreach ($ranges as $this_from => $this_to) {
|
||||
$max_end = max($max_end, $this_to);
|
||||
|
@ -766,7 +766,7 @@ function search_excerpt($keys, $text, $langcode = NULL) {
|
|||
$new_ranges[$working_from] = $working_to;
|
||||
|
||||
// Fetch text within the combined ranges we found.
|
||||
$out = array();
|
||||
$out = [];
|
||||
foreach ($new_ranges as $from => $to) {
|
||||
$out[] = substr($text, $from, $to - $from);
|
||||
}
|
||||
|
@ -846,7 +846,7 @@ function _search_find_match_with_simplify($key, $text, $boundary, $langcode = NU
|
|||
// Split $text into words, keeping track of where the word boundaries are.
|
||||
$words = preg_split('/' . $boundary . '+/u', $text, NULL, PREG_SPLIT_OFFSET_CAPTURE);
|
||||
// Add an entry pointing to the end of the string, for the loop below.
|
||||
$words[] = array('', strlen($text));
|
||||
$words[] = ['', strlen($text)];
|
||||
|
||||
// Using a binary search, find the earliest possible ending position in
|
||||
// $text where it will still match the keyword after applying
|
||||
|
|
|
@ -12,7 +12,7 @@ use Drupal\Core\Language\LanguageInterface;
|
|||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function search_theme_suggestions_search_result(array $variables) {
|
||||
return array('search_result__' . $variables['plugin_id']);
|
||||
return ['search_result__' . $variables['plugin_id']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,7 +42,7 @@ function template_preprocess_search_result(&$variables) {
|
|||
$variables['content_attributes']['lang'] = $result['language'];
|
||||
}
|
||||
|
||||
$info = array();
|
||||
$info = [];
|
||||
if (!empty($result['plugin_id'])) {
|
||||
$info['plugin_id'] = $result['plugin_id'];
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ function template_preprocess_search_result(&$variables) {
|
|||
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
|
||||
// Provide separated and grouped meta information..
|
||||
$variables['info_split'] = $info;
|
||||
$variables['info'] = array(
|
||||
$variables['info'] = [
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '{{ info|safe_join(" - ") }}',
|
||||
'#context' => array('info' => $info),
|
||||
);
|
||||
'#context' => ['info' => $info],
|
||||
];
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class SearchController extends ControllerBase {
|
|||
* The search form and search results build array.
|
||||
*/
|
||||
public function view(Request $request, SearchPageInterface $entity) {
|
||||
$build = array();
|
||||
$build = [];
|
||||
$plugin = $entity->getPlugin();
|
||||
|
||||
// Build the form first, because it may redirect during the submit,
|
||||
|
@ -89,12 +89,12 @@ class SearchController extends ControllerBase {
|
|||
// 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
|
||||
// there at all, vs. being empty, due to advanced search.
|
||||
$results = array();
|
||||
$results = [];
|
||||
if ($request->query->has('keys')) {
|
||||
if ($plugin->isSearchExecutable()) {
|
||||
// Log the search.
|
||||
if ($this->config('search.settings')->get('logging')) {
|
||||
$this->logger->notice('Searched %type for %keys.', array('%keys' => $keys, '%type' => $entity->label()));
|
||||
$this->logger->notice('Searched %type for %keys.', ['%keys' => $keys, '%type' => $entity->label()]);
|
||||
}
|
||||
|
||||
// Collect the search results.
|
||||
|
@ -108,22 +108,22 @@ class SearchController extends ControllerBase {
|
|||
}
|
||||
|
||||
if (count($results)) {
|
||||
$build['search_results_title'] = array(
|
||||
$build['search_results_title'] = [
|
||||
'#markup' => '<h2>' . $this->t('Search results') . '</h2>',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$build['search_results'] = array(
|
||||
'#theme' => array('item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'),
|
||||
$build['search_results'] = [
|
||||
'#theme' => ['item_list__search_results__' . $plugin->getPluginId(), 'item_list__search_results'],
|
||||
'#items' => $results,
|
||||
'#empty' => array(
|
||||
'#empty' => [
|
||||
'#markup' => '<h3>' . $this->t('Your search yielded no results.') . '</h3>',
|
||||
),
|
||||
],
|
||||
'#list_type' => 'ol',
|
||||
'#context' => array(
|
||||
'#context' => [
|
||||
'plugin' => $plugin->getPluginId(),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$this->renderer->addCacheableDependency($build, $entity);
|
||||
if ($plugin instanceof CacheableDependencyInterface) {
|
||||
|
@ -138,9 +138,9 @@ class SearchController extends ControllerBase {
|
|||
$build['search_results']['#cache']['tags'][] = 'search_index:' . $plugin->getType();
|
||||
}
|
||||
|
||||
$build['pager'] = array(
|
||||
$build['pager'] = [
|
||||
'#type' => 'pager',
|
||||
);
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ class SearchController extends ControllerBase {
|
|||
* The search help page.
|
||||
*/
|
||||
public function searchHelp(SearchPageInterface $entity) {
|
||||
$build = array();
|
||||
$build = [];
|
||||
|
||||
$build['search_help'] = $entity->getPlugin()->getHelp();
|
||||
|
||||
|
@ -189,7 +189,7 @@ class SearchController extends ControllerBase {
|
|||
* The title for the search page edit form.
|
||||
*/
|
||||
public function editTitle(SearchPageInterface $search_page) {
|
||||
return $this->t('Edit %label search page', array('%label' => $search_page->label()));
|
||||
return $this->t('Edit %label search page', ['%label' => $search_page->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,10 +207,10 @@ class SearchController extends ControllerBase {
|
|||
$search_page->$op()->save();
|
||||
|
||||
if ($op == 'enable') {
|
||||
drupal_set_message($this->t('The %label search page has been enabled.', array('%label' => $search_page->label())));
|
||||
drupal_set_message($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.', array('%label' => $search_page->label())));
|
||||
drupal_set_message($this->t('The %label search page has been disabled.', ['%label' => $search_page->label()]));
|
||||
}
|
||||
|
||||
$url = $search_page->urlInfo('collection');
|
||||
|
@ -230,7 +230,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.', array('%label' => $search_page->label())));
|
||||
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()]));
|
||||
return $this->redirect('entity.search_page.collection');
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface, Entity
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $configuration = array();
|
||||
protected $configuration = [];
|
||||
|
||||
/**
|
||||
* The search plugin ID.
|
||||
|
@ -129,7 +129,7 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface, Entity
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPluginCollections() {
|
||||
return array('configuration' => $this->getPluginCollection());
|
||||
return ['configuration' => $this->getPluginCollection()];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,8 +76,6 @@ class SearchBlockForm extends FormBase {
|
|||
// Set up the form to submit using GET to the correct search page.
|
||||
$entity_id = $this->searchPageRepository->getDefaultSearchPage();
|
||||
|
||||
$form = [];
|
||||
|
||||
// SearchPageRepository::getDefaultSearchPage() depends on search.settings.
|
||||
// The dependency needs to be added before the conditional return, otherwise
|
||||
// the block would get cached without the necessary cacheablity metadata in
|
||||
|
@ -86,9 +84,9 @@ class SearchBlockForm extends FormBase {
|
|||
$this->renderer->addCacheableDependency($form, $this->configFactory->get('search.settings'));
|
||||
|
||||
if (!$entity_id) {
|
||||
$form['message'] = array(
|
||||
$form['message'] = [
|
||||
'#markup' => $this->t('Search is currently disabled'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -96,22 +94,22 @@ class SearchBlockForm extends FormBase {
|
|||
$form['#action'] = $this->url($route);
|
||||
$form['#method'] = 'get';
|
||||
|
||||
$form['keys'] = array(
|
||||
$form['keys'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $this->t('Search'),
|
||||
'#title_display' => 'invisible',
|
||||
'#size' => 15,
|
||||
'#default_value' => '',
|
||||
'#attributes' => array('title' => $this->t('Enter the terms you wish to search for.')),
|
||||
);
|
||||
'#attributes' => ['title' => $this->t('Enter the terms you wish to search for.')],
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Search'),
|
||||
// Prevent op from showing up in the query string.
|
||||
'#name' => '',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class SearchPageAddForm extends SearchPageFormBase {
|
|||
|
||||
parent::save($form, $form_state);
|
||||
|
||||
drupal_set_message($this->t('The %label search page has been added.', array('%label' => $this->entity->label())));
|
||||
drupal_set_message($this->t('The %label search page has been added.', ['%label' => $this->entity->label()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,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.', array('%label' => $this->entity->label())));
|
||||
drupal_set_message($this->t('The %label search page has been updated.', ['%label' => $this->entity->label()]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,37 +38,37 @@ class SearchPageForm extends EntityForm {
|
|||
$plugin = $this->entity->getPlugin();
|
||||
$form_state->set('search_page_id', $this->entity->id());
|
||||
|
||||
$form['basic'] = array(
|
||||
$form['basic'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('container-inline'),
|
||||
),
|
||||
);
|
||||
$form['basic']['keys'] = array(
|
||||
'#attributes' => [
|
||||
'class' => ['container-inline'],
|
||||
],
|
||||
];
|
||||
$form['basic']['keys'] = [
|
||||
'#type' => 'search',
|
||||
'#title' => $this->t('Enter your keywords'),
|
||||
'#default_value' => $plugin->getKeywords(),
|
||||
'#size' => 30,
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
];
|
||||
|
||||
// processed_keys is used to coordinate keyword passing between other forms
|
||||
// that hook into the basic search form.
|
||||
$form['basic']['processed_keys'] = array(
|
||||
$form['basic']['processed_keys'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => '',
|
||||
);
|
||||
$form['basic']['submit'] = array(
|
||||
];
|
||||
$form['basic']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Search'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['help_link'] = array(
|
||||
$form['help_link'] = [
|
||||
'#type' => 'link',
|
||||
'#url' => new Url('search.help_' . $this->entity->id()),
|
||||
'#title' => $this->t('Search help'),
|
||||
'#options' => array('attributes' => array('class' => 'search-help-link')),
|
||||
);
|
||||
'#options' => ['attributes' => ['class' => 'search-help-link']],
|
||||
];
|
||||
|
||||
// Allow the plugin to add to or alter the search form.
|
||||
$plugin->searchFormAlter($form, $form_state);
|
||||
|
@ -81,7 +81,7 @@ class SearchPageForm extends EntityForm {
|
|||
*/
|
||||
protected function actions(array $form, FormStateInterface $form_state) {
|
||||
// The submit button is added in the form directly.
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,8 +97,8 @@ class SearchPageForm extends EntityForm {
|
|||
$route = 'search.view_' . $form_state->get('search_page_id');
|
||||
$form_state->setRedirect(
|
||||
$route,
|
||||
array(),
|
||||
array('query' => $query)
|
||||
[],
|
||||
['query' => $query]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Drupal\search\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\PluginFormInterface;
|
||||
use Drupal\search\SearchPageRepositoryInterface;
|
||||
|
@ -28,13 +27,6 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* The entity query factory.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQuery;
|
||||
|
||||
/**
|
||||
* The search page repository.
|
||||
*
|
||||
|
@ -45,13 +37,10 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
/**
|
||||
* Constructs a new search form.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
|
||||
* The entity query.
|
||||
* @param \Drupal\search\SearchPageRepositoryInterface $search_page_repository
|
||||
* The search page repository.
|
||||
*/
|
||||
public function __construct(QueryFactory $entity_query, SearchPageRepositoryInterface $search_page_repository) {
|
||||
$this->entityQuery = $entity_query;
|
||||
public function __construct(SearchPageRepositoryInterface $search_page_repository) {
|
||||
$this->searchPageRepository = $search_page_repository;
|
||||
}
|
||||
|
||||
|
@ -60,7 +49,6 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query'),
|
||||
$container->get('search.search_page_repository')
|
||||
);
|
||||
}
|
||||
|
@ -84,35 +72,35 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form['label'] = array(
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#description' => $this->t('The label for this search page.'),
|
||||
'#default_value' => $this->entity->label(),
|
||||
'#maxlength' => '255',
|
||||
);
|
||||
];
|
||||
|
||||
$form['id'] = array(
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $this->entity->id(),
|
||||
'#disabled' => !$this->entity->isNew(),
|
||||
'#maxlength' => 64,
|
||||
'#machine_name' => array(
|
||||
'exists' => array($this, 'exists'),
|
||||
),
|
||||
);
|
||||
$form['path'] = array(
|
||||
'#machine_name' => [
|
||||
'exists' => [$this, 'exists'],
|
||||
],
|
||||
];
|
||||
$form['path'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Path'),
|
||||
'#field_prefix' => 'search/',
|
||||
'#default_value' => $this->entity->getPath(),
|
||||
'#maxlength' => '255',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['plugin'] = array(
|
||||
];
|
||||
$form['plugin'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $this->entity->get('plugin'),
|
||||
);
|
||||
];
|
||||
|
||||
if ($this->plugin instanceof PluginFormInterface) {
|
||||
$form += $this->plugin->buildConfigurationForm($form, $form_state);
|
||||
|
@ -131,7 +119,7 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
* TRUE if the search configuration exists, FALSE otherwise.
|
||||
*/
|
||||
public function exists($id) {
|
||||
$entity = $this->entityQuery->get('search_page')
|
||||
$entity = $this->entityTypeManager->getStorage('search_page')->getQuery()
|
||||
->condition('id', $id)
|
||||
->execute();
|
||||
return (bool) $entity;
|
||||
|
@ -144,7 +132,7 @@ abstract class SearchPageFormBase extends EntityForm {
|
|||
parent::validateForm($form, $form_state);
|
||||
|
||||
// Ensure each path is unique.
|
||||
$path = $this->entityQuery->get('search_page')
|
||||
$path = $this->entityTypeManager->getStorage('search_page')->getQuery()
|
||||
->condition('path', $form_state->getValue('path'))
|
||||
->condition('id', $form_state->getValue('id'), '<>')
|
||||
->execute();
|
||||
|
|
|
@ -30,7 +30,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ abstract class ConfigurableSearchPluginBase extends SearchPluginBase implements
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,17 +42,17 @@ class SearchLocalTask extends DeriverBase implements ContainerDeriverInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$this->derivatives = array();
|
||||
$this->derivatives = [];
|
||||
|
||||
if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
|
||||
$active_search_pages = $this->searchPageRepository->getActiveSearchPages();
|
||||
foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
|
||||
$this->derivatives[$entity_id] = array(
|
||||
$this->derivatives[$entity_id] = [
|
||||
'title' => $entity->label(),
|
||||
'route_name' => 'search.view_' . $entity_id,
|
||||
'base_route' => 'search.plugins:' . $default,
|
||||
'weight' => $entity->getWeight(),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->derivatives;
|
||||
|
|
|
@ -97,13 +97,13 @@ abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPl
|
|||
public function buildResults() {
|
||||
$results = $this->execute();
|
||||
|
||||
$built = array();
|
||||
$built = [];
|
||||
foreach ($results as $result) {
|
||||
$built[] = array(
|
||||
$built[] = [
|
||||
'#theme' => 'search_result',
|
||||
'#result' => $result,
|
||||
'#plugin_id' => $this->getPluginId(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $built;
|
||||
|
@ -123,7 +123,7 @@ abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPl
|
|||
// If the user entered a search string, truncate it and append it to the
|
||||
// title.
|
||||
if (!empty($this->keywords)) {
|
||||
return $this->t('Search for @keywords', array('@keywords' => Unicode::truncate($this->keywords, 60, TRUE, TRUE)));
|
||||
return $this->t('Search for @keywords', ['@keywords' => Unicode::truncate($this->keywords, 60, TRUE, TRUE)]);
|
||||
}
|
||||
// Use the default 'Search' title.
|
||||
return $this->t('Search');
|
||||
|
@ -135,7 +135,7 @@ abstract class SearchPluginBase extends PluginBase implements ContainerFactoryPl
|
|||
public function buildSearchUrlQuery(FormStateInterface $form_state) {
|
||||
// Grab the keywords entered in the form and put them as 'keys' in the GET.
|
||||
$keys = trim($form_state->getValue('keys'));
|
||||
$query = array('keys' => $keys);
|
||||
$query = ['keys' => $keys];
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
@ -146,16 +146,16 @@ 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 = array('list' => array(
|
||||
$help = ['list' => [
|
||||
'#theme' => 'item_list',
|
||||
'#items' => array(
|
||||
'#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;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class SearchConfigurationRankings extends ProcessPluginBase {
|
|||
* Generate the configuration rankings.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$return = array();
|
||||
$return = [];
|
||||
foreach ($row->getSource() as $name => $rank) {
|
||||
if (substr($name, 0, 10) == 'node_rank_' && is_numeric($rank)) {
|
||||
$return[substr($name, 10)] = $rank;
|
||||
|
|
|
@ -21,7 +21,7 @@ class SearchConfigurationRankings extends ProcessPluginBase {
|
|||
* Generate the configuration rankings.
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
$return = array();
|
||||
$return = [];
|
||||
foreach ($row->getSource() as $name => $rank) {
|
||||
if (substr($name, 0, 10) == 'node_rank_' && $rank) {
|
||||
$return[substr($name, 10)] = $rank;
|
||||
|
|
|
@ -47,7 +47,7 @@ class Search extends ArgumentPluginBase {
|
|||
*/
|
||||
protected function queryParseSearchExpression($input) {
|
||||
if (!isset($this->searchQuery)) {
|
||||
$this->searchQuery = db_select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\search\ViewsSearchQuery');
|
||||
$this->searchQuery = db_select('search_index', 'i', ['target' => 'replica'])->extend('Drupal\search\ViewsSearchQuery');
|
||||
$this->searchQuery->searchExpression($input, $this->searchType);
|
||||
$this->searchQuery->publicParseSearchExpression();
|
||||
}
|
||||
|
@ -79,17 +79,17 @@ class Search extends ArgumentPluginBase {
|
|||
$search_condition = db_and();
|
||||
|
||||
// Create a new join to relate the 'search_total' table to our current 'search_index' table.
|
||||
$definition = array(
|
||||
$definition = [
|
||||
'table' => 'search_total',
|
||||
'field' => 'word',
|
||||
'left_table' => $search_index,
|
||||
'left_field' => 'word',
|
||||
);
|
||||
];
|
||||
$join = Views::pluginManager('join')->createInstance('standard', $definition);
|
||||
$search_total = $this->query->addRelationship('search_total', $join, $search_index);
|
||||
|
||||
// Add the search score field to the query.
|
||||
$this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', array('function' => 'sum'));
|
||||
$this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);
|
||||
|
||||
// Add the conditions set up by the search query to the views query.
|
||||
$search_condition->condition("$search_index.type", $this->searchType);
|
||||
|
@ -120,7 +120,7 @@ class Search extends ArgumentPluginBase {
|
|||
$this->query->addGroupBy("$search_index.sid");
|
||||
$matches = $this->searchQuery->matches();
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->addHavingExpression(0, "COUNT(*) >= $placeholder", array($placeholder => $matches));
|
||||
$this->query->addHavingExpression(0, "COUNT(*) >= $placeholder", [$placeholder => $matches]);
|
||||
}
|
||||
|
||||
// Set to NULL to prevent PDO exception when views object is cached
|
||||
|
|
|
@ -67,28 +67,28 @@ class Search extends FilterPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function operatorForm(&$form, FormStateInterface $form_state) {
|
||||
$form['operator'] = array(
|
||||
$form['operator'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => $this->t('On empty input'),
|
||||
'#default_value' => $this->operator,
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'optional' => $this->t('Show All'),
|
||||
'required' => $this->t('Show None'),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function valueForm(&$form, FormStateInterface $form_state) {
|
||||
$form['value'] = array(
|
||||
$form['value'] = [
|
||||
'#type' => 'textfield',
|
||||
'#size' => 15,
|
||||
'#default_value' => $this->value,
|
||||
'#attributes' => array('title' => $this->t('Search keywords')),
|
||||
'#attributes' => ['title' => $this->t('Search keywords')],
|
||||
'#title' => !$form_state->get('exposed') ? $this->t('Keywords') : '',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ class Search extends FilterPluginBase {
|
|||
protected function queryParseSearchExpression($input) {
|
||||
if (!isset($this->searchQuery)) {
|
||||
$this->parsed = TRUE;
|
||||
$this->searchQuery = db_select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\search\ViewsSearchQuery');
|
||||
$this->searchQuery = db_select('search_index', 'i', ['target' => 'replica'])->extend('Drupal\search\ViewsSearchQuery');
|
||||
$this->searchQuery->searchExpression($input, $this->searchType);
|
||||
$this->searchQuery->publicParseSearchExpression();
|
||||
}
|
||||
|
@ -154,17 +154,17 @@ class Search extends FilterPluginBase {
|
|||
|
||||
// Create a new join to relate the 'search_total' table to our current
|
||||
// 'search_index' table.
|
||||
$definition = array(
|
||||
$definition = [
|
||||
'table' => 'search_total',
|
||||
'field' => 'word',
|
||||
'left_table' => $search_index,
|
||||
'left_field' => 'word',
|
||||
);
|
||||
];
|
||||
$join = Views::pluginManager('join')->createInstance('standard', $definition);
|
||||
$search_total = $this->query->addRelationship('search_total', $join, $search_index);
|
||||
|
||||
// Add the search score field to the query.
|
||||
$this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', array('function' => 'sum'));
|
||||
$this->search_score = $this->query->addField('', "$search_index.score * $search_total.count", 'score', ['function' => 'sum']);
|
||||
|
||||
// Add the conditions set up by the search query to the views query.
|
||||
$search_condition->condition("$search_index.type", $this->searchType);
|
||||
|
@ -196,7 +196,7 @@ class Search extends FilterPluginBase {
|
|||
$this->query->addGroupBy("$search_index.sid");
|
||||
$matches = $this->searchQuery->matches();
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->addHavingExpression($this->options['group'], "COUNT(*) >= $placeholder", array($placeholder => $matches));
|
||||
$this->query->addHavingExpression($this->options['group'], "COUNT(*) >= $placeholder", [$placeholder => $matches]);
|
||||
}
|
||||
// Set to NULL to prevent PDO exception when views object is cached.
|
||||
$this->searchQuery = NULL;
|
||||
|
|
|
@ -22,7 +22,7 @@ class SearchRow extends RowPluginBase {
|
|||
protected function defineOptions() {
|
||||
$options = parent::defineOptions();
|
||||
|
||||
$options['score'] = array('default' => TRUE);
|
||||
$options['score'] = ['default' => TRUE];
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -31,23 +31,23 @@ class SearchRow extends RowPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
|
||||
$form['score'] = array(
|
||||
$form['score'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Display score'),
|
||||
'#default_value' => $this->options['score'],
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($row) {
|
||||
return array(
|
||||
return [
|
||||
'#theme' => $this->themeFunctions(),
|
||||
'#view' => $this->view,
|
||||
'#options' => $this->options,
|
||||
'#row' => $row,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class Score extends SortPluginBase {
|
|||
// Our filter stores it as $handler->search_score -- and we also
|
||||
// need to check its relationship to make sure that we're using the same
|
||||
// one or obviously this won't work.
|
||||
foreach (array('filter', 'argument') as $type) {
|
||||
foreach (['filter', 'argument'] as $type) {
|
||||
foreach ($this->view->{$type} as $handler) {
|
||||
if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
|
||||
$this->query->addOrderBy(NULL, NULL, $this->options['order'], $handler->search_score);
|
||||
|
|
|
@ -45,70 +45,70 @@ class SearchPageRoutes implements ContainerInjectionInterface {
|
|||
* An array of route objects.
|
||||
*/
|
||||
public function routes() {
|
||||
$routes = array();
|
||||
$routes = [];
|
||||
// @todo Decide if /search should continue to redirect to /search/$default,
|
||||
// or just perform the appropriate search.
|
||||
if ($default_page = $this->searchPageRepository->getDefaultSearchPage()) {
|
||||
$routes['search.view'] = new Route(
|
||||
'/search',
|
||||
array(
|
||||
[
|
||||
'_controller' => 'Drupal\search\Controller\SearchController::redirectSearchPage',
|
||||
'_title' => 'Search',
|
||||
'entity' => $default_page,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'_entity_access' => 'entity.view',
|
||||
'_permission' => 'search content',
|
||||
),
|
||||
array(
|
||||
'parameters' => array(
|
||||
'entity' => array(
|
||||
],
|
||||
[
|
||||
'parameters' => [
|
||||
'entity' => [
|
||||
'type' => 'entity:search_page',
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
$active_pages = $this->searchPageRepository->getActiveSearchPages();
|
||||
foreach ($active_pages as $entity_id => $entity) {
|
||||
$routes["search.view_$entity_id"] = new Route(
|
||||
'/search/' . $entity->getPath(),
|
||||
array(
|
||||
[
|
||||
'_controller' => 'Drupal\search\Controller\SearchController::view',
|
||||
'_title' => 'Search',
|
||||
'entity' => $entity_id,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'_entity_access' => 'entity.view',
|
||||
'_permission' => 'search content',
|
||||
),
|
||||
array(
|
||||
'parameters' => array(
|
||||
'entity' => array(
|
||||
],
|
||||
[
|
||||
'parameters' => [
|
||||
'entity' => [
|
||||
'type' => 'entity:search_page',
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$routes["search.help_$entity_id"] = new Route(
|
||||
'/search/' . $entity->getPath() . '/help',
|
||||
array(
|
||||
[
|
||||
'_controller' => 'Drupal\search\Controller\SearchController::searchHelp',
|
||||
'_title' => 'Search help',
|
||||
'entity' => $entity_id,
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'_entity_access' => 'entity.view',
|
||||
'_permission' => 'search content',
|
||||
),
|
||||
array(
|
||||
'parameters' => array(
|
||||
'entity' => array(
|
||||
],
|
||||
[
|
||||
'parameters' => [
|
||||
'entity' => [
|
||||
'type' => 'entity:search_page',
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
return $routes;
|
||||
|
|
|
@ -20,7 +20,7 @@ class SearchPageAccessControlHandler extends EntityAccessControlHandler {
|
|||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var $entity \Drupal\search\SearchPageInterface */
|
||||
if (in_array($operation, array('delete', 'disable'))) {
|
||||
if (in_array($operation, ['delete', 'disable'])) {
|
||||
if ($entity->isDefaultSearch()) {
|
||||
return AccessResult::forbidden()->addCacheableDependency($entity);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
*
|
||||
* @var \Drupal\search\SearchPageInterface[]
|
||||
*/
|
||||
protected $entities = array();
|
||||
protected $entities = [];
|
||||
|
||||
/**
|
||||
* Stores the configuration factory.
|
||||
|
@ -90,24 +90,24 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = array(
|
||||
$header['label'] = [
|
||||
'data' => $this->t('Label'),
|
||||
);
|
||||
$header['url'] = array(
|
||||
];
|
||||
$header['url'] = [
|
||||
'data' => $this->t('URL'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW),
|
||||
);
|
||||
$header['plugin'] = array(
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW],
|
||||
];
|
||||
$header['plugin'] = [
|
||||
'data' => $this->t('Type'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_LOW),
|
||||
);
|
||||
$header['status'] = array(
|
||||
'class' => [RESPONSIVE_PRIORITY_LOW],
|
||||
];
|
||||
$header['status'] = [
|
||||
'data' => $this->t('Status'),
|
||||
);
|
||||
$header['progress'] = array(
|
||||
];
|
||||
$header['progress'] = [
|
||||
'data' => $this->t('Indexing progress'),
|
||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
|
||||
);
|
||||
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
|
||||
];
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
|
@ -120,11 +120,11 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
$row['url']['#markup'] = 'search/' . $entity->getPath();
|
||||
// If the search page is active, link to it.
|
||||
if ($entity->status()) {
|
||||
$row['url'] = array(
|
||||
$row['url'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => $row['url'],
|
||||
'#url' => Url::fromRoute('search.view_' . $entity->id()),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$definition = $entity->getPlugin()->getPluginDefinition();
|
||||
|
@ -143,10 +143,10 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
|
||||
if ($entity->isIndexable()) {
|
||||
$status = $entity->getPlugin()->indexStatus();
|
||||
$row['progress']['#markup'] = $this->t('%num_indexed of %num_total indexed', array(
|
||||
$row['progress']['#markup'] = $this->t('%num_indexed of %num_total indexed', [
|
||||
'%num_indexed' => $status['total'] - $status['remaining'],
|
||||
'%num_total' => $status['total']
|
||||
));
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$row['progress']['#markup'] = $this->t('Does not use index');
|
||||
|
@ -178,102 +178,102 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
// will show as 99%, to indicate "almost done".
|
||||
$percentage = $total > 0 ? floor(100 * $done / $total) : 100;
|
||||
$percentage .= '%';
|
||||
$status = '<p><strong>' . $this->t('%percentage of the site has been indexed.', array('%percentage' => $percentage)) . ' ' . $count . '</strong></p>';
|
||||
$form['status'] = array(
|
||||
$status = '<p><strong>' . $this->t('%percentage of the site has been indexed.', ['%percentage' => $percentage]) . ' ' . $count . '</strong></p>';
|
||||
$form['status'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Indexing progress'),
|
||||
'#open' => TRUE,
|
||||
'#description' => $this->t('Only items in the index will appear in search results. To build and maintain the index, a correctly configured <a href=":cron">cron maintenance task</a> is required.', array(':cron' => \Drupal::url('system.cron_settings'))),
|
||||
);
|
||||
$form['status']['status'] = array('#markup' => $status);
|
||||
$form['status']['wipe'] = array(
|
||||
'#description' => $this->t('Only items in the index will appear in search results. To build and maintain the index, a correctly configured <a href=":cron">cron maintenance task</a> is required.', [':cron' => \Drupal::url('system.cron_settings')]),
|
||||
];
|
||||
$form['status']['status'] = ['#markup' => $status];
|
||||
$form['status']['wipe'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Re-index site'),
|
||||
'#submit' => array('::searchAdminReindexSubmit'),
|
||||
);
|
||||
'#submit' => ['::searchAdminReindexSubmit'],
|
||||
];
|
||||
|
||||
$items = array(10, 20, 50, 100, 200, 500);
|
||||
$items = [10, 20, 50, 100, 200, 500];
|
||||
$items = array_combine($items, $items);
|
||||
|
||||
// Indexing throttle:
|
||||
$form['indexing_throttle'] = array(
|
||||
$form['indexing_throttle'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Indexing throttle'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['indexing_throttle']['cron_limit'] = array(
|
||||
];
|
||||
$form['indexing_throttle']['cron_limit'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Number of items to index per cron run'),
|
||||
'#default_value' => $search_settings->get('index.cron_limit'),
|
||||
'#options' => $items,
|
||||
'#description' => $this->t('The maximum number of items indexed in each run of the <a href=":cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing. Some search page types may have their own setting for this.', array(':cron' => \Drupal::url('system.cron_settings'))),
|
||||
);
|
||||
'#description' => $this->t('The maximum number of items indexed in each run of the <a href=":cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing. Some search page types may have their own setting for this.', [':cron' => \Drupal::url('system.cron_settings')]),
|
||||
];
|
||||
// Indexing settings:
|
||||
$form['indexing_settings'] = array(
|
||||
$form['indexing_settings'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Default indexing settings'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['indexing_settings']['info'] = array(
|
||||
];
|
||||
$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>")
|
||||
);
|
||||
$form['indexing_settings']['minimum_word_size'] = array(
|
||||
];
|
||||
$form['indexing_settings']['minimum_word_size'] = [
|
||||
'#type' => 'number',
|
||||
'#title' => $this->t('Minimum word length to index'),
|
||||
'#default_value' => $search_settings->get('index.minimum_word_size'),
|
||||
'#min' => 1,
|
||||
'#max' => 1000,
|
||||
'#description' => $this->t('The minimum character length for a word to be added to the index. Searches must include a keyword of at least this length.'),
|
||||
);
|
||||
$form['indexing_settings']['overlap_cjk'] = array(
|
||||
];
|
||||
$form['indexing_settings']['overlap_cjk'] = [
|
||||
'#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.')
|
||||
);
|
||||
];
|
||||
|
||||
// Indexing settings:
|
||||
$form['logging'] = array(
|
||||
$form['logging'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Logging'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['logging']['logging'] = array(
|
||||
$form['logging']['logging'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Log searches'),
|
||||
'#default_value' => $search_settings->get('logging'),
|
||||
'#description' => $this->t('If checked, all searches will be logged. Uncheck to skip logging. Logging may affect performance.'),
|
||||
);
|
||||
];
|
||||
|
||||
$form['search_pages'] = array(
|
||||
$form['search_pages'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Search pages'),
|
||||
'#open' => TRUE,
|
||||
);
|
||||
$form['search_pages']['add_page'] = array(
|
||||
];
|
||||
$form['search_pages']['add_page'] = [
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('container-inline'),
|
||||
),
|
||||
);
|
||||
'#attributes' => [
|
||||
'class' => ['container-inline'],
|
||||
],
|
||||
];
|
||||
// In order to prevent validation errors for the parent form, this cannot be
|
||||
// required, see self::validateAddSearchPage().
|
||||
$form['search_pages']['add_page']['search_type'] = array(
|
||||
$form['search_pages']['add_page']['search_type'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Search page type'),
|
||||
'#empty_option' => $this->t('- Choose page type -'),
|
||||
'#options' => array_map(function ($definition) {
|
||||
return $definition['title'];
|
||||
}, $this->searchManager->getDefinitions()),
|
||||
);
|
||||
$form['search_pages']['add_page']['add_search_submit'] = array(
|
||||
];
|
||||
$form['search_pages']['add_page']['add_search_submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Add search page'),
|
||||
'#validate' => array('::validateAddSearchPage'),
|
||||
'#submit' => array('::submitAddSearchPage'),
|
||||
'#limit_validation_errors' => array(array('search_type')),
|
||||
);
|
||||
'#validate' => ['::validateAddSearchPage'],
|
||||
'#submit' => ['::submitAddSearchPage'],
|
||||
'#limit_validation_errors' => [['search_type']],
|
||||
];
|
||||
|
||||
// Move the listing into the search_pages element.
|
||||
$form['search_pages'][$this->entitiesKey] = $form[$this->entitiesKey];
|
||||
|
@ -281,11 +281,11 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
unset($form[$this->entitiesKey]);
|
||||
|
||||
$form['actions']['#type'] = 'actions';
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Save configuration'),
|
||||
'#button_type' => 'primary',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
@ -302,13 +302,13 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
unset($operations['disable'], $operations['delete']);
|
||||
}
|
||||
else {
|
||||
$operations['default'] = array(
|
||||
$operations['default'] = [
|
||||
'title' => $this->t('Set as default'),
|
||||
'url' => Url::fromRoute('entity.search_page.set_default', [
|
||||
'search_page' => $entity->id(),
|
||||
]),
|
||||
'weight' => 50,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $operations;
|
||||
|
@ -369,7 +369,7 @@ class SearchPageListBuilder extends DraggableListBuilder implements FormInterfac
|
|||
public function submitAddSearchPage(array &$form, FormStateInterface $form_state) {
|
||||
$form_state->setRedirect(
|
||||
'search.add_type',
|
||||
array('search_plugin_id' => $form_state->getValue('search_type'))
|
||||
['search_plugin_id' => $form_state->getValue('search_type')]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class SearchPageRepository implements SearchPageRepositoryInterface {
|
|||
*/
|
||||
public function sortSearchPages($search_pages) {
|
||||
$entity_type = $this->storage->getEntityType();
|
||||
uasort($search_pages, array($entity_type->getClass(), 'sort'));
|
||||
uasort($search_pages, [$entity_type->getClass(), 'sort']);
|
||||
return $search_pages;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class SearchQuery extends SelectExtender {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keys = array('positive' => array(), 'negative' => array());
|
||||
protected $keys = ['positive' => [], 'negative' => []];
|
||||
|
||||
/**
|
||||
* Indicates whether the query conditions are simple or complex (LIKE).
|
||||
|
@ -129,7 +129,7 @@ class SearchQuery extends SelectExtender {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $words = array();
|
||||
protected $words = [];
|
||||
|
||||
/**
|
||||
* Multiplier to normalize the keyword score.
|
||||
|
@ -164,14 +164,14 @@ class SearchQuery extends SelectExtender {
|
|||
*
|
||||
* @see SearchQuery::addScore()
|
||||
*/
|
||||
protected $scores = array();
|
||||
protected $scores = [];
|
||||
|
||||
/**
|
||||
* Arguments for the score expressions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $scoresArguments = array();
|
||||
protected $scoresArguments = [];
|
||||
|
||||
/**
|
||||
* The number of 'i.relevance' occurrences in score expressions.
|
||||
|
@ -185,7 +185,7 @@ class SearchQuery extends SelectExtender {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $multiply = array();
|
||||
protected $multiply = [];
|
||||
|
||||
/**
|
||||
* Sets the search query expression.
|
||||
|
@ -258,7 +258,7 @@ class SearchQuery extends SelectExtender {
|
|||
$words = search_simplify($match[2]);
|
||||
// Re-explode in case simplification added more words, except when
|
||||
// matching a phrase.
|
||||
$words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$words = $phrase ? [$words] : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
|
||||
// Negative matches.
|
||||
if ($match[1] == '-') {
|
||||
$this->keys['negative'] = array_merge($this->keys['negative'], $words);
|
||||
|
@ -269,7 +269,7 @@ class SearchQuery extends SelectExtender {
|
|||
$last = array_pop($this->keys['positive']);
|
||||
// Starting a new OR?
|
||||
if (!is_array($last)) {
|
||||
$last = array($last);
|
||||
$last = [$last];
|
||||
}
|
||||
$this->keys['positive'][] = $last;
|
||||
$in_or = TRUE;
|
||||
|
@ -373,7 +373,7 @@ class SearchQuery extends SelectExtender {
|
|||
}
|
||||
|
||||
// Return matching snippet and number of added words.
|
||||
return array($num_new_scores, $num_valid_words);
|
||||
return [$num_new_scores, $num_valid_words];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,7 +419,7 @@ class SearchQuery extends SelectExtender {
|
|||
// simple queries, this condition could lead to incorrectly deciding not
|
||||
// to continue with the full query.
|
||||
if ($this->simple) {
|
||||
$this->having('COUNT(*) >= :matches', array(':matches' => $this->matches));
|
||||
$this->having('COUNT(*) >= :matches', [':matches' => $this->matches]);
|
||||
}
|
||||
|
||||
// Clone the query object to calculate normalization.
|
||||
|
@ -498,7 +498,7 @@ class SearchQuery extends SelectExtender {
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addScore($score, $arguments = array(), $multiply = FALSE) {
|
||||
public function addScore($score, $arguments = [], $multiply = FALSE) {
|
||||
if ($multiply) {
|
||||
$i = count($this->multiply);
|
||||
// Modify the score expression so it is multiplied by the multiplier,
|
||||
|
@ -589,7 +589,7 @@ class SearchQuery extends SelectExtender {
|
|||
// Add query metadata.
|
||||
$this
|
||||
->addMetaData('normalize', $this->normalize)
|
||||
->fields('i', array('type', 'sid'));
|
||||
->fields('i', ['type', 'sid']);
|
||||
return $this->query->execute();
|
||||
}
|
||||
|
||||
|
@ -617,12 +617,12 @@ class SearchQuery extends SelectExtender {
|
|||
// Remove existing fields and expressions, they are not needed for a count
|
||||
// query.
|
||||
$fields =& $inner->getFields();
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
$expressions =& $inner->getExpressions();
|
||||
$expressions = array();
|
||||
$expressions = [];
|
||||
|
||||
// Add sid as the only field and count them as a subquery.
|
||||
$count = db_select($inner->fields('i', array('sid')), NULL, array('target' => 'replica'));
|
||||
$count = db_select($inner->fields('i', ['sid']), NULL, ['target' => 'replica']);
|
||||
|
||||
// Add the COUNT() expression.
|
||||
$count->addExpression('COUNT(*)');
|
||||
|
|
|
@ -19,7 +19,7 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes'));
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
||||
// Create initial node.
|
||||
|
@ -37,44 +37,44 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests advanced search by node type.
|
||||
*/
|
||||
function testNodeType() {
|
||||
public function testNodeType() {
|
||||
// Verify some properties of the node that was created.
|
||||
$this->assertTrue($this->node->getType() == 'page', 'Node type is Basic page.');
|
||||
$dummy_title = 'Lorem ipsum';
|
||||
$this->assertNotEqual($dummy_title, $this->node->label(), "Dummy title doesn't equal node title.");
|
||||
|
||||
// Search for the dummy title with a GET query.
|
||||
$this->drupalGet('search/node', array('query' => array('keys' => $dummy_title)));
|
||||
$this->drupalGet('search/node', ['query' => ['keys' => $dummy_title]]);
|
||||
$this->assertNoText($this->node->label(), 'Basic page node is not found with dummy title.');
|
||||
|
||||
// Search for the title of the node with a GET query.
|
||||
$this->drupalGet('search/node', array('query' => array('keys' => $this->node->label())));
|
||||
$this->drupalGet('search/node', ['query' => ['keys' => $this->node->label()]]);
|
||||
$this->assertText($this->node->label(), 'Basic page node is found with GET query.');
|
||||
|
||||
// Search for the title of the node with a POST query.
|
||||
$edit = array('or' => $this->node->label());
|
||||
$edit = ['or' => $this->node->label()];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
$this->assertText($this->node->label(), 'Basic page node is found with POST query.');
|
||||
|
||||
// Search by node type.
|
||||
$this->drupalPostForm('search/node', array_merge($edit, array('type[page]' => 'page')), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[page]' => 'page']), t('Advanced search'));
|
||||
$this->assertText($this->node->label(), 'Basic page node is found with POST query and type:page.');
|
||||
|
||||
$this->drupalPostForm('search/node', array_merge($edit, array('type[article]' => 'article')), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', array_merge($edit, ['type[article]' => 'article']), t('Advanced search'));
|
||||
$this->assertText('search yielded no results', 'Article node is not found with POST query and type:article.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that after submitting the advanced search form, the form is refilled.
|
||||
*/
|
||||
function testFormRefill() {
|
||||
$edit = array(
|
||||
public function testFormRefill() {
|
||||
$edit = [
|
||||
'keys' => 'cat',
|
||||
'or' => 'dog gerbil',
|
||||
'phrase' => 'pets are nice',
|
||||
'negative' => 'fish snake',
|
||||
'type[page]' => 'page',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
|
||||
// Test that the encoded query appears in the page title. Only test the
|
||||
|
@ -85,11 +85,11 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
// Verify that all of the form fields are filled out.
|
||||
foreach ($edit as $key => $value) {
|
||||
if ($key != 'type[page]') {
|
||||
$elements = $this->xpath('//input[@name=:name]', array(':name' => $key));
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertTrue(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is set to $value");
|
||||
}
|
||||
else {
|
||||
$elements = $this->xpath('//input[@name=:name]', array(':name' => $key));
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), "Field $key is checked");
|
||||
}
|
||||
}
|
||||
|
@ -97,12 +97,12 @@ class SearchAdvancedSearchFormTest extends SearchTestBase {
|
|||
// Now test by submitting the or/not part of the query in the main
|
||||
// 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 = array('keys' => 'cat dog OR gerbil -fish -snake');
|
||||
$edit2 = ['keys' => 'cat dog OR gerbil -fish -snake'];
|
||||
$this->drupalPostForm('search/node', $edit2, t('Advanced search'));
|
||||
$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]', array(':name' => $key));
|
||||
$elements = $this->xpath('//input[@name=:name]', [':name' => $key]);
|
||||
$this->assertFalse(isset($elements[0]) && $elements[0]['value'] == $value, "Field $key is not set to $value");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ class SearchBlockTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block');
|
||||
public static $modules = ['block'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$admin_user = $this->drupalCreateUser(array('administer blocks', 'search content'));
|
||||
$admin_user = $this->drupalCreateUser(['administer blocks', 'search content']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class SearchBlockTest extends SearchTestBase {
|
|||
$this->assertTrue(empty($elements), 'The search input field does not have empty name attribute.');
|
||||
|
||||
// Test a normal search via the block form, from the front page.
|
||||
$terms = array('keys' => 'test');
|
||||
$terms = ['keys' => 'test'];
|
||||
$this->submitGetForm('', $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Your search yielded no results');
|
||||
|
@ -72,12 +72,12 @@ class SearchBlockTest extends SearchTestBase {
|
|||
$entity_id = $search_page_repository->getDefaultSearchPage();
|
||||
$this->assertEqual(
|
||||
$this->getUrl(),
|
||||
\Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => $terms['keys']), 'absolute' => TRUE)),
|
||||
\Drupal::url('search.view_' . $entity_id, [], ['query' => ['keys' => $terms['keys']], 'absolute' => TRUE]),
|
||||
'Submitted to correct URL.'
|
||||
);
|
||||
|
||||
// Test an empty search via the block form, from the front page.
|
||||
$terms = array('keys' => '');
|
||||
$terms = ['keys' => ''];
|
||||
$this->submitGetForm('', $terms, t('Search'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertText('Please enter some keywords');
|
||||
|
@ -86,22 +86,22 @@ class SearchBlockTest extends SearchTestBase {
|
|||
// submitted empty.
|
||||
$this->assertEqual(
|
||||
$this->getUrl(),
|
||||
\Drupal::url('search.view_' . $entity_id, array(), array('query' => array('keys' => ''), 'absolute' => TRUE)),
|
||||
\Drupal::url('search.view_' . $entity_id, [], ['query' => ['keys' => ''], 'absolute' => TRUE]),
|
||||
'Redirected to correct URL.'
|
||||
);
|
||||
|
||||
// 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', array('keys' => $this->randomMachineName(1)), t('Search'));
|
||||
$this->submitGetForm('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, array('keys' => $this->randomMachineName()), t('Search'), 'search-block-form');
|
||||
$this->submitGetForm(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', array('keys' => $this->randomMachineName(1)), t('Search'));
|
||||
$this->drupalPostForm(NULL, array('keys' => $this->randomMachineName()), t('Search'), array(), array(), 'search-form');
|
||||
$this->submitGetForm('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');
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('filter', 'node', 'comment');
|
||||
public static $modules = ['filter', 'node', 'comment'];
|
||||
|
||||
/**
|
||||
* Test subject for comments.
|
||||
|
@ -55,17 +55,17 @@ class SearchCommentTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
$full_html_format = FilterFormat::create([
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
'weight' => 1,
|
||||
'filters' => array(),
|
||||
));
|
||||
'filters' => [],
|
||||
]);
|
||||
$full_html_format->save();
|
||||
|
||||
// Create and log in an administrative user having access to the Full HTML
|
||||
// text format.
|
||||
$permissions = array(
|
||||
$permissions = [
|
||||
'administer filters',
|
||||
$full_html_format->getPermissionName(),
|
||||
'administer permissions',
|
||||
|
@ -73,7 +73,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
'post comments',
|
||||
'skip comment approval',
|
||||
'access comments',
|
||||
);
|
||||
];
|
||||
$this->adminUser = $this->drupalCreateUser($permissions);
|
||||
$this->drupalLogin($this->adminUser);
|
||||
// Add a comment field.
|
||||
|
@ -83,18 +83,18 @@ class SearchCommentTest extends SearchTestBase {
|
|||
/**
|
||||
* Verify that comments are rendered using proper format in search results.
|
||||
*/
|
||||
function testSearchResultsComment() {
|
||||
public function testSearchResultsComment() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
// Create basic_html format that escapes all HTML.
|
||||
$basic_html_format = FilterFormat::create(array(
|
||||
$basic_html_format = FilterFormat::create([
|
||||
'format' => 'basic_html',
|
||||
'name' => 'Basic HTML',
|
||||
'weight' => 1,
|
||||
'filters' => array(
|
||||
'filter_html_escape' => array('status' => 1),
|
||||
),
|
||||
'roles' => array(RoleInterface::AUTHENTICATED_ID),
|
||||
));
|
||||
'filters' => [
|
||||
'filter_html_escape' => ['status' => 1],
|
||||
],
|
||||
'roles' => [RoleInterface::AUTHENTICATED_ID],
|
||||
]);
|
||||
$basic_html_format->save();
|
||||
|
||||
$comment_body = 'Test comment body';
|
||||
|
@ -105,17 +105,17 @@ class SearchCommentTest extends SearchTestBase {
|
|||
$field->save();
|
||||
|
||||
// Allow anonymous users to search content.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
RoleInterface::ANONYMOUS_ID . '[search content]' => 1,
|
||||
RoleInterface::ANONYMOUS_ID . '[access comments]' => 1,
|
||||
RoleInterface::ANONYMOUS_ID . '[post comments]' => 1,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/people/permissions', $edit, t('Save permissions'));
|
||||
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$node = $this->drupalCreateNode(['type' => 'article']);
|
||||
// Post a comment using 'Full HTML' text format.
|
||||
$edit_comment = array();
|
||||
$edit_comment = [];
|
||||
$edit_comment['subject[0][value]'] = 'Test comment subject';
|
||||
$edit_comment['comment_body[0][value]'] = '<h1>' . $comment_body . '</h1>';
|
||||
$full_html_format_id = 'full_html';
|
||||
|
@ -125,7 +125,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
// Post a comment with an evil script tag in the comment subject and a
|
||||
// script tag nearby a keyword in the comment body. Use the 'FULL HTML' text
|
||||
// format so the script tag stored.
|
||||
$edit_comment2 = array();
|
||||
$edit_comment2 = [];
|
||||
$edit_comment2['subject[0][value]'] = "<script>alert('subjectkeyword');</script>";
|
||||
$edit_comment2['comment_body[0][value]'] = "nearbykeyword<script>alert('somethinggeneric');</script>";
|
||||
$edit_comment2['comment_body[0][format]'] = $full_html_format_id;
|
||||
|
@ -133,7 +133,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
|
||||
// Post a comment with a keyword inside an evil script tag in the comment
|
||||
// body. Use the 'FULL HTML' text format so the script tag is stored.
|
||||
$edit_comment3 = array();
|
||||
$edit_comment3 = [];
|
||||
$edit_comment3['subject[0][value]'] = 'asubject';
|
||||
$edit_comment3['comment_body[0][value]'] = "<script>alert('insidekeyword');</script>";
|
||||
$edit_comment3['comment_body[0][format]'] = $full_html_format_id;
|
||||
|
@ -144,19 +144,19 @@ class SearchCommentTest extends SearchTestBase {
|
|||
$this->cronRun();
|
||||
|
||||
// Search for the comment subject.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'keys' => "'" . $edit_comment['subject[0][value]'] . "'",
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$node_storage->resetCache(array($node->id()));
|
||||
$node_storage->resetCache([$node->id()]);
|
||||
$node2 = $node_storage->load($node->id());
|
||||
$this->assertText($node2->label(), 'Node found in search results.');
|
||||
$this->assertText($edit_comment['subject[0][value]'], 'Comment subject found in search results.');
|
||||
|
||||
// Search for the comment body.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'keys' => "'" . $comment_body . "'",
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Search'));
|
||||
$this->assertText($node2->label(), 'Node found in search results.');
|
||||
|
||||
|
@ -166,9 +166,9 @@ class SearchCommentTest extends SearchTestBase {
|
|||
$this->assertNoEscaped($edit_comment['comment_body[0][value]'], 'HTML in comment body is not escaped.');
|
||||
|
||||
// Search for the evil script comment subject.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'keys' => 'subjectkeyword',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
|
||||
// Verify the evil comment subject is escaped in search results.
|
||||
|
@ -215,7 +215,7 @@ class SearchCommentTest extends SearchTestBase {
|
|||
/**
|
||||
* Verify access rules for comment indexing with different permissions.
|
||||
*/
|
||||
function testSearchResultsCommentAccess() {
|
||||
public function testSearchResultsCommentAccess() {
|
||||
$comment_body = 'Test comment body';
|
||||
$this->commentSubject = 'Test comment subject';
|
||||
$roles = $this->adminUser->getRoles(TRUE);
|
||||
|
@ -226,10 +226,10 @@ class SearchCommentTest extends SearchTestBase {
|
|||
$field = FieldConfig::loadByName('node', 'article', 'comment');
|
||||
$field->setSetting('preview', DRUPAL_OPTIONAL);
|
||||
$field->save();
|
||||
$this->node = $this->drupalCreateNode(array('type' => 'article'));
|
||||
$this->node = $this->drupalCreateNode(['type' => 'article']);
|
||||
|
||||
// Post a comment using 'Full HTML' text format.
|
||||
$edit_comment = array();
|
||||
$edit_comment = [];
|
||||
$edit_comment['subject[0][value]'] = $this->commentSubject;
|
||||
$edit_comment['comment_body[0][value]'] = '<h1>' . $comment_body . '</h1>';
|
||||
$this->drupalPostForm('comment/reply/node/' . $this->node->id() . '/comment', $edit_comment, t('Save'));
|
||||
|
@ -276,26 +276,26 @@ class SearchCommentTest extends SearchTestBase {
|
|||
/**
|
||||
* Set permissions for role.
|
||||
*/
|
||||
function setRolePermissions($rid, $access_comments = FALSE, $search_content = TRUE) {
|
||||
$permissions = array(
|
||||
public function setRolePermissions($rid, $access_comments = FALSE, $search_content = TRUE) {
|
||||
$permissions = [
|
||||
'access comments' => $access_comments,
|
||||
'search content' => $search_content,
|
||||
);
|
||||
];
|
||||
user_role_change_permissions($rid, $permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update search index and search for comment.
|
||||
*/
|
||||
function assertCommentAccess($assume_access, $message) {
|
||||
public function assertCommentAccess($assume_access, $message) {
|
||||
// Invoke search index update.
|
||||
search_mark_for_reindex('node_search', $this->node->id());
|
||||
$this->cronRun();
|
||||
|
||||
// Search for the comment subject.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'keys' => "'" . $this->commentSubject . "'",
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
|
||||
if ($assume_access) {
|
||||
|
@ -312,21 +312,21 @@ class SearchCommentTest extends SearchTestBase {
|
|||
/**
|
||||
* Verify that 'add new comment' does not appear in search results or index.
|
||||
*/
|
||||
function testAddNewComment() {
|
||||
public function testAddNewComment() {
|
||||
// Create a node with a short body.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => 'article',
|
||||
'title' => 'short title',
|
||||
'body' => array(array('value' => 'short body text')),
|
||||
);
|
||||
'body' => [['value' => 'short body text']],
|
||||
];
|
||||
|
||||
$user = $this->drupalCreateUser(array(
|
||||
$user = $this->drupalCreateUser([
|
||||
'search content',
|
||||
'create article content',
|
||||
'access content',
|
||||
'post comments',
|
||||
'access comments',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
@ -341,12 +341,12 @@ class SearchCommentTest extends SearchTestBase {
|
|||
|
||||
// Search for 'comment'. Should be no results.
|
||||
$this->drupalLogin($user);
|
||||
$this->drupalPostForm('search/node', array('keys' => 'comment'), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => 'comment'], t('Search'));
|
||||
$this->assertText(t('Your search yielded no results'));
|
||||
|
||||
// Search for the node title. Should be found, and 'Add new comment' should
|
||||
// not be part of the search snippet.
|
||||
$this->drupalPostForm('search/node', array('keys' => 'short'), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => 'short'], t('Search'));
|
||||
$this->assertText($node->label(), 'Search for keyword worked');
|
||||
$this->assertNoText(t('Add new comment'));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('block', 'search_extra_type', 'test_page_test');
|
||||
public static $modules = ['block', 'search_extra_type', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* User who can search and administer search.
|
||||
|
@ -37,7 +37,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Log in as a user that can create and search content.
|
||||
$this->searchUser = $this->drupalCreateUser(array('search content', 'administer search', 'administer nodes', 'bypass node access', 'access user profiles', 'administer users', 'administer blocks', 'access site reports'));
|
||||
$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);
|
||||
|
||||
// Add a single piece of content and index it.
|
||||
|
@ -61,42 +61,42 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
/**
|
||||
* Verifies the search settings form.
|
||||
*/
|
||||
function testSearchSettingsPage() {
|
||||
public function testSearchSettingsPage() {
|
||||
|
||||
// Test that the settings form displays the correct count of items left to index.
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
$this->assertText(t('There are @count items left to index.', array('@count' => 0)));
|
||||
$this->assertText(t('There are @count items left to index.', ['@count' => 0]));
|
||||
|
||||
// Test the re-index button.
|
||||
$this->drupalPostForm('admin/config/search/pages', array(), t('Re-index site'));
|
||||
$this->drupalPostForm('admin/config/search/pages', [], t('Re-index site'));
|
||||
$this->assertText(t('Are you sure you want to re-index the site'));
|
||||
$this->drupalPostForm('admin/config/search/pages/reindex', array(), t('Re-index site'));
|
||||
$this->drupalPostForm('admin/config/search/pages/reindex', [], t('Re-index site'));
|
||||
$this->assertText(t('All search indexes will be rebuilt'));
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
$this->assertText(t('There is 1 item left to index.'));
|
||||
|
||||
// Test that the form saves with the default values.
|
||||
$this->drupalPostForm('admin/config/search/pages', array(), t('Save configuration'));
|
||||
$this->drupalPostForm('admin/config/search/pages', [], t('Save configuration'));
|
||||
$this->assertText(t('The configuration options have been saved.'), 'Form saves with the default values.');
|
||||
|
||||
// Test that the form does not save with an invalid word length.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'minimum_word_size' => $this->randomMachineName(3),
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
|
||||
$this->assertNoText(t('The configuration options have been saved.'), 'Form does not save with an invalid word length.');
|
||||
|
||||
// Test logging setting. It should be off by default.
|
||||
$text = $this->randomMachineName(5);
|
||||
$this->drupalPostForm('search/node', array('keys' => $text), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => $text], t('Search'));
|
||||
$this->drupalGet('admin/reports/dblog');
|
||||
$this->assertNoLink('Searched Content for ' . $text . '.', 'Search was not logged');
|
||||
|
||||
// Turn on logging.
|
||||
$edit = array('logging' => TRUE);
|
||||
$edit = ['logging' => TRUE];
|
||||
$this->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
|
||||
$text = $this->randomMachineName(5);
|
||||
$this->drupalPostForm('search/node', array('keys' => $text), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => $text], t('Search'));
|
||||
$this->drupalGet('admin/reports/dblog');
|
||||
$this->assertLink('Searched Content for ' . $text . '.', 0, 'Search was logged');
|
||||
|
||||
|
@ -105,7 +105,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
/**
|
||||
* Verifies plugin-supplied settings form.
|
||||
*/
|
||||
function testSearchModuleSettingsPage() {
|
||||
public function testSearchModuleSettingsPage() {
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
$this->clickLink(t('Edit'), 1);
|
||||
|
||||
|
@ -113,13 +113,13 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
$this->assertTrue($this->xpath('//select[@id="edit-extra-type-settings-boost"]//option[@value="bi" and @selected="selected"]'), 'Module specific settings are picked up from the default config');
|
||||
|
||||
// Change extra type setting and also modify a common search setting.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'extra_type_settings[boost]' => 'ii',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save search page'));
|
||||
|
||||
// Ensure that the modifications took effect.
|
||||
$this->assertRaw(t('The %label search page has been updated.', array('%label' => 'Dummy search type')));
|
||||
$this->assertRaw(t('The %label search page has been updated.', ['%label' => 'Dummy search type']));
|
||||
$this->drupalGet('admin/config/search/pages/manage/dummy_search_type');
|
||||
$this->assertTrue($this->xpath('//select[@id="edit-extra-type-settings-boost"]//option[@value="ii" and @selected="selected"]'), 'Module specific settings can be changed');
|
||||
}
|
||||
|
@ -127,23 +127,23 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
/**
|
||||
* Verifies that you can disable individual search plugins.
|
||||
*/
|
||||
function testSearchModuleDisabling() {
|
||||
public function testSearchModuleDisabling() {
|
||||
// Array of search plugins to test: 'keys' are the keywords to search for,
|
||||
// and 'text' is the text to assert is on the results page.
|
||||
$plugin_info = array(
|
||||
'node_search' => array(
|
||||
$plugin_info = [
|
||||
'node_search' => [
|
||||
'keys' => 'pizza',
|
||||
'text' => $this->searchNode->label(),
|
||||
),
|
||||
'user_search' => array(
|
||||
],
|
||||
'user_search' => [
|
||||
'keys' => $this->searchUser->getUsername(),
|
||||
'text' => $this->searchUser->getEmail(),
|
||||
),
|
||||
'dummy_search_type' => array(
|
||||
],
|
||||
'dummy_search_type' => [
|
||||
'keys' => 'foo',
|
||||
'text' => 'Dummy search snippet to display',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$plugins = array_keys($plugin_info);
|
||||
/** @var $entities \Drupal\search\SearchPageInterface[] */
|
||||
$entities = SearchPage::loadMultiple();
|
||||
|
@ -158,7 +158,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
|
||||
// Run a search from the correct search URL.
|
||||
$info = $plugin_info[$entity_id];
|
||||
$this->drupalGet('search/' . $entity->getPath(), array('query' => array('keys' => $info['keys'])));
|
||||
$this->drupalGet('search/' . $entity->getPath(), ['query' => ['keys' => $info['keys']]]);
|
||||
$this->assertResponse(200);
|
||||
$this->assertNoText('no results', $entity->label() . ' search found results');
|
||||
$this->assertText($info['text'], 'Correct search text found');
|
||||
|
@ -173,10 +173,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 = array('keys' => $info['keys']);
|
||||
$terms = ['keys' => $info['keys']];
|
||||
$this->submitGetForm('node', $terms, t('Search'));
|
||||
$current = $this->getURL();
|
||||
$expected = \Drupal::url('search.view_' . $entity->id(), array(), array('query' => array('keys' => $info['keys']), 'absolute' => TRUE));
|
||||
$expected = \Drupal::url('search.view_' . $entity->id(), [], ['query' => ['keys' => $info['keys']], 'absolute' => TRUE]);
|
||||
$this->assertEqual( $current, $expected, 'Block redirected to right search page');
|
||||
|
||||
// Try an invalid search path, which should 404.
|
||||
|
@ -197,16 +197,16 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$paths = array(
|
||||
array('path' => 'search/node', 'options' => array('query' => array('keys' => 'pizza'))),
|
||||
array('path' => 'search/node', 'options' => array()),
|
||||
);
|
||||
$paths = [
|
||||
['path' => 'search/node', 'options' => ['query' => ['keys' => 'pizza']]],
|
||||
['path' => 'search/node', 'options' => []],
|
||||
];
|
||||
|
||||
foreach ($paths as $item) {
|
||||
$this->drupalGet($item['path'], $item['options']);
|
||||
foreach ($plugins as $entity_id) {
|
||||
$label = $entities[$entity_id]->label();
|
||||
$this->assertText($label, format_string('%label search tab is shown', array('%label' => $label)));
|
||||
$this->assertText($label, format_string('%label search tab is shown', ['%label' => $label]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
*/
|
||||
public function testDefaultSearchPageOrdering() {
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', array(':class' => 'tabs primary'));
|
||||
$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'));
|
||||
|
@ -237,24 +237,24 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
$this->assertText(t('No search pages have been configured.'));
|
||||
|
||||
// Add a search page.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['search_type'] = 'search_extra_type_search';
|
||||
$this->drupalPostForm(NULL, $edit, t('Add search page'));
|
||||
$this->assertTitle('Add new search page | Drupal');
|
||||
|
||||
$first = array();
|
||||
$first = [];
|
||||
$first['label'] = $this->randomString();
|
||||
$first_id = $first['id'] = strtolower($this->randomMachineName(8));
|
||||
$first['path'] = strtolower($this->randomMachineName(8));
|
||||
$this->drupalPostForm(NULL, $first, t('Save'));
|
||||
$this->assertDefaultSearch($first_id, 'The default page matches the only search page.');
|
||||
$this->assertRaw(t('The %label search page has been added.', array('%label' => $first['label'])));
|
||||
$this->assertRaw(t('The %label search page has been added.', ['%label' => $first['label']]));
|
||||
|
||||
// Attempt to add a search page with an existing path.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['search_type'] = 'search_extra_type_search';
|
||||
$this->drupalPostForm(NULL, $edit, t('Add search page'));
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['label'] = $this->randomString();
|
||||
$edit['id'] = strtolower($this->randomMachineName(8));
|
||||
$edit['path'] = $first['path'];
|
||||
|
@ -262,7 +262,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
$this->assertText(t('The search page path must be unique.'));
|
||||
|
||||
// Add a second search page.
|
||||
$second = array();
|
||||
$second = [];
|
||||
$second['label'] = $this->randomString();
|
||||
$second_id = $second['id'] = strtolower($this->randomMachineName(8));
|
||||
$second['path'] = strtolower($this->randomMachineName(8));
|
||||
|
@ -271,18 +271,18 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
|
||||
// Ensure both search pages have their tabs displayed.
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', array(':class' => 'tabs primary'));
|
||||
$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());
|
||||
|
||||
// Switch the weight of the search pages and check the order of the tabs.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'entities[' . $first_id . '][weight]' => 10,
|
||||
'entities[' . $second_id . '][weight]' => -10,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('admin/config/search/pages', $edit, t('Save configuration'));
|
||||
$this->drupalGet('search');
|
||||
$elements = $this->xpath('//*[contains(@class, :class)]//a', array(':class' => 'tabs primary'));
|
||||
$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());
|
||||
|
||||
|
@ -293,7 +293,7 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
|
||||
// Change the default search page.
|
||||
$this->clickLink(t('Set as default'));
|
||||
$this->assertRaw(t('The default search page is now %label. Be sure to check the ordering of your search pages.', array('%label' => $second['label'])));
|
||||
$this->assertRaw(t('The default search page is now %label. Be sure to check the ordering of your search pages.', ['%label' => $second['label']]));
|
||||
$this->verifySearchPageOperations($first_id, TRUE, TRUE, TRUE, FALSE);
|
||||
$this->verifySearchPageOperations($second_id, TRUE, FALSE, FALSE, FALSE);
|
||||
|
||||
|
@ -312,9 +312,9 @@ class SearchConfigSettingsFormTest extends SearchTestBase {
|
|||
|
||||
// Test deleting.
|
||||
$this->clickLink(t('Delete'));
|
||||
$this->assertRaw(t('Are you sure you want to delete the search page %label?', array('%label' => $first['label'])));
|
||||
$this->drupalPostForm(NULL, array(), t('Delete'));
|
||||
$this->assertRaw(t('The search page %label has been deleted.', array('%label' => $first['label'])));
|
||||
$this->assertRaw(t('Are you sure you want to delete the search page %label?', ['%label' => $first['label']]));
|
||||
$this->drupalPostForm(NULL, [], t('Delete'));
|
||||
$this->assertRaw(t('The search page %label has been deleted.', ['%label' => $first['label']]));
|
||||
$this->verifySearchPageOperations($first_id, FALSE, FALSE, FALSE, FALSE);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search_embedded_form');
|
||||
public static $modules = ['search_embedded_form'];
|
||||
|
||||
/**
|
||||
* Node used for testing.
|
||||
|
@ -34,7 +34,7 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create a user and a node, and update the search index.
|
||||
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'administer nodes'));
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'administer nodes']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
||||
$this->node = $this->drupalCreateNode();
|
||||
|
@ -50,10 +50,10 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that the embedded form appears and can be submitted.
|
||||
*/
|
||||
function testEmbeddedForm() {
|
||||
public function testEmbeddedForm() {
|
||||
// First verify we can submit the form from the module's page.
|
||||
$this->drupalPostForm('search_embedded_form',
|
||||
array('name' => 'John'),
|
||||
['name' => 'John'],
|
||||
t('Send away'));
|
||||
$this->assertText(t('Test form was submitted'), 'Form message appears');
|
||||
$count = \Drupal::state()->get('search_embedded_form.submit_count');
|
||||
|
@ -61,10 +61,10 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
$this->submitCount = $count;
|
||||
|
||||
// Now verify that we can see and submit the form from the search results.
|
||||
$this->drupalGet('search/node', array('query' => array('keys' => $this->node->label())));
|
||||
$this->drupalGet('search/node', ['query' => ['keys' => $this->node->label()]]);
|
||||
$this->assertText(t('Your name'), 'Form is visible');
|
||||
$this->drupalPostForm(NULL,
|
||||
array('name' => 'John'),
|
||||
['name' => 'John'],
|
||||
t('Send away'));
|
||||
$this->assertText(t('Test form was submitted'), 'Form message appears');
|
||||
$count = \Drupal::state()->get('search_embedded_form.submit_count');
|
||||
|
@ -74,7 +74,7 @@ class SearchEmbedFormTest extends SearchTestBase {
|
|||
// Now verify that if we submit the search form, it doesn't count as
|
||||
// our form being submitted.
|
||||
$this->drupalPostForm('search',
|
||||
array('keys' => 'foo'),
|
||||
['keys' => 'foo'],
|
||||
t('Search'));
|
||||
$this->assertNoText(t('Test form was submitted'), 'Form message does not appear');
|
||||
$count = \Drupal::state()->get('search_embedded_form.submit_count');
|
||||
|
|
|
@ -17,7 +17,7 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('language');
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* Array of nodes available to search.
|
||||
|
@ -30,7 +30,7 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration'));
|
||||
$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);
|
||||
|
||||
// Add a new language.
|
||||
|
@ -45,38 +45,38 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
|
||||
// Create a few page nodes with multilingual body values.
|
||||
$default_format = filter_default_format();
|
||||
$nodes = array(
|
||||
array(
|
||||
$nodes = [
|
||||
[
|
||||
'title' => 'First node en',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'title' => 'Second node this is the Spanish title',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'es',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'title' => 'Third node en',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$this->searchableNodes = [];
|
||||
foreach ($nodes as $setting) {
|
||||
$this->searchableNodes[] = $this->drupalCreateNode($setting);
|
||||
}
|
||||
|
||||
// Add English translation to the second node.
|
||||
$translation = $this->searchableNodes[1]->addTranslation('en', array('title' => 'Second node en'));
|
||||
$translation = $this->searchableNodes[1]->addTranslation('en', ['title' => 'Second node en']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$this->searchableNodes[1]->save();
|
||||
|
||||
// Add Spanish translation to the third node.
|
||||
$translation = $this->searchableNodes[2]->addTranslation('es', array('title' => 'Third node es'));
|
||||
$translation = $this->searchableNodes[2]->addTranslation('es', ['title' => 'Third node es']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$this->searchableNodes[2]->save();
|
||||
|
||||
|
@ -86,9 +86,9 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
}
|
||||
|
||||
function testLanguages() {
|
||||
public function testLanguages() {
|
||||
// Add predefined language.
|
||||
$edit = array('predefined_langcode' => 'fr');
|
||||
$edit = ['predefined_langcode' => 'fr'];
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
||||
$this->assertText('French', 'Language added successfully.');
|
||||
|
||||
|
@ -99,11 +99,11 @@ 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', array(), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', [], t('Advanced search'));
|
||||
$this->assertUrl(\Drupal::url('search.view_node_search', [], ['query' => ['keys' => ''], 'absolute' => TRUE]), [], 'Correct page redirection, no language filtering.');
|
||||
|
||||
// Pick French and ensure it is selected.
|
||||
$edit = array('language[fr]' => TRUE);
|
||||
$edit = ['language[fr]' => TRUE];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
// Get the redirected URL.
|
||||
$url = $this->getUrl();
|
||||
|
@ -112,7 +112,7 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
$this->assertTrue(strpos($query_string, '=language:fr') !== FALSE, 'Language filter language:fr add to the query string.');
|
||||
|
||||
// Search for keyword node and language filter as Spanish.
|
||||
$edit = array('keys' => 'node', 'language[es]' => TRUE);
|
||||
$edit = ['keys' => 'node', 'language[es]' => TRUE];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
// Check for Spanish results.
|
||||
$this->assertLink('Second node this is the Spanish title', 0, 'Second node Spanish title found in search results');
|
||||
|
@ -126,12 +126,12 @@ class SearchLanguageTest extends SearchTestBase {
|
|||
$path = 'admin/config/regional/language';
|
||||
$this->drupalGet($path);
|
||||
$this->assertFieldChecked('edit-site-default-language-en', 'Default language updated.');
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'site_default_language' => 'fr',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm($path, $edit, t('Save configuration'));
|
||||
$this->assertNoFieldChecked('edit-site-default-language-en', 'Default language updated.');
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', array(), t('Delete'));
|
||||
$this->drupalPostForm('admin/config/regional/language/delete/en', [], t('Delete'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array();
|
||||
public static $modules = [];
|
||||
|
||||
/**
|
||||
* A user with permission to access and search content.
|
||||
|
@ -27,19 +27,19 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(array('access content', 'search content'));
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the search index info is properly updated when a node changes.
|
||||
*/
|
||||
function testSearchIndexUpdateOnNodeChange() {
|
||||
public function testSearchIndexUpdateOnNodeChange() {
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array(
|
||||
$node = $this->drupalCreateNode([
|
||||
'title' => 'Someone who says Ni!',
|
||||
'body' => array(array('value' => "We are the knights who say Ni!")),
|
||||
'type' => 'page'));
|
||||
'body' => [['value' => "We are the knights who say Ni!"]],
|
||||
'type' => 'page']);
|
||||
|
||||
$node_search_plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Update the search index.
|
||||
|
@ -47,7 +47,7 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
|
||||
// Search the node to verify it appears in search results
|
||||
$edit = array('keys' => 'knights');
|
||||
$edit = ['keys' => 'knights'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($node->label());
|
||||
|
||||
|
@ -60,7 +60,7 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
|
||||
// Search again to verify the new text appears in test results.
|
||||
$edit = array('keys' => 'shrubbery');
|
||||
$edit = ['keys' => 'shrubbery'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($node->label());
|
||||
}
|
||||
|
@ -68,12 +68,12 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that the search index info is updated when a node is deleted.
|
||||
*/
|
||||
function testSearchIndexUpdateOnNodeDeletion() {
|
||||
public function testSearchIndexUpdateOnNodeDeletion() {
|
||||
// Create a node.
|
||||
$node = $this->drupalCreateNode(array(
|
||||
$node = $this->drupalCreateNode([
|
||||
'title' => 'No dragons here',
|
||||
'body' => array(array('value' => 'Again: No dragons here')),
|
||||
'type' => 'page'));
|
||||
'body' => [['value' => 'Again: No dragons here']],
|
||||
'type' => 'page']);
|
||||
|
||||
$node_search_plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Update the search index.
|
||||
|
@ -81,12 +81,12 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
|
||||
// Search the node to verify it appears in search results
|
||||
$edit = array('keys' => 'dragons');
|
||||
$edit = ['keys' => 'dragons'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($node->label());
|
||||
|
||||
// Get the node info from the search index tables.
|
||||
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", array(':word' => 'dragons'))
|
||||
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [':word' => 'dragons'])
|
||||
->fetchField();
|
||||
$this->assertNotEqual($search_index_dataset, FALSE, t('Node info found on the search_index'));
|
||||
|
||||
|
@ -94,7 +94,7 @@ class SearchNodeUpdateAndDeletionTest extends SearchTestBase {
|
|||
$node->delete();
|
||||
|
||||
// Check if the node info is gone from the search table.
|
||||
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", array(':word' => 'dragons'))
|
||||
$search_index_dataset = db_query("SELECT sid FROM {search_index} WHERE type = 'node_search' AND word = :word", [':word' => 'dragons'])
|
||||
->fetchField();
|
||||
$this->assertFalse($search_index_dataset, t('Node info successfully removed from search_index'));
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $numbers = array(
|
||||
protected $numbers = [
|
||||
'123456789',
|
||||
'12/34/56789',
|
||||
'12.3456789',
|
||||
|
@ -35,7 +35,7 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
'123,456,789',
|
||||
'-123456789',
|
||||
'0123456789',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* An array of nodes created for testing purposes.
|
||||
|
@ -47,15 +47,15 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->testUser = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
|
||||
$this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
||||
foreach ($this->numbers as $num) {
|
||||
$info = array(
|
||||
'body' => array(array('value' => $num)),
|
||||
$info = [
|
||||
'body' => [['value' => $num]],
|
||||
'type' => 'page',
|
||||
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
);
|
||||
];
|
||||
$this->nodes[] = $this->drupalCreateNode($info);
|
||||
}
|
||||
|
||||
|
@ -68,16 +68,16 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that all the numbers can be searched.
|
||||
*/
|
||||
function testNumberSearching() {
|
||||
public function testNumberSearching() {
|
||||
for ($i = 0; $i < count($this->numbers); $i++) {
|
||||
$node = $this->nodes[$i];
|
||||
|
||||
// Verify that the node title does not appear on the search page
|
||||
// with a dummy search.
|
||||
$this->drupalPostForm('search/node',
|
||||
array('keys' => 'foo'),
|
||||
['keys' => 'foo'],
|
||||
t('Search'));
|
||||
$this->assertNoText($node->label(), format_string('%number: node title not shown in dummy search', array('%number' => $i)));
|
||||
$this->assertNoText($node->label(), format_string('%number: node title not shown in dummy search', ['%number' => $i]));
|
||||
|
||||
// Now verify that we can find node i by searching for any of the
|
||||
// numbers.
|
||||
|
@ -88,9 +88,9 @@ class SearchNumberMatchingTest extends SearchTestBase {
|
|||
$number = ltrim($number, '-');
|
||||
|
||||
$this->drupalPostForm('search/node',
|
||||
array('keys' => $number),
|
||||
['keys' => $number],
|
||||
t('Search'));
|
||||
$this->assertText($node->label(), format_string('%i: node title shown (search found the node) in search for number %number', array('%i' => $i, '%number' => $number)));
|
||||
$this->assertText($node->label(), format_string('%i: node title shown (search found the node) in search for number %number', ['%i' => $i, '%number' => $number]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $numbers = array(
|
||||
protected $numbers = [
|
||||
'ISBN' => '978-0446365383',
|
||||
'UPC' => '036000 291452',
|
||||
'EAN bar code' => '5901234123457',
|
||||
|
@ -41,7 +41,7 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666',
|
||||
'date' => '01/02/2009',
|
||||
'commas' => '987,654,321',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* An array of nodes created for testing purposes.
|
||||
|
@ -53,16 +53,16 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->testUser = $this->drupalCreateUser(array('search content', 'access content', 'administer nodes', 'access site reports'));
|
||||
$this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
|
||||
foreach ($this->numbers as $doc => $num) {
|
||||
$info = array(
|
||||
'body' => array(array('value' => $num)),
|
||||
$info = [
|
||||
'body' => [['value' => $num]],
|
||||
'type' => 'page',
|
||||
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
'title' => $doc . ' number',
|
||||
);
|
||||
];
|
||||
$this->nodes[$doc] = $this->drupalCreateNode($info);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that all the numbers can be searched.
|
||||
*/
|
||||
function testNumberSearching() {
|
||||
public function testNumberSearching() {
|
||||
$types = array_keys($this->numbers);
|
||||
|
||||
foreach ($types as $type) {
|
||||
|
@ -88,16 +88,16 @@ class SearchNumbersTest extends SearchTestBase {
|
|||
// Verify that the node title does not appear on the search page
|
||||
// with a dummy search.
|
||||
$this->drupalPostForm('search/node',
|
||||
array('keys' => 'foo'),
|
||||
['keys' => 'foo'],
|
||||
t('Search'));
|
||||
$this->assertNoText($node->label(), $type . ': node title not shown in dummy search');
|
||||
|
||||
// Verify that the node title does appear as a link on the search page
|
||||
// when searching for the number.
|
||||
$this->drupalPostForm('search/node',
|
||||
array('keys' => $number),
|
||||
['keys' => $number],
|
||||
t('Search'));
|
||||
$this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', array('%type' => $type, '%number' => $number)));
|
||||
$this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create user.
|
||||
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access user profiles'));
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access user profiles']);
|
||||
|
||||
// Create a node and update the search index.
|
||||
$this->node = $this->drupalCreateNode(['title' => 'bike shed shop']);
|
||||
|
@ -50,7 +50,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests the presence of the expected cache tag in various situations.
|
||||
*/
|
||||
function testSearchText() {
|
||||
public function testSearchText() {
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
|
||||
// Initial page for searching nodes.
|
||||
|
@ -60,7 +60,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->assertCacheTag('node_list');
|
||||
|
||||
// Node search results.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['keys'] = 'bike shed';
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText('bike shed shop');
|
||||
|
@ -70,6 +70,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->assertCacheTag('node:1');
|
||||
$this->assertCacheTag('user:2');
|
||||
$this->assertCacheTag('rendered');
|
||||
$this->assertCacheTag('http_response');
|
||||
$this->assertCacheTag('node_list');
|
||||
|
||||
// Updating a node should invalidate the search plugin's index cache tag.
|
||||
|
@ -83,6 +84,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
$this->assertCacheTag('node:1');
|
||||
$this->assertCacheTag('user:2');
|
||||
$this->assertCacheTag('rendered');
|
||||
$this->assertCacheTag('http_response');
|
||||
$this->assertCacheTag('node_list');
|
||||
|
||||
// Deleting a node should invalidate the search plugin's index cache tag.
|
||||
|
@ -172,6 +174,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
'config:search.page.node_search',
|
||||
'search_index',
|
||||
'search_index:node_search',
|
||||
'http_response',
|
||||
'rendered',
|
||||
'node_list',
|
||||
];
|
||||
|
@ -179,7 +182,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
// Node search results for shop, should return node:1 (bike shed shop) and
|
||||
// node:2 (Llama shop). The related authors cache tags should be visible as
|
||||
// well.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['keys'] = 'shop';
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText('bike shed shop');
|
||||
|
@ -192,13 +195,12 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
'node_view',
|
||||
'config:filter.format.plain_text',
|
||||
]);
|
||||
$cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
|
||||
$this->assertEqual(explode(' ', $cache_tags), $expected_cache_tags);
|
||||
$this->assertCacheTags($expected_cache_tags);
|
||||
|
||||
// Only get the new node in the search results, should result in node:1,
|
||||
// node:2 and user:3 as cache tags even though only node:1 is shown. This is
|
||||
// because node:2 is reference in node:1 as an entity reference.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['keys'] = 'Llama';
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText('Llama shop');
|
||||
|
@ -208,8 +210,7 @@ class SearchPageCacheTagsTest extends SearchTestBase {
|
|||
'user:3',
|
||||
'node_view',
|
||||
]);
|
||||
$cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
|
||||
$this->assertEqual(explode(' ', $cache_tags), $expected_cache_tags);
|
||||
$this->assertCacheTags($expected_cache_tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create user.
|
||||
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access user profiles', 'use advanced search'));
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access user profiles', 'use advanced search']);
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
*
|
||||
* This is a regression test for https://www.drupal.org/node/2338081
|
||||
*/
|
||||
function testSearchLabelXSS() {
|
||||
$this->drupalLogin($this->drupalCreateUser(array('administer search')));
|
||||
public function testSearchLabelXSS() {
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer search']));
|
||||
|
||||
$keys['label'] = '<script>alert("Dont Panic");</script>';
|
||||
$this->drupalPostForm('admin/config/search/pages/manage/node_search', $keys, t('Save search page'));
|
||||
|
@ -56,21 +56,21 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests the failed search text, and various other text on the search page.
|
||||
*/
|
||||
function testSearchText() {
|
||||
public function testSearchText() {
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
$this->drupalGet('search/node');
|
||||
$this->assertText(t('Enter your keywords'));
|
||||
$this->assertText(t('Search'));
|
||||
$this->assertTitle(t('Search') . ' | Drupal', 'Search page title is correct');
|
||||
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$search_terms = 'bike shed ' . $this->randomMachineName();
|
||||
$edit['keys'] = $search_terms;
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText('search yielded no results');
|
||||
$this->assertText(t('Search'));
|
||||
$title_source = 'Search for @keywords | Drupal';
|
||||
$this->assertTitle(t($title_source, array('@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE))), 'Search page title is correct');
|
||||
$this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)]), 'Search page title is correct');
|
||||
$this->assertNoText('Node', 'Erroneous tab and breadcrumb text is not present');
|
||||
$this->assertNoText(t('Node'), 'Erroneous translated tab and breadcrumb text is not present');
|
||||
$this->assertText(t('Content'), 'Tab and breadcrumb text is present');
|
||||
|
@ -80,23 +80,23 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
$this->assertText('Use upper-case OR to get more results', 'Correct text is on content search help page');
|
||||
|
||||
// Search for a longer text, and see that it is in the title, truncated.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$search_terms = 'Every word is like an unnecessary stain on silence and nothingness.';
|
||||
$edit['keys'] = $search_terms;
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertTitle(t($title_source, array('@keywords' => 'Every word is like an unnecessary stain on silence and…')), 'Search page title is correct');
|
||||
$this->assertTitle(t($title_source, ['@keywords' => 'Every word is like an unnecessary stain on silence and…']), 'Search page title is correct');
|
||||
|
||||
// Search for a string with a lot of special characters.
|
||||
$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'));
|
||||
$this->assertEqual($actual_title, Html::decodeEntities(t($title_source, array('@keywords' => Unicode::truncate($search_terms, 60, TRUE, TRUE)))), 'Search page title is correct');
|
||||
$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();
|
||||
$this->drupalPostForm('search/user', $edit, t('Search'));
|
||||
$this->assertText(t('Search'));
|
||||
$this->assertTitle(t($title_source, array('@keywords' => Unicode::truncate($this->searchingUser->getUsername(), 60, TRUE, TRUE))));
|
||||
$this->assertTitle(t($title_source, ['@keywords' => Unicode::truncate($this->searchingUser->getUsername(), 60, TRUE, TRUE)]));
|
||||
|
||||
$this->clickLink('Search help');
|
||||
$this->assertText('Search help', 'Correct title is on search help page');
|
||||
|
@ -105,14 +105,14 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
// Test that search keywords containing slashes are correctly loaded
|
||||
// from the GET params and displayed in the search form.
|
||||
$arg = $this->randomMachineName() . '/' . $this->randomMachineName();
|
||||
$this->drupalGet('search/node', array('query' => array('keys' => $arg)));
|
||||
$this->drupalGet('search/node', ['query' => ['keys' => $arg]]);
|
||||
$input = $this->xpath("//input[@id='edit-keys' and @value='{$arg}']");
|
||||
$this->assertFalse(empty($input), 'Search keys with a / are correctly set as the default value in the search box.');
|
||||
|
||||
// Test a search input exceeding the limit of AND/OR combinations to test
|
||||
// the Denial-of-Service protection.
|
||||
$limit = $this->config('search.settings')->get('and_or_limit');
|
||||
$keys = array();
|
||||
$keys = [];
|
||||
for ($i = 0; $i < $limit + 1; $i++) {
|
||||
// Use a key of 4 characters to ensure we never generate 'AND' or 'OR'.
|
||||
$keys[] = $this->randomMachineName(4);
|
||||
|
@ -122,40 +122,40 @@ class SearchPageTextTest extends SearchTestBase {
|
|||
}
|
||||
$edit['keys'] = implode(' ', $keys);
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', array('@count' => $limit)));
|
||||
$this->assertRaw(t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', ['@count' => $limit]));
|
||||
|
||||
// Test that a search on Node or User with no keywords entered generates
|
||||
// the "Please enter some keywords" message.
|
||||
$this->drupalPostForm('search/node', array(), t('Search'));
|
||||
$this->drupalPostForm('search/node', [], t('Search'));
|
||||
$this->assertText(t('Please enter some keywords'), 'With no keywords entered, message is displayed on node page');
|
||||
$this->drupalPostForm('search/user', array(), t('Search'));
|
||||
$this->drupalPostForm('search/user', [], t('Search'));
|
||||
$this->assertText(t('Please enter some keywords'), 'With no keywords entered, message is displayed on user page');
|
||||
|
||||
// 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', array('or' => $this->randomMachineName() . ' ' . $this->randomMachineName()), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', ['or' => $this->randomMachineName() . ' ' . $this->randomMachineName()], t('Advanced search'));
|
||||
$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', array('phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'), t('Advanced search'));
|
||||
$this->drupalPostForm('search/node', ['phrase' => '"' . $this->randomMachineName() . '" "' . $this->randomMachineName() . '"'], t('Advanced search'));
|
||||
$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
|
||||
// message, and that if after that you search for a longer keyword, you
|
||||
// do not still see the message.
|
||||
$this->drupalPostForm('search/node', array('keys' => $this->randomMachineName(1)), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => $this->randomMachineName(1)], t('Search'));
|
||||
$this->assertText('You must include at least one keyword', '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->drupalPostForm(NULL, array('keys' => $this->randomMachineName()), t('Search'));
|
||||
$this->drupalPostForm(NULL, ['keys' => $this->randomMachineName()], t('Search'));
|
||||
$this->assertNoText('You must include at least one keyword', 'Keyword message is not displayed when searching for long word after short word search');
|
||||
|
||||
// Test that if you search for a URL with .. in it, you still end up at
|
||||
// the search page. See issue https://www.drupal.org/node/890058.
|
||||
$this->drupalPostForm('search/node', array('keys' => '../../admin'), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => '../../admin'], t('Search'));
|
||||
$this->assertResponse(200, 'Searching for ../../admin with non-admin user does not lead to a 403 error');
|
||||
$this->assertText('no results', 'Searching for ../../admin with non-admin user gives you a no search results page');
|
||||
|
||||
// Test that if you search for a URL starting with "./", you still end up
|
||||
// at the search page. See issue https://www.drupal.org/node/1421560.
|
||||
$this->drupalPostForm('search/node', array('keys' => '.something'), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => '.something'], t('Search'));
|
||||
$this->assertResponse(200, 'Searching for .something does not lead to a 403 error');
|
||||
$this->assertText('no results', 'Searching for .something gives you a no search results page');
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search_langcode_test');
|
||||
public static $modules = ['search_langcode_test'];
|
||||
|
||||
/**
|
||||
* Test node for searching.
|
||||
|
@ -26,21 +26,21 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$web_user = $this->drupalCreateUser(array(
|
||||
$web_user = $this->drupalCreateUser([
|
||||
'create page content',
|
||||
'edit own page content',
|
||||
'search content',
|
||||
'use advanced search',
|
||||
));
|
||||
]);
|
||||
$this->drupalLogin($web_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that hook_search_preprocess() returns the correct langcode.
|
||||
*/
|
||||
function testPreprocessLangcode() {
|
||||
public function testPreprocessLangcode() {
|
||||
// Create a node.
|
||||
$this->node = $this->drupalCreateNode(array('body' => array(array()), 'langcode' => 'en'));
|
||||
$this->node = $this->drupalCreateNode(['body' => [[]], 'langcode' => 'en']);
|
||||
|
||||
// First update the index. This does the initial processing.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
@ -53,7 +53,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
// Search for the additional text that is added by the preprocess
|
||||
// function. If you search for text that is in the node, preprocess is
|
||||
// not invoked on the node during the search excerpt generation.
|
||||
$edit = array('or' => 'Additional text');
|
||||
$edit = ['or' => 'Additional text'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
|
||||
// Checks if the langcode message has been set by hook_search_preprocess().
|
||||
|
@ -63,13 +63,13 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests stemming for hook_search_preprocess().
|
||||
*/
|
||||
function testPreprocessStemming() {
|
||||
public function testPreprocessStemming() {
|
||||
// Create a node.
|
||||
$this->node = $this->drupalCreateNode(array(
|
||||
$this->node = $this->drupalCreateNode([
|
||||
'title' => 'we are testing',
|
||||
'body' => array(array()),
|
||||
'body' => [[]],
|
||||
'langcode' => 'en',
|
||||
));
|
||||
]);
|
||||
|
||||
// First update the index. This does the initial processing.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
@ -80,7 +80,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
|
||||
// Search for the title of the node with a POST query.
|
||||
$edit = array('or' => 'testing');
|
||||
$edit = ['or' => 'testing'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
|
||||
// Check if the node has been found.
|
||||
|
@ -88,7 +88,7 @@ class SearchPreprocessLangcodeTest extends SearchTestBase {
|
|||
$this->assertText('we are testing');
|
||||
|
||||
// Search for the same node using a different query.
|
||||
$edit = array('or' => 'test');
|
||||
$edit = ['or' => 'test'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Advanced search'));
|
||||
|
||||
// Check if the node has been found.
|
||||
|
|
|
@ -13,22 +13,22 @@ class SearchQueryAlterTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search_query_alter');
|
||||
public static $modules = ['search_query_alter'];
|
||||
|
||||
/**
|
||||
* Tests that the query alter works.
|
||||
*/
|
||||
function testQueryAlter() {
|
||||
public function testQueryAlter() {
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('create page content', 'search content')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['create page content', 'search content']));
|
||||
|
||||
// Create a node and an article with the same keyword. The query alter
|
||||
// test module will alter the query so only articles should be returned.
|
||||
$data = array(
|
||||
$data = [
|
||||
'type' => 'page',
|
||||
'title' => 'test page',
|
||||
'body' => array(array('value' => 'pizza')),
|
||||
);
|
||||
'body' => [['value' => 'pizza']],
|
||||
];
|
||||
$this->drupalCreateNode($data);
|
||||
|
||||
$data['type'] = 'article';
|
||||
|
@ -40,7 +40,7 @@ class SearchQueryAlterTest extends SearchTestBase {
|
|||
search_update_totals();
|
||||
|
||||
// Search for the body keyword 'pizza'.
|
||||
$this->drupalPostForm('search/node', array('keys' => 'pizza'), t('Search'));
|
||||
$this->drupalPostForm('search/node', ['keys' => 'pizza'], t('Search'));
|
||||
// The article should be there but not the page.
|
||||
$this->assertText('article', 'Article is in search results');
|
||||
$this->assertNoText('page', 'Page is not in search results');
|
||||
|
|
|
@ -29,7 +29,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('statistics', 'comment');
|
||||
public static $modules = ['statistics', 'comment'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -38,7 +38,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
$this->nodeSearch = SearchPage::load('node_search');
|
||||
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->drupalCreateUser(array('post comments', 'skip comment approval', 'create page content', 'administer search')));
|
||||
$this->drupalLogin($this->drupalCreateUser(['post comments', 'skip comment approval', 'create page content', 'administer search']));
|
||||
}
|
||||
|
||||
public function testRankings() {
|
||||
|
@ -46,24 +46,24 @@ class SearchRankingTest extends SearchTestBase {
|
|||
$this->addDefaultCommentField('node', 'page');
|
||||
|
||||
// Build a list of the rankings to test.
|
||||
$node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views');
|
||||
$node_ranks = ['sticky', 'promote', 'relevance', 'recent', 'comments', 'views'];
|
||||
|
||||
// Create nodes for testing.
|
||||
$nodes = array();
|
||||
$nodes = [];
|
||||
foreach ($node_ranks as $node_rank) {
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => 'page',
|
||||
'comment' => array(array(
|
||||
'comment' => [[
|
||||
'status' => CommentItemInterface::HIDDEN,
|
||||
)),
|
||||
]],
|
||||
'title' => 'Drupal rocks',
|
||||
'body' => array(array('value' => "Drupal's search rocks")),
|
||||
'body' => [['value' => "Drupal's search rocks"]],
|
||||
// Node is one day old.
|
||||
'created' => REQUEST_TIME - 24 * 3600,
|
||||
'sticky' => 0,
|
||||
'promote' => 0,
|
||||
);
|
||||
foreach (array(0, 1) as $num) {
|
||||
];
|
||||
foreach ([0, 1] as $num) {
|
||||
if ($num == 1) {
|
||||
switch ($node_rank) {
|
||||
case 'sticky':
|
||||
|
@ -87,7 +87,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
}
|
||||
|
||||
// Add a comment to one of the nodes.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
$edit['subject[0][value]'] = 'my comment title';
|
||||
$edit['comment_body[0][value]'] = 'some random comment';
|
||||
$this->drupalGet('comment/reply/node/' . $nodes['comments'][1]->id() . '/comment');
|
||||
|
@ -102,7 +102,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
// counter for this node.
|
||||
$nid = $nodes['views'][1]->id();
|
||||
db_insert('node_counter')
|
||||
->fields(array('totalcount' => 5, 'daycount' => 5, 'timestamp' => REQUEST_TIME, 'nid' => $nid))
|
||||
->fields(['totalcount' => 5, 'daycount' => 5, 'timestamp' => REQUEST_TIME, 'nid' => $nid])
|
||||
->execute();
|
||||
|
||||
// Run cron to update the search index and comment/statistics totals.
|
||||
|
@ -118,7 +118,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
}
|
||||
|
||||
// Test each of the possible rankings.
|
||||
$edit = array();
|
||||
$edit = [];
|
||||
foreach ($node_ranks as $node_rank) {
|
||||
// Enable the ranking we are testing.
|
||||
$edit['rankings[' . $node_rank . '][value]'] = 10;
|
||||
|
@ -129,7 +129,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
// Reload the plugin to get the up-to-date values.
|
||||
$this->nodeSearch = SearchPage::load('node_search');
|
||||
// Do the search and assert the results.
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
|
||||
$set = $this->nodeSearch->getPlugin()->execute();
|
||||
$this->assertEqual($set[0]['node']->id(), $nodes[$node_rank][1]->id(), 'Search ranking "' . $node_rank . '" order.');
|
||||
|
||||
|
@ -147,14 +147,14 @@ class SearchRankingTest extends SearchTestBase {
|
|||
|
||||
// Try with sticky, then promoted. This is a test for issue
|
||||
// https://www.drupal.org/node/771596.
|
||||
$node_ranks = array(
|
||||
$node_ranks = [
|
||||
'sticky' => 10,
|
||||
'promote' => 1,
|
||||
'relevance' => 0,
|
||||
'recent' => 0,
|
||||
'comments' => 0,
|
||||
'views' => 0,
|
||||
);
|
||||
];
|
||||
$configuration = $this->nodeSearch->getPlugin()->getConfiguration();
|
||||
foreach ($node_ranks as $var => $value) {
|
||||
$configuration['rankings'][$var] = $value;
|
||||
|
@ -164,7 +164,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
|
||||
// Do the search and assert the results. The sticky node should show up
|
||||
// first, then the promoted node, then all the rest.
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
|
||||
$set = $this->nodeSearch->getPlugin()->execute();
|
||||
$this->assertEqual($set[0]['node']->id(), $nodes['sticky'][1]->id(), 'Search ranking for sticky first worked.');
|
||||
$this->assertEqual($set[1]['node']->id(), $nodes['promote'][1]->id(), 'Search ranking for promoted second worked.');
|
||||
|
@ -172,14 +172,14 @@ class SearchRankingTest extends SearchTestBase {
|
|||
// Try with recent, then comments. This is a test for issues
|
||||
// https://www.drupal.org/node/771596 and
|
||||
// https://www.drupal.org/node/303574.
|
||||
$node_ranks = array(
|
||||
$node_ranks = [
|
||||
'sticky' => 0,
|
||||
'promote' => 0,
|
||||
'relevance' => 0,
|
||||
'recent' => 10,
|
||||
'comments' => 1,
|
||||
'views' => 0,
|
||||
);
|
||||
];
|
||||
$configuration = $this->nodeSearch->getPlugin()->getConfiguration();
|
||||
foreach ($node_ranks as $var => $value) {
|
||||
$configuration['rankings'][$var] = $value;
|
||||
|
@ -189,7 +189,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
|
||||
// Do the search and assert the results. The recent node should show up
|
||||
// first, then the commented node, then all the rest.
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
|
||||
$set = $this->nodeSearch->getPlugin()->execute();
|
||||
$this->assertEqual($set[0]['node']->id(), $nodes['recent'][1]->id(), 'Search ranking for recent first worked.');
|
||||
$this->assertEqual($set[1]['node']->id(), $nodes['comments'][1]->id(), 'Search ranking for comments second worked.');
|
||||
|
@ -200,33 +200,33 @@ class SearchRankingTest extends SearchTestBase {
|
|||
* Test rankings of HTML tags.
|
||||
*/
|
||||
public function testHTMLRankings() {
|
||||
$full_html_format = FilterFormat::create(array(
|
||||
$full_html_format = FilterFormat::create([
|
||||
'format' => 'full_html',
|
||||
'name' => 'Full HTML',
|
||||
));
|
||||
]);
|
||||
$full_html_format->save();
|
||||
|
||||
// Test HTML tags with different weights.
|
||||
$sorted_tags = array('h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'notag');
|
||||
$sorted_tags = ['h1', 'h2', 'h3', 'h4', 'a', 'h5', 'h6', 'notag'];
|
||||
$shuffled_tags = $sorted_tags;
|
||||
|
||||
// Shuffle tags to ensure HTML tags are ranked properly.
|
||||
shuffle($shuffled_tags);
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => 'page',
|
||||
'title' => 'Simple node',
|
||||
);
|
||||
$nodes = array();
|
||||
];
|
||||
$nodes = [];
|
||||
foreach ($shuffled_tags as $tag) {
|
||||
switch ($tag) {
|
||||
case 'a':
|
||||
$settings['body'] = array(array('value' => \Drupal::l('Drupal Rocks', new Url('<front>')), 'format' => 'full_html'));
|
||||
$settings['body'] = [['value' => \Drupal::l('Drupal Rocks', new Url('<front>')), 'format' => 'full_html']];
|
||||
break;
|
||||
case 'notag':
|
||||
$settings['body'] = array(array('value' => 'Drupal Rocks'));
|
||||
$settings['body'] = [['value' => 'Drupal Rocks']];
|
||||
break;
|
||||
default:
|
||||
$settings['body'] = array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html'));
|
||||
$settings['body'] = [['value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html']];
|
||||
break;
|
||||
}
|
||||
$nodes[$tag] = $this->drupalCreateNode($settings);
|
||||
|
@ -236,7 +236,7 @@ class SearchRankingTest extends SearchTestBase {
|
|||
$this->nodeSearch->getPlugin()->updateIndex();
|
||||
search_update_totals();
|
||||
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
|
||||
// Do the search and assert the results.
|
||||
$set = $this->nodeSearch->getPlugin()->execute();
|
||||
|
||||
|
@ -252,16 +252,16 @@ class SearchRankingTest extends SearchTestBase {
|
|||
}
|
||||
|
||||
// Test tags with the same weight against the sorted tags.
|
||||
$unsorted_tags = array('u', 'b', 'i', 'strong', 'em');
|
||||
$unsorted_tags = ['u', 'b', 'i', 'strong', 'em'];
|
||||
foreach ($unsorted_tags as $tag) {
|
||||
$settings['body'] = array(array('value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html'));
|
||||
$settings['body'] = [['value' => "<$tag>Drupal Rocks</$tag>", 'format' => 'full_html']];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Update the search index.
|
||||
$this->nodeSearch->getPlugin()->updateIndex();
|
||||
search_update_totals();
|
||||
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
|
||||
$this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
|
||||
// Do the search and assert the results.
|
||||
$set = $this->nodeSearch->getPlugin()->execute();
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@ use Drupal\Component\Utility\SafeMarkup;
|
|||
|
||||
/**
|
||||
* Defines the common search test code.
|
||||
*
|
||||
* @deprecated Scheduled for removal in Drupal 9.0.0.
|
||||
* Use \Drupal\Tests\search\Functional\SearchTestBase instead.
|
||||
*/
|
||||
abstract class SearchTestBase extends WebTestBase {
|
||||
|
||||
|
@ -15,15 +18,15 @@ abstract class SearchTestBase extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'search', 'dblog');
|
||||
public static $modules = ['node', 'search', 'dblog'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,13 +71,13 @@ abstract class SearchTestBase extends WebTestBase {
|
|||
foreach ($forms as $form) {
|
||||
// Try to set the fields of this form as specified in $edit.
|
||||
$edit = $edit_save;
|
||||
$post = array();
|
||||
$upload = array();
|
||||
$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, array('query' => $post));
|
||||
$this->drupalGet($action, ['query' => $post]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -82,10 +85,10 @@ 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', array('@name' => $name, '@value' => $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', array('@submit' => $submit)));
|
||||
$this->fail(format_string('Found the requested form fields at @path', array('@path' => $path)));
|
||||
$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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class ViewsSearchQuery extends SearchQuery {
|
|||
* item from a \Drupal\Core\Database\Query\Condition::conditions array,
|
||||
* which must have a 'field' element.
|
||||
*/
|
||||
function conditionReplaceString($search, $replace, &$condition) {
|
||||
public function conditionReplaceString($search, $replace, &$condition) {
|
||||
if ($condition['field'] instanceof Condition) {
|
||||
$conditions =& $condition['field']->conditions();
|
||||
foreach ($conditions as $key => &$subcondition) {
|
||||
|
|
|
@ -23,20 +23,20 @@ class SearchEmbeddedForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$count = \Drupal::state()->get('search_embedded_form.submit_count');
|
||||
|
||||
$form['name'] = array(
|
||||
$form['name'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Your name'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => '',
|
||||
'#required' => TRUE,
|
||||
'#description' => $this->t('Times form has been submitted: %count', array('%count' => $count)),
|
||||
);
|
||||
'#description' => $this->t('Times form has been submitted: %count', ['%count' => $count]),
|
||||
];
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions'] = ['#type' => 'actions'];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Send away'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -50,18 +50,18 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
* A structured list of search results
|
||||
*/
|
||||
public function execute() {
|
||||
$results = array();
|
||||
$results = [];
|
||||
if (!$this->isSearchExecutable()) {
|
||||
return $results;
|
||||
}
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'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)]),
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,15 +72,15 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
$output['prefix']['#markup'] = '<h2>Test page text is here</h2> <ol class="search-results">';
|
||||
|
||||
foreach ($results as $entry) {
|
||||
$output[] = array(
|
||||
$output[] = [
|
||||
'#theme' => 'search_result',
|
||||
'#result' => $entry,
|
||||
'#plugin_id' => 'search_extra_type_search',
|
||||
);
|
||||
];
|
||||
}
|
||||
$pager = array(
|
||||
$pager = [
|
||||
'#type' => 'pager',
|
||||
);
|
||||
];
|
||||
$output['suffix']['#markup'] = '</ol>' . drupal_render($pager);
|
||||
|
||||
return $output;
|
||||
|
@ -91,21 +91,21 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
// Output form for defining rank factor weights.
|
||||
$form['extra_type_settings'] = array(
|
||||
$form['extra_type_settings'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Extra type settings'),
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['extra_type_settings']['boost'] = array(
|
||||
$form['extra_type_settings']['boost'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Boost method'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'bi' => t('Bistromathic'),
|
||||
'ii' => t('Infinite Improbability'),
|
||||
),
|
||||
],
|
||||
'#default_value' => $this->configuration['boost'],
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -113,16 +113,16 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->configuration['boost'] = $form_state->getValue(array('extra_type_settings', 'boost'));
|
||||
$this->configuration['boost'] = $form_state->getValue(['extra_type_settings', 'boost']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'boost' => 'bi',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
|
@ -26,7 +26,7 @@ class SearchCommentCountToggleTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'comment');
|
||||
public static $modules = ['node', 'comment'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
|
@ -46,7 +46,7 @@ class SearchCommentCountToggleTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create searching user.
|
||||
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'post comments', 'skip comment approval'));
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'post comments', 'skip comment approval']);
|
||||
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
|
@ -54,13 +54,13 @@ class SearchCommentCountToggleTest extends SearchTestBase {
|
|||
// Add a comment field.
|
||||
$this->addDefaultCommentField('node', 'article');
|
||||
// Create initial nodes.
|
||||
$node_params = array('type' => 'article', 'body' => array(array('value' => 'SearchCommentToggleTestCase')));
|
||||
$node_params = ['type' => 'article', 'body' => [['value' => 'SearchCommentToggleTestCase']]];
|
||||
|
||||
$this->searchableNodes['1 comment'] = $this->drupalCreateNode($node_params);
|
||||
$this->searchableNodes['0 comments'] = $this->drupalCreateNode($node_params);
|
||||
|
||||
// Create a comment array
|
||||
$edit_comment = array();
|
||||
$edit_comment = [];
|
||||
$edit_comment['subject[0][value]'] = $this->randomMachineName();
|
||||
$edit_comment['comment_body[0][value]'] = $this->randomMachineName();
|
||||
|
||||
|
@ -79,11 +79,11 @@ class SearchCommentCountToggleTest extends SearchTestBase {
|
|||
/**
|
||||
* Verify that comment count display toggles properly on comment status of node
|
||||
*/
|
||||
function testSearchCommentCountToggle() {
|
||||
public function testSearchCommentCountToggle() {
|
||||
// Search for the nodes by string in the node body.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'keys' => "'SearchCommentToggleTestCase'",
|
||||
);
|
||||
];
|
||||
$this->drupalGet('search/node');
|
||||
|
||||
// Test comment count display for nodes with comment status set to Open
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
|
@ -43,13 +43,13 @@ class SearchDateIntervalTest extends SearchTestBase {
|
|||
'format' => $default_format,
|
||||
],
|
||||
'langcode' => 'en',
|
||||
'created' => $created_time_en->format('U'),
|
||||
'created' => $created_time_en->getTimestamp(),
|
||||
]);
|
||||
|
||||
// Add Spanish translation to the node.
|
||||
$translation = $node->addTranslation('es', ['title' => 'Node ES']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$translation->created->value = $created_time_es->format('U');
|
||||
$translation->created->value = $created_time_es->getTimestamp();
|
||||
$node->save();
|
||||
|
||||
// Update the index.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests that searching for a phrase gets the correct page count.
|
||||
|
@ -11,27 +11,27 @@ class SearchExactTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that the correct number of pager links are found for both keywords and phrases.
|
||||
*/
|
||||
function testExactQuery() {
|
||||
public function testExactQuery() {
|
||||
// Log in with sufficient privileges.
|
||||
$user = $this->drupalCreateUser(array('create page content', 'search content'));
|
||||
$user = $this->drupalCreateUser(['create page content', 'search content']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => 'page',
|
||||
'title' => 'Simple Node',
|
||||
);
|
||||
];
|
||||
// Create nodes with exact phrase.
|
||||
for ($i = 0; $i <= 17; $i++) {
|
||||
$settings['body'] = array(array('value' => 'love pizza'));
|
||||
$settings['body'] = [['value' => 'love pizza']];
|
||||
$this->drupalCreateNode($settings);
|
||||
}
|
||||
// Create nodes containing keywords.
|
||||
for ($i = 0; $i <= 17; $i++) {
|
||||
$settings['body'] = array(array('value' => 'love cheesy pizza'));
|
||||
$settings['body'] = [['value' => 'love cheesy pizza']];
|
||||
$this->drupalCreateNode($settings);
|
||||
}
|
||||
// Create another node and save it for later.
|
||||
$settings['body'] = array(array('value' => 'Druplicon'));
|
||||
$settings['body'] = [['value' => 'Druplicon']];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Update the search index.
|
||||
|
@ -42,7 +42,7 @@ class SearchExactTest extends SearchTestBase {
|
|||
$this->refreshVariables();
|
||||
|
||||
// Test that the correct number of pager links are found for keyword search.
|
||||
$edit = array('keys' => 'love pizza');
|
||||
$edit = ['keys' => 'love pizza'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertLinkByHref('page=1', 0, '2nd page link is found for keyword search.');
|
||||
$this->assertLinkByHref('page=2', 0, '3rd page link is found for keyword search.');
|
||||
|
@ -50,7 +50,7 @@ class SearchExactTest extends SearchTestBase {
|
|||
$this->assertNoLinkByHref('page=4', '5th page link is not found for keyword search.');
|
||||
|
||||
// Test that the correct number of pager links are found for exact phrase search.
|
||||
$edit = array('keys' => '"love pizza"');
|
||||
$edit = ['keys' => '"love pizza"'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertLinkByHref('page=1', 0, '2nd page link is found for exact phrase search.');
|
||||
$this->assertNoLinkByHref('page=2', '3rd page link is not found for exact phrase search.');
|
||||
|
@ -60,7 +60,7 @@ class SearchExactTest extends SearchTestBase {
|
|||
$node_type_config->set('display_submitted', TRUE);
|
||||
$node_type_config->save();
|
||||
|
||||
$edit = array('keys' => 'Druplicon');
|
||||
$edit = ['keys' => 'Druplicon'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($user->getUsername(), 'Basic page node displays author name when post settings are on.');
|
||||
$this->assertText(format_date($node->getChangedTime(), 'short'), 'Basic page node displays post date when post settings are on.');
|
||||
|
@ -69,7 +69,7 @@ class SearchExactTest extends SearchTestBase {
|
|||
// information is not displayed.
|
||||
$node_type_config->set('display_submitted', FALSE);
|
||||
$node_type_config->save();
|
||||
$edit = array('keys' => 'Druplicon');
|
||||
$edit = ['keys' => 'Druplicon'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoText($user->getUsername(), 'Basic page node does not display author name when post settings are off.');
|
||||
$this->assertNoText(format_date($node->getChangedTime(), 'short'), 'Basic page node does not display post date when post settings are off.');
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
||||
|
@ -20,7 +20,7 @@ class SearchKeywordsConditionsTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment', 'search_extra_type', 'test_page_test');
|
||||
public static $modules = ['comment', 'search_extra_type', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
|
@ -33,7 +33,7 @@ class SearchKeywordsConditionsTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Create searching user.
|
||||
$this->searchingUser = $this->drupalCreateUser(array('search content', 'access content', 'access comments', 'skip comment approval'));
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'skip comment approval']);
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
}
|
||||
|
@ -41,22 +41,22 @@ class SearchKeywordsConditionsTest extends SearchTestBase {
|
|||
/**
|
||||
* Verify the keywords are captured and conditions respected.
|
||||
*/
|
||||
function testSearchKeywordsConditions() {
|
||||
public function testSearchKeywordsConditions() {
|
||||
// No keys, not conditions - no results.
|
||||
$this->drupalGet('search/dummy_path');
|
||||
$this->assertNoText('Dummy search snippet to display');
|
||||
// With keys - get results.
|
||||
$keys = 'bike shed ' . $this->randomMachineName();
|
||||
$this->drupalGet("search/dummy_path", array('query' => array('keys' => $keys)));
|
||||
$this->drupalGet("search/dummy_path", ['query' => ['keys' => $keys]]);
|
||||
$this->assertText("Dummy search snippet to display. Keywords: {$keys}");
|
||||
$keys = 'blue drop ' . $this->randomMachineName();
|
||||
$this->drupalGet("search/dummy_path", array('query' => array('keys' => $keys)));
|
||||
$this->drupalGet("search/dummy_path", ['query' => ['keys' => $keys]]);
|
||||
$this->assertText("Dummy search snippet to display. Keywords: {$keys}");
|
||||
// Add some conditions and keys.
|
||||
$keys = 'moving drop ' . $this->randomMachineName();
|
||||
$this->drupalGet("search/dummy_path", array('query' => array('keys' => 'bike', 'search_conditions' => $keys)));
|
||||
$this->drupalGet("search/dummy_path", ['query' => ['keys' => 'bike', 'search_conditions' => $keys]]);
|
||||
$this->assertText("Dummy search snippet to display.");
|
||||
$this->assertRaw(Html::escape(print_r(array('keys' => 'bike', 'search_conditions' => $keys), TRUE)));
|
||||
$this->assertRaw(Html::escape(print_r(['keys' => 'bike', 'search_conditions' => $keys], TRUE)));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
@ -17,7 +17,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
*
|
||||
* @var \Drupal\node\NodeInterface[]
|
||||
*/
|
||||
protected $searchableNodes = array();
|
||||
protected $searchableNodes = [];
|
||||
|
||||
/**
|
||||
* Node search plugin.
|
||||
|
@ -26,14 +26,14 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
*/
|
||||
protected $plugin;
|
||||
|
||||
public static $modules = array('language', 'locale', 'comment');
|
||||
public static $modules = ['language', 'locale', 'comment'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a user who can administer search, do searches, see the status
|
||||
// report, and administer cron. Log in.
|
||||
$user = $this->drupalCreateUser(array('administer search', 'search content', 'use advanced search', 'access content', 'access site reports', 'administer site configuration'));
|
||||
$user = $this->drupalCreateUser(['administer search', 'search content', 'use advanced search', 'access content', 'access site reports', 'administer site configuration']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Set up the search plugin.
|
||||
|
@ -56,53 +56,53 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
|
||||
// Create a few page nodes with multilingual body values.
|
||||
$default_format = filter_default_format();
|
||||
$nodes = array(
|
||||
array(
|
||||
$nodes = [
|
||||
[
|
||||
'title' => 'First node en',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'title' => 'Second node this is the English title',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'title' => 'Third node en',
|
||||
'type' => 'page',
|
||||
'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)),
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
),
|
||||
],
|
||||
// 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.
|
||||
array(
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
),
|
||||
);
|
||||
$this->searchableNodes = array();
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
];
|
||||
$this->searchableNodes = [];
|
||||
foreach ($nodes as $setting) {
|
||||
$this->searchableNodes[] = $this->drupalCreateNode($setting);
|
||||
}
|
||||
|
||||
// Add a single translation to the second node.
|
||||
$translation = $this->searchableNodes[1]->addTranslation('hu', array('title' => 'Second node hu'));
|
||||
$translation = $this->searchableNodes[1]->addTranslation('hu', ['title' => 'Second node hu']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$this->searchableNodes[1]->save();
|
||||
|
||||
// Add two translations to the third node.
|
||||
$translation = $this->searchableNodes[2]->addTranslation('hu', array('title' => 'Third node this is the Hungarian title'));
|
||||
$translation = $this->searchableNodes[2]->addTranslation('hu', ['title' => 'Third node this is the Hungarian title']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$translation = $this->searchableNodes[2]->addTranslation('sv', array('title' => 'Third node sv'));
|
||||
$translation = $this->searchableNodes[2]->addTranslation('sv', ['title' => 'Third node sv']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$this->searchableNodes[2]->save();
|
||||
|
||||
|
@ -114,7 +114,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests the indexing throttle and search results with multilingual nodes.
|
||||
*/
|
||||
function testMultilingualSearch() {
|
||||
public function testMultilingualSearch() {
|
||||
// Index only 2 nodes per cron run. We cannot do this setting in the UI,
|
||||
// because it doesn't go this low.
|
||||
$this->config('search.settings')->set('index.cron_limit', 2)->save();
|
||||
|
@ -132,7 +132,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
|
||||
// Now index the rest of the nodes.
|
||||
// Make sure index throttle is high enough, via the UI.
|
||||
$this->drupalPostForm('admin/config/search/pages', array('cron_limit' => 20), t('Save configuration'));
|
||||
$this->drupalPostForm('admin/config/search/pages', ['cron_limit' => 20], t('Save configuration'));
|
||||
$this->assertEqual(20, $this->config('search.settings')->get('index.cron_limit', 100), 'Config setting was saved correctly');
|
||||
// Get a new search plugin, to make sure it has this setting.
|
||||
$this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
|
@ -143,8 +143,8 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
$this->assertDatabaseCounts(8, 0, 'after updating fully');
|
||||
|
||||
// Click the reindex button on the admin page, verify counts, and reindex.
|
||||
$this->drupalPostForm('admin/config/search/pages', array(), t('Re-index site'));
|
||||
$this->drupalPostForm(NULL, array(), t('Re-index site'));
|
||||
$this->drupalPostForm('admin/config/search/pages', [], t('Re-index site'));
|
||||
$this->drupalPostForm(NULL, [], t('Re-index site'));
|
||||
$this->assertIndexCounts(8, 8, 'after reindex');
|
||||
$this->assertDatabaseCounts(8, 0, 'after reindex');
|
||||
$this->plugin->updateIndex();
|
||||
|
@ -153,30 +153,30 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
// Test search results.
|
||||
|
||||
// This should find two results for the second and third node.
|
||||
$this->plugin->setSearch('English OR Hungarian', array(), array());
|
||||
$this->plugin->setSearch('English OR Hungarian', [], []);
|
||||
$search_result = $this->plugin->execute();
|
||||
$this->assertEqual(count($search_result), 2, 'Found two results.');
|
||||
// Nodes are saved directly after each other and have the same created time
|
||||
// so testing for the order is not possible.
|
||||
$results = array($search_result[0]['title'], $search_result[1]['title']);
|
||||
$results = [$search_result[0]['title'], $search_result[1]['title']];
|
||||
$this->assertTrue(in_array('Third node this is the Hungarian title', $results), 'The search finds the correct Hungarian title.');
|
||||
$this->assertTrue(in_array('Second node this is the English title', $results), 'The search finds the correct English title.');
|
||||
|
||||
// Now filter for Hungarian results only.
|
||||
$this->plugin->setSearch('English OR Hungarian', array('f' => array('language:hu')), array());
|
||||
$this->plugin->setSearch('English OR Hungarian', ['f' => ['language:hu']], []);
|
||||
$search_result = $this->plugin->execute();
|
||||
|
||||
$this->assertEqual(count($search_result), 1, 'The search found only one result');
|
||||
$this->assertEqual($search_result[0]['title'], 'Third node this is the Hungarian title', 'The search finds the correct Hungarian title.');
|
||||
|
||||
// Test for search with common key word across multiple languages.
|
||||
$this->plugin->setSearch('node', array(), array());
|
||||
$this->plugin->setSearch('node', [], []);
|
||||
$search_result = $this->plugin->execute();
|
||||
|
||||
$this->assertEqual(count($search_result), 6, 'The search found total six results');
|
||||
|
||||
// Test with language filters and common key word.
|
||||
$this->plugin->setSearch('node', array('f' => array('language:hu')), array());
|
||||
$this->plugin->setSearch('node', ['f' => ['language:hu']], []);
|
||||
$search_result = $this->plugin->execute();
|
||||
|
||||
$this->assertEqual(count($search_result), 2, 'The search found 2 results');
|
||||
|
@ -207,14 +207,14 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
$current = REQUEST_TIME;
|
||||
$old = $current - 10;
|
||||
db_update('search_dataset')
|
||||
->fields(array('reindex' => $old))
|
||||
->fields(['reindex' => $old])
|
||||
->condition('reindex', $current, '>=')
|
||||
->execute();
|
||||
|
||||
// Save the node again. Verify that the request time on it is not updated.
|
||||
$this->searchableNodes[1]->save();
|
||||
$result = db_select('search_dataset', 'd')
|
||||
->fields('d', array('reindex'))
|
||||
->fields('d', ['reindex'])
|
||||
->condition('type', 'node_search')
|
||||
->condition('sid', $this->searchableNodes[1]->id())
|
||||
->execute()
|
||||
|
@ -302,7 +302,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
protected function assertDatabaseCounts($count_node, $count_foo, $message) {
|
||||
// Count number of distinct nodes by ID.
|
||||
$results = db_select('search_dataset', 'i')
|
||||
->fields('i', array('sid'))
|
||||
->fields('i', ['sid'])
|
||||
->condition('type', 'node_search')
|
||||
->groupBy('sid')
|
||||
->execute()
|
||||
|
@ -311,7 +311,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
|
|||
|
||||
// Count number of "foo" records.
|
||||
$results = db_select('search_dataset', 'i')
|
||||
->fields('i', array('sid'))
|
||||
->fields('i', ['sid'])
|
||||
->condition('type', 'foo')
|
||||
->execute()
|
||||
->fetchCol();
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests search functionality with diacritics.
|
||||
|
@ -21,17 +21,17 @@ class SearchNodeDiacriticsTest extends SearchTestBase {
|
|||
node_access_rebuild();
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'access user profiles'));
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that search returns results with diacritics in the search phrase.
|
||||
*/
|
||||
function testPhraseSearchPunctuation() {
|
||||
public function testPhraseSearchPunctuation() {
|
||||
$body_text = 'The Enricþment Center is cómmīŦŧęđ to the well BɆĬŇĜ of æll påŔťıçȉpǎǹţș. ';
|
||||
$body_text .= 'Also meklēt (see #731298)';
|
||||
$this->drupalCreateNode(array('body' => array(array('value' => $body_text))));
|
||||
$this->drupalCreateNode(['body' => [['value' => $body_text]]]);
|
||||
|
||||
// Update the search index.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
@ -40,39 +40,39 @@ class SearchNodeDiacriticsTest extends SearchTestBase {
|
|||
// Refresh variables after the treatment.
|
||||
$this->refreshVariables();
|
||||
|
||||
$edit = array('keys' => 'meklet');
|
||||
$edit = ['keys' => 'meklet'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>meklēt</strong>');
|
||||
|
||||
$edit = array('keys' => 'meklēt');
|
||||
$edit = ['keys' => 'meklēt'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>meklēt</strong>');
|
||||
|
||||
$edit = array('keys' => 'cómmīŦŧęđ BɆĬŇĜ påŔťıçȉpǎǹţș');
|
||||
$edit = ['keys' => 'cómmīŦŧęđ BɆĬŇĜ påŔťıçȉpǎǹţș'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>cómmīŦŧęđ</strong>');
|
||||
$this->assertRaw('<strong>BɆĬŇĜ</strong>');
|
||||
$this->assertRaw('<strong>påŔťıçȉpǎǹţș</strong>');
|
||||
|
||||
$edit = array('keys' => 'committed being participants');
|
||||
$edit = ['keys' => 'committed being participants'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>cómmīŦŧęđ</strong>');
|
||||
$this->assertRaw('<strong>BɆĬŇĜ</strong>');
|
||||
$this->assertRaw('<strong>påŔťıçȉpǎǹţș</strong>');
|
||||
|
||||
$edit = array('keys' => 'Enricþment');
|
||||
$edit = ['keys' => 'Enricþment'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>Enricþment</strong>');
|
||||
|
||||
$edit = array('keys' => 'Enritchment');
|
||||
$edit = ['keys' => 'Enritchment'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>Enricþment</strong>');
|
||||
|
||||
$edit = array('keys' => 'æll');
|
||||
$edit = ['keys' => 'æll'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>æll</strong>');
|
||||
|
||||
$edit = array('keys' => 'all');
|
||||
$edit = ['keys' => 'all'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>æll</strong>');
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests search functionality with punctuation and HTML entities.
|
||||
|
@ -21,16 +21,16 @@ class SearchNodePunctuationTest extends SearchTestBase {
|
|||
node_access_rebuild();
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'access user profiles'));
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that search works with punctuation and HTML entities.
|
||||
*/
|
||||
function testPhraseSearchPunctuation() {
|
||||
$node = $this->drupalCreateNode(array('body' => array(array('value' => "The bunny's ears were fluffy."))));
|
||||
$node2 = $this->drupalCreateNode(array('body' => array(array('value' => 'Dignissim Aliquam & Quieligo meus natu quae quia te. Damnum© erat— neo pneum. Facilisi feugiat ibidem ratis.'))));
|
||||
public function testPhraseSearchPunctuation() {
|
||||
$node = $this->drupalCreateNode(['body' => [['value' => "The bunny's ears were fluffy."]]]);
|
||||
$node2 = $this->drupalCreateNode(['body' => [['value' => 'Dignissim Aliquam & Quieligo meus natu quae quia te. Damnum© erat— neo pneum. Facilisi feugiat ibidem ratis.']]]);
|
||||
|
||||
// Update the search index.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
@ -40,7 +40,7 @@ class SearchNodePunctuationTest extends SearchTestBase {
|
|||
$this->refreshVariables();
|
||||
|
||||
// Submit a phrase wrapped in double quotes to include the punctuation.
|
||||
$edit = array('keys' => '"bunny\'s"');
|
||||
$edit = ['keys' => '"bunny\'s"'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($node->label());
|
||||
|
||||
|
@ -49,12 +49,12 @@ class SearchNodePunctuationTest extends SearchTestBase {
|
|||
$this->assertLink($username);
|
||||
|
||||
// Search for "&" and verify entities are not broken up in the output.
|
||||
$edit = array('keys' => '&');
|
||||
$edit = ['keys' => '&'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>&</strong>amp;');
|
||||
$this->assertText('You must include at least one keyword');
|
||||
|
||||
$edit = array('keys' => '&');
|
||||
$edit = ['keys' => '&'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>&</strong>amp;');
|
||||
$this->assertText('You must include at least one keyword');
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests if the result page can be overridden.
|
||||
|
@ -17,7 +17,7 @@ class SearchPageOverrideTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search_extra_type');
|
||||
public static $modules = ['search_extra_type'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer search.
|
||||
|
@ -30,13 +30,13 @@ class SearchPageOverrideTest extends SearchTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Log in as a user that can create and search content.
|
||||
$this->searchUser = $this->drupalCreateUser(array('search content', 'administer search'));
|
||||
$this->searchUser = $this->drupalCreateUser(['search content', 'administer search']);
|
||||
$this->drupalLogin($this->searchUser);
|
||||
}
|
||||
|
||||
function testSearchPageHook() {
|
||||
public function testSearchPageHook() {
|
||||
$keys = 'bike shed ' . $this->randomMachineName();
|
||||
$this->drupalGet("search/dummy_path", array('query' => array('keys' => $keys)));
|
||||
$this->drupalGet("search/dummy_path", ['query' => ['keys' => $keys]]);
|
||||
$this->assertText('Dummy search snippet', 'Dummy search snippet is shown');
|
||||
$this->assertText('Test page text is here', 'Page override is working');
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests that search works with numeric locale settings.
|
||||
|
@ -14,7 +14,7 @@ class SearchSetLocaleTest extends SearchTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('comment');
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* A node search plugin instance.
|
||||
|
@ -29,7 +29,7 @@ class SearchSetLocaleTest extends SearchTestBase {
|
|||
// Create a plugin instance.
|
||||
$this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
// Create a node with a very simple body.
|
||||
$this->drupalCreateNode(array('body' => array(array('value' => 'tapir'))));
|
||||
$this->drupalCreateNode(['body' => [['value' => 'tapir']]]);
|
||||
// Update the search index.
|
||||
$this->nodeSearchPlugin->updateIndex();
|
||||
search_update_totals();
|
||||
|
@ -41,7 +41,7 @@ class SearchSetLocaleTest extends SearchTestBase {
|
|||
public function testSearchWithNumericLocale() {
|
||||
// French decimal point is comma.
|
||||
setlocale(LC_NUMERIC, 'fr_FR');
|
||||
$this->nodeSearchPlugin->setSearch('tapir', array(), array());
|
||||
$this->nodeSearchPlugin->setSearch('tapir', [], []);
|
||||
// The call to execute will throw an exception if a float in the wrong
|
||||
// format is passed in the query to the database, so an assertion is not
|
||||
// necessary here.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,7 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that all Unicode characters simplify correctly.
|
||||
*/
|
||||
function testSearchSimplifyUnicode() {
|
||||
public function testSearchSimplifyUnicode() {
|
||||
// This test uses a file that was constructed so that the even lines are
|
||||
// boundary characters, and the odd lines are valid word characters. (It
|
||||
// was generated as a sequence of all the Unicode characters, and then the
|
||||
|
@ -22,7 +22,7 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
// verify that simplification doesn't lose any characters.
|
||||
$input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt');
|
||||
$basestrings = explode(chr(10), $input);
|
||||
$strings = array();
|
||||
$strings = [];
|
||||
foreach ($basestrings as $key => $string) {
|
||||
if ($key % 2) {
|
||||
// Even line - should simplify down to a space.
|
||||
|
@ -64,13 +64,13 @@ class SearchSimplifyTest extends SearchTestBase {
|
|||
/**
|
||||
* Tests that search_simplify() does the right thing with punctuation.
|
||||
*/
|
||||
function testSearchSimplifyPunctuation() {
|
||||
$cases = array(
|
||||
array('20.03/94-28,876', '20039428876', 'Punctuation removed from numbers'),
|
||||
array('great...drupal--module', 'great drupal module', 'Multiple dot and dashes are word boundaries'),
|
||||
array('very_great-drupal.module', 'verygreatdrupalmodule', 'Single dot, dash, underscore are removed'),
|
||||
array('regular,punctuation;word', 'regular punctuation word', 'Punctuation is a word boundary'),
|
||||
);
|
||||
public function testSearchSimplifyPunctuation() {
|
||||
$cases = [
|
||||
['20.03/94-28,876', '20039428876', 'Punctuation removed from numbers'],
|
||||
['great...drupal--module', 'great drupal module', 'Multiple dot and dashes are word boundaries'],
|
||||
['very_great-drupal.module', 'verygreatdrupalmodule', 'Single dot, dash, underscore are removed'],
|
||||
['regular,punctuation;word', 'regular punctuation word', 'Punctuation is a word boundary'],
|
||||
];
|
||||
|
||||
foreach ($cases as $case) {
|
||||
$out = trim(search_simplify($case[0]));
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Defines the common search test code.
|
||||
*/
|
||||
abstract class SearchTestBase extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'search', 'dblog'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create Basic page and Article node types.
|
||||
if ($this->profile != 'standard') {
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param string $path
|
||||
* Location of the form to be submitted: either a Drupal path, absolute
|
||||
* path, or NULL to use the current page.
|
||||
* @param array $edit
|
||||
* Form field data to submit. Unlike drupalPostForm(), this does not support
|
||||
* file uploads.
|
||||
* @param string $submit
|
||||
* Value of the submit button to submit clicking. Unlike drupalPostForm(),
|
||||
* this does not support AJAX.
|
||||
* @param string $form_html_id
|
||||
* (optional) HTML ID of the form, to disambiguate.
|
||||
*/
|
||||
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]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\search\Tests;
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
* character classes are tokenized properly. See PREG_CLASS_CKJ for more
|
||||
* information.
|
||||
*/
|
||||
function testTokenizer() {
|
||||
public function testTokenizer() {
|
||||
// Set the minimum word size to 1 (to split all CJK characters) and make
|
||||
// sure CJK tokenizing is turned on.
|
||||
$this->config('search.settings')
|
||||
|
@ -31,7 +31,7 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
// the Unicode tables.
|
||||
|
||||
// Beginnings of the character ranges.
|
||||
$starts = array(
|
||||
$starts = [
|
||||
'CJK unified' => 0x4e00,
|
||||
'CJK Ext A' => 0x3400,
|
||||
'CJK Compat' => 0xf900,
|
||||
|
@ -52,10 +52,10 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
'Bomofo Ext' => 0x31a0,
|
||||
'Lisu' => 0xa4d0,
|
||||
'Yi' => 0xa000,
|
||||
);
|
||||
];
|
||||
|
||||
// Ends of the character ranges.
|
||||
$ends = array(
|
||||
$ends = [
|
||||
'CJK unified' => 0x9fcf,
|
||||
'CJK Ext A' => 0x4dbf,
|
||||
'CJK Compat' => 0xfaff,
|
||||
|
@ -76,11 +76,11 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
'Bomofo Ext' => 0x31b7,
|
||||
'Lisu' => 0xa4fd,
|
||||
'Yi' => 0xa48f,
|
||||
);
|
||||
];
|
||||
|
||||
// Generate characters consisting of starts, midpoints, and ends.
|
||||
$chars = array();
|
||||
$charcodes = array();
|
||||
$chars = [];
|
||||
$charcodes = [];
|
||||
foreach ($starts as $key => $value) {
|
||||
$charcodes[] = $starts[$key];
|
||||
$chars[] = $this->code2utf($starts[$key]);
|
||||
|
@ -106,7 +106,7 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
* This is just a sanity check - it verifies that strings of letters are
|
||||
* not tokenized.
|
||||
*/
|
||||
function testNoTokenizer() {
|
||||
public function testNoTokenizer() {
|
||||
// Set the minimum word size to 1 (to split all CJK characters) and make
|
||||
// sure CJK tokenizing is turned on.
|
||||
$this->config('search.settings')
|
||||
|
@ -128,7 +128,7 @@ class SearchTokenizerTest extends SearchTestBase {
|
|||
* converts a number to the corresponding unicode character. Adapted from
|
||||
* functions supplied in comments on several functions on php.net.
|
||||
*/
|
||||
function code2utf($num) {
|
||||
public function code2utf($num) {
|
||||
if ($num < 128) {
|
||||
return chr($num);
|
||||
}
|
|
@ -35,20 +35,20 @@ class MigrateSearchPageTest extends MigrateDrupal6TestBase {
|
|||
$search_page = SearchPage::load($id);
|
||||
$this->assertIdentical($id, $search_page->id());
|
||||
$configuration = $search_page->getPlugin()->getConfiguration();
|
||||
$this->assertIdentical($configuration['rankings'], array(
|
||||
$this->assertIdentical($configuration['rankings'], [
|
||||
'comments' => 5,
|
||||
'promote' => 0,
|
||||
'recent' => 0,
|
||||
'relevance' => 2,
|
||||
'sticky' => 8,
|
||||
'views' => 1,
|
||||
));
|
||||
]);
|
||||
$this->assertIdentical('node', $search_page->getPath());
|
||||
|
||||
// Test that we can re-import using the EntitySearchPage destination.
|
||||
Database::getConnection('default', 'migrate')
|
||||
->update('variable')
|
||||
->fields(array('value' => serialize(4)))
|
||||
->fields(['value' => serialize(4)])
|
||||
->condition('name', 'node_rank_comments')
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\search\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ class MigrateSearchPageTest extends MigrateDrupal7TestBase {
|
|||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('node', 'search');
|
||||
public static $modules = ['node', 'search'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -37,20 +37,20 @@ class MigrateSearchPageTest extends MigrateDrupal7TestBase {
|
|||
$search_page = SearchPage::load($id);
|
||||
$this->assertIdentical($id, $search_page->id());
|
||||
$configuration = $search_page->getPlugin()->getConfiguration();
|
||||
$expected_rankings = array(
|
||||
$expected_rankings = [
|
||||
'comments' => 0,
|
||||
'promote' => 0,
|
||||
'relevance' => 2,
|
||||
'sticky' => 0,
|
||||
'views' => 0,
|
||||
);
|
||||
];
|
||||
$this->assertIdentical($expected_rankings, $configuration['rankings']);
|
||||
$this->assertIdentical('node', $search_page->getPath());
|
||||
|
||||
// Test that we can re-import using the EntitySearchPage destination.
|
||||
Database::getConnection('default', 'migrate')
|
||||
->update('variable')
|
||||
->fields(array('value' => serialize(4)))
|
||||
->fields(['value' => serialize(4)])
|
||||
->condition('name', 'node_rank_comments')
|
||||
->execute();
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class SearchExcerptTest extends KernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('search', 'search_langcode_test');
|
||||
public static $modules = ['search', 'search_langcode_test'];
|
||||
|
||||
/**
|
||||
* Tests search_excerpt() with several simulated search keywords.
|
||||
|
@ -27,7 +27,7 @@ class SearchExcerptTest extends KernelTestBase {
|
|||
* contains either highlighted keywords or the original marked
|
||||
* up string if no keywords matched the string.
|
||||
*/
|
||||
function testSearchExcerpt() {
|
||||
public function testSearchExcerpt() {
|
||||
// Make some text with entities and tags.
|
||||
$text = 'The <strong>quick</strong> <a href="#">brown</a> fox & jumps <h2>over</h2> the lazy dog';
|
||||
$expected = 'The quick brown fox & jumps over the lazy dog';
|
||||
|
@ -74,7 +74,7 @@ class SearchExcerptTest extends KernelTestBase {
|
|||
* search_simplify(). This test passes keywords that match simplified words
|
||||
* and compares them with strings that contain the original unsimplified word.
|
||||
*/
|
||||
function testSearchExcerptSimplified() {
|
||||
public function testSearchExcerptSimplified() {
|
||||
$start_time = microtime(TRUE);
|
||||
|
||||
$lorem1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero.';
|
||||
|
|
|
@ -37,7 +37,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
/**
|
||||
* Test search indexing.
|
||||
*/
|
||||
function testMatching() {
|
||||
public function testMatching() {
|
||||
$this->_setup();
|
||||
$this->_testQueries();
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
/**
|
||||
* Set up a small index of items to test against.
|
||||
*/
|
||||
function _setup() {
|
||||
public function _setup() {
|
||||
$this->config('search.settings')->set('index.minimum_word_size', 3)->save();
|
||||
|
||||
for ($i = 1; $i <= 7; ++$i) {
|
||||
|
@ -55,11 +55,11 @@ class SearchMatchTest extends KernelTestBase {
|
|||
search_index(static::SEARCH_TYPE_2, $i + 7, LanguageInterface::LANGCODE_NOT_SPECIFIED, $this->getText2($i));
|
||||
}
|
||||
// No getText builder function for Japanese text; just a simple array.
|
||||
foreach (array(
|
||||
foreach ([
|
||||
13 => '以呂波耳・ほへとち。リヌルヲ。',
|
||||
14 => 'ドルーパルが大好きよ!',
|
||||
15 => 'コーヒーとケーキ',
|
||||
) as $i => $jpn) {
|
||||
] as $i => $jpn) {
|
||||
search_index(static::SEARCH_TYPE_JPN, $i, LanguageInterface::LANGCODE_NOT_SPECIFIED, $jpn);
|
||||
}
|
||||
search_update_totals();
|
||||
|
@ -77,7 +77,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
* 6 enim am minim veniam es cillum
|
||||
* 7 am minim veniam es cillum dolore eu
|
||||
*/
|
||||
function getText($n) {
|
||||
public function getText($n) {
|
||||
$words = explode(' ', "Ipsum dolore sit am. Ut enim am minim veniam. Es cillum dolore eu.");
|
||||
return implode(' ', array_slice($words, $n - 1, $n));
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
* 11 came over from germany
|
||||
* 12 over from germany swimming
|
||||
*/
|
||||
function getText2($n) {
|
||||
public function getText2($n) {
|
||||
$words = explode(' ', "Dear King Philip came over from Germany swimming.");
|
||||
return implode(' ', array_slice($words, $n - 1, $n));
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class SearchMatchTest extends KernelTestBase {
|
|||
/**
|
||||
* Run predefine queries looking for indexed terms.
|
||||
*/
|
||||
function _testQueries() {
|
||||
public function _testQueries() {
|
||||
// Note: OR queries that include short words in OR groups are only accepted
|
||||
// if the ORed terms are ANDed with at least one long word in the rest of
|
||||
// the query. Examples:
|
||||
|
@ -108,106 +108,106 @@ class SearchMatchTest extends KernelTestBase {
|
|||
// is good, and
|
||||
// dolore OR ut = (dolore) OR (ut)
|
||||
// is bad. This is a design limitation to avoid full table scans.
|
||||
$queries = array(
|
||||
$queries = [
|
||||
// Simple AND queries.
|
||||
'ipsum' => array(1),
|
||||
'enim' => array(4, 5, 6),
|
||||
'xxxxx' => array(),
|
||||
'enim minim' => array(5, 6),
|
||||
'enim xxxxx' => array(),
|
||||
'dolore eu' => array(7),
|
||||
'dolore xx' => array(),
|
||||
'ut minim' => array(5),
|
||||
'xx minim' => array(),
|
||||
'enim veniam am minim ut' => array(5),
|
||||
'ipsum' => [1],
|
||||
'enim' => [4, 5, 6],
|
||||
'xxxxx' => [],
|
||||
'enim minim' => [5, 6],
|
||||
'enim xxxxx' => [],
|
||||
'dolore eu' => [7],
|
||||
'dolore xx' => [],
|
||||
'ut minim' => [5],
|
||||
'xx minim' => [],
|
||||
'enim veniam am minim ut' => [5],
|
||||
// Simple OR and AND/OR queries.
|
||||
'dolore OR ipsum' => array(1, 2, 7),
|
||||
'dolore OR xxxxx' => array(2, 7),
|
||||
'dolore OR ipsum OR enim' => array(1, 2, 4, 5, 6, 7),
|
||||
'ipsum OR dolore sit OR cillum' => array(2, 7),
|
||||
'minim dolore OR ipsum' => array(7),
|
||||
'dolore OR ipsum veniam' => array(7),
|
||||
'minim dolore OR ipsum OR enim' => array(5, 6, 7),
|
||||
'dolore xx OR yy' => array(),
|
||||
'xxxxx dolore OR ipsum' => array(),
|
||||
'dolore OR ipsum' => [1, 2, 7],
|
||||
'dolore OR xxxxx' => [2, 7],
|
||||
'dolore OR ipsum OR enim' => [1, 2, 4, 5, 6, 7],
|
||||
'ipsum OR dolore sit OR cillum' => [2, 7],
|
||||
'minim dolore OR ipsum' => [7],
|
||||
'dolore OR ipsum veniam' => [7],
|
||||
'minim dolore OR ipsum OR enim' => [5, 6, 7],
|
||||
'dolore xx OR yy' => [],
|
||||
'xxxxx dolore OR ipsum' => [],
|
||||
// Sequence of OR queries.
|
||||
'minim' => array(5, 6, 7),
|
||||
'minim OR xxxx' => array(5, 6, 7),
|
||||
'minim OR xxxx OR minim' => array(5, 6, 7),
|
||||
'minim OR xxxx minim' => array(5, 6, 7),
|
||||
'minim OR xxxx minim OR yyyy' => array(5, 6, 7),
|
||||
'minim OR xxxx minim OR cillum' => array(6, 7, 5),
|
||||
'minim OR xxxx minim OR xxxx' => array(5, 6, 7),
|
||||
'minim' => [5, 6, 7],
|
||||
'minim OR xxxx' => [5, 6, 7],
|
||||
'minim OR xxxx OR minim' => [5, 6, 7],
|
||||
'minim OR xxxx minim' => [5, 6, 7],
|
||||
'minim OR xxxx minim OR yyyy' => [5, 6, 7],
|
||||
'minim OR xxxx minim OR cillum' => [6, 7, 5],
|
||||
'minim OR xxxx minim OR xxxx' => [5, 6, 7],
|
||||
// Negative queries.
|
||||
'dolore -sit' => array(7),
|
||||
'dolore -eu' => array(2),
|
||||
'dolore -xxxxx' => array(2, 7),
|
||||
'dolore -xx' => array(2, 7),
|
||||
'dolore -sit' => [7],
|
||||
'dolore -eu' => [2],
|
||||
'dolore -xxxxx' => [2, 7],
|
||||
'dolore -xx' => [2, 7],
|
||||
// Phrase queries.
|
||||
'"dolore sit"' => array(2),
|
||||
'"sit dolore"' => array(),
|
||||
'"am minim veniam es"' => array(6, 7),
|
||||
'"minim am veniam es"' => array(),
|
||||
'"dolore sit"' => [2],
|
||||
'"sit dolore"' => [],
|
||||
'"am minim veniam es"' => [6, 7],
|
||||
'"minim am veniam es"' => [],
|
||||
// Mixed queries.
|
||||
'"am minim veniam es" OR dolore' => array(2, 6, 7),
|
||||
'"minim am veniam es" OR "dolore sit"' => array(2),
|
||||
'"minim am veniam es" OR "sit dolore"' => array(),
|
||||
'"am minim veniam es" -eu' => array(6),
|
||||
'"am minim veniam" -"cillum dolore"' => array(5, 6),
|
||||
'"am minim veniam" -"dolore cillum"' => array(5, 6, 7),
|
||||
'xxxxx "minim am veniam es" OR dolore' => array(),
|
||||
'xx "minim am veniam es" OR dolore' => array()
|
||||
);
|
||||
'"am minim veniam es" OR dolore' => [2, 6, 7],
|
||||
'"minim am veniam es" OR "dolore sit"' => [2],
|
||||
'"minim am veniam es" OR "sit dolore"' => [],
|
||||
'"am minim veniam es" -eu' => [6],
|
||||
'"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' => []
|
||||
];
|
||||
foreach ($queries as $query => $results) {
|
||||
$result = db_select('search_index', 'i')
|
||||
->extend('Drupal\search\SearchQuery')
|
||||
->searchExpression($query, static::SEARCH_TYPE)
|
||||
->execute();
|
||||
|
||||
$set = $result ? $result->fetchAll() : array();
|
||||
$set = $result ? $result->fetchAll() : [];
|
||||
$this->_testQueryMatching($query, $set, $results);
|
||||
$this->_testQueryScores($query, $set, $results);
|
||||
}
|
||||
|
||||
// These queries are run against the second index type, SEARCH_TYPE_2.
|
||||
$queries = array(
|
||||
$queries = [
|
||||
// Simple AND queries.
|
||||
'ipsum' => array(),
|
||||
'enim' => array(),
|
||||
'enim minim' => array(),
|
||||
'dear' => array(8),
|
||||
'germany' => array(11, 12),
|
||||
);
|
||||
'ipsum' => [],
|
||||
'enim' => [],
|
||||
'enim minim' => [],
|
||||
'dear' => [8],
|
||||
'germany' => [11, 12],
|
||||
];
|
||||
foreach ($queries as $query => $results) {
|
||||
$result = db_select('search_index', 'i')
|
||||
->extend('Drupal\search\SearchQuery')
|
||||
->searchExpression($query, static::SEARCH_TYPE_2)
|
||||
->execute();
|
||||
|
||||
$set = $result ? $result->fetchAll() : array();
|
||||
$set = $result ? $result->fetchAll() : [];
|
||||
$this->_testQueryMatching($query, $set, $results);
|
||||
$this->_testQueryScores($query, $set, $results);
|
||||
}
|
||||
|
||||
// These queries are run against the third index type, SEARCH_TYPE_JPN.
|
||||
$queries = array(
|
||||
$queries = [
|
||||
// Simple AND queries.
|
||||
'呂波耳' => array(13),
|
||||
'以呂波耳' => array(13),
|
||||
'ほへと ヌルヲ' => array(13),
|
||||
'とちリ' => array(),
|
||||
'ドルーパル' => array(14),
|
||||
'パルが大' => array(14),
|
||||
'コーヒー' => array(15),
|
||||
'ヒーキ' => array(),
|
||||
);
|
||||
'呂波耳' => [13],
|
||||
'以呂波耳' => [13],
|
||||
'ほへと ヌルヲ' => [13],
|
||||
'とちリ' => [],
|
||||
'ドルーパル' => [14],
|
||||
'パルが大' => [14],
|
||||
'コーヒー' => [15],
|
||||
'ヒーキ' => [],
|
||||
];
|
||||
foreach ($queries as $query => $results) {
|
||||
$result = db_select('search_index', 'i')
|
||||
->extend('Drupal\search\SearchQuery')
|
||||
->searchExpression($query, static::SEARCH_TYPE_JPN)
|
||||
->execute();
|
||||
|
||||
$set = $result ? $result->fetchAll() : array();
|
||||
$set = $result ? $result->fetchAll() : [];
|
||||
$this->_testQueryMatching($query, $set, $results);
|
||||
$this->_testQueryScores($query, $set, $results);
|
||||
}
|
||||
|
@ -218,9 +218,9 @@ class SearchMatchTest extends KernelTestBase {
|
|||
*
|
||||
* Verify if a query produces the correct results.
|
||||
*/
|
||||
function _testQueryMatching($query, $set, $results) {
|
||||
public function _testQueryMatching($query, $set, $results) {
|
||||
// Get result IDs.
|
||||
$found = array();
|
||||
$found = [];
|
||||
foreach ($set as $item) {
|
||||
$found[] = $item->sid;
|
||||
}
|
||||
|
@ -236,9 +236,9 @@ class SearchMatchTest extends KernelTestBase {
|
|||
*
|
||||
* Verify if a query produces normalized, monotonous scores.
|
||||
*/
|
||||
function _testQueryScores($query, $set, $results) {
|
||||
public function _testQueryScores($query, $set, $results) {
|
||||
// Get result scores.
|
||||
$scores = array();
|
||||
$scores = [];
|
||||
foreach ($set as $item) {
|
||||
$scores[] = $item->calculated_score;
|
||||
}
|
||||
|
|
|
@ -75,14 +75,14 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue($this->query));
|
||||
$this->query->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test' => 'test', 'other_test' => 'other_test')));
|
||||
->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test']));
|
||||
|
||||
$entities = array();
|
||||
$entities = [];
|
||||
$entities['test'] = $this->getMock('Drupal\search\SearchPageInterface');
|
||||
$entities['other_test'] = $this->getMock('Drupal\search\SearchPageInterface');
|
||||
$this->storage->expects($this->once())
|
||||
->method('loadMultiple')
|
||||
->with(array('test' => 'test', 'other_test' => 'other_test'))
|
||||
->with(['test' => 'test', 'other_test' => 'other_test'])
|
||||
->will($this->returnValue($entities));
|
||||
|
||||
$result = $this->searchPageRepository->getActiveSearchPages();
|
||||
|
@ -103,7 +103,7 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue($this->query));
|
||||
$this->query->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test' => 'test')));
|
||||
->will($this->returnValue(['test' => 'test']));
|
||||
|
||||
$this->assertSame(TRUE, $this->searchPageRepository->isSearchActive());
|
||||
}
|
||||
|
@ -118,9 +118,9 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue($this->query));
|
||||
$this->query->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test' => 'test', 'other_test' => 'other_test')));
|
||||
->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test']));
|
||||
|
||||
$entities = array();
|
||||
$entities = [];
|
||||
$entities['test'] = $this->getMock('Drupal\search\SearchPageInterface');
|
||||
$entities['test']->expects($this->once())
|
||||
->method('isIndexable')
|
||||
|
@ -131,7 +131,7 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue(FALSE));
|
||||
$this->storage->expects($this->once())
|
||||
->method('loadMultiple')
|
||||
->with(array('test' => 'test', 'other_test' => 'other_test'))
|
||||
->with(['test' => 'test', 'other_test' => 'other_test'])
|
||||
->will($this->returnValue($entities));
|
||||
|
||||
$result = $this->searchPageRepository->getIndexableSearchPages();
|
||||
|
@ -167,7 +167,7 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue($this->query));
|
||||
$this->query->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test' => 'test', 'other_test' => 'other_test')));
|
||||
->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test']));
|
||||
|
||||
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -194,7 +194,7 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
->will($this->returnValue($this->query));
|
||||
$this->query->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('test' => 'test')));
|
||||
->will($this->returnValue(['test' => 'test']));
|
||||
|
||||
$config = $this->getMockBuilder('Drupal\Core\Config\Config')
|
||||
->disableOriginalConstructor()
|
||||
|
@ -259,10 +259,10 @@ class SearchPageRepositoryTest extends UnitTestCase {
|
|||
// Declare entities out of their expected order so we can be sure they were
|
||||
// sorted. We cannot mock these because of uasort(), see
|
||||
// https://bugs.php.net/bug.php?id=50688.
|
||||
$unsorted_entities['test4'] = new TestSearchPage(array('weight' => 0, 'status' => FALSE, 'label' => 'Test4'));
|
||||
$unsorted_entities['test3'] = new TestSearchPage(array('weight' => 10, 'status' => TRUE, 'label' => 'Test3'));
|
||||
$unsorted_entities['test2'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test2'));
|
||||
$unsorted_entities['test1'] = new TestSearchPage(array('weight' => 0, 'status' => TRUE, 'label' => 'Test1'));
|
||||
$unsorted_entities['test4'] = new TestSearchPage(['weight' => 0, 'status' => FALSE, 'label' => 'Test4']);
|
||||
$unsorted_entities['test3'] = new TestSearchPage(['weight' => 10, 'status' => TRUE, 'label' => 'Test3']);
|
||||
$unsorted_entities['test2'] = new TestSearchPage(['weight' => 0, 'status' => TRUE, 'label' => 'Test2']);
|
||||
$unsorted_entities['test1'] = new TestSearchPage(['weight' => 0, 'status' => TRUE, 'label' => 'Test1']);
|
||||
$expected = $unsorted_entities;
|
||||
ksort($expected);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class SearchPluginCollectionTest extends UnitTestCase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
$this->pluginManager = $this->getMock('Drupal\Component\Plugin\PluginManagerInterface');
|
||||
$this->searchPluginCollection = new SearchPluginCollection($this->pluginManager, 'banana', array('id' => 'banana', 'color' => 'yellow'), 'fruit_stand');
|
||||
$this->searchPluginCollection = new SearchPluginCollection($this->pluginManager, 'banana', ['id' => 'banana', 'color' => 'yellow'], 'fruit_stand');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue