Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -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',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
|
||||
use Drupal\comment\Tests\CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Tests that comment count display toggles properly on comment status of node.
|
||||
*
|
||||
* Issue 537278
|
||||
*
|
||||
* - Nodes with comment status set to Open should always how comment counts
|
||||
* - Nodes with comment status set to Closed should show comment counts
|
||||
* only when there are comments
|
||||
* - Nodes with comment status set to Hidden should never show comment counts
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchCommentCountToggleTest extends SearchTestBase {
|
||||
|
||||
use CommentTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['node', 'comment'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $searchingUser;
|
||||
|
||||
/**
|
||||
* Array of nodes available to search.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface[]
|
||||
*/
|
||||
protected $searchableNodes;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create searching user.
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'post comments', 'skip comment approval']);
|
||||
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
|
||||
// Add a comment field.
|
||||
$this->addDefaultCommentField('node', 'article');
|
||||
// Create initial nodes.
|
||||
$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 = [];
|
||||
$edit_comment['subject[0][value]'] = $this->randomMachineName();
|
||||
$edit_comment['comment_body[0][value]'] = $this->randomMachineName();
|
||||
|
||||
// Post comment to the test node with comment
|
||||
$this->drupalPostForm('comment/reply/node/' . $this->searchableNodes['1 comment']->id() . '/comment', $edit_comment, t('Save'));
|
||||
|
||||
// First update the index. This does the initial processing.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
|
||||
// Then, run the shutdown function. Testing is a unique case where indexing
|
||||
// and searching has to happen in the same request, so running the shutdown
|
||||
// function manually is needed to finish the indexing process.
|
||||
search_update_totals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that comment count display toggles properly on comment status of node
|
||||
*/
|
||||
public function testSearchCommentCountToggle() {
|
||||
// Search for the nodes by string in the node body.
|
||||
$edit = [
|
||||
'keys' => "'SearchCommentToggleTestCase'",
|
||||
];
|
||||
$this->drupalGet('search/node');
|
||||
|
||||
// Test comment count display for nodes with comment status set to Open
|
||||
$this->drupalPostForm(NULL, $edit, t('Search'));
|
||||
$this->assertText(t('0 comments'), 'Empty comment count displays for nodes with comment status set to Open');
|
||||
$this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Open');
|
||||
|
||||
// Test comment count display for nodes with comment status set to Closed
|
||||
$this->searchableNodes['0 comments']->set('comment', CommentItemInterface::CLOSED);
|
||||
$this->searchableNodes['0 comments']->save();
|
||||
$this->searchableNodes['1 comment']->set('comment', CommentItemInterface::CLOSED);
|
||||
$this->searchableNodes['1 comment']->save();
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Search'));
|
||||
$this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Closed');
|
||||
$this->assertText(t('1 comment'), 'Non-empty comment count displays for nodes with comment status set to Closed');
|
||||
|
||||
// Test comment count display for nodes with comment status set to Hidden
|
||||
$this->searchableNodes['0 comments']->set('comment', CommentItemInterface::HIDDEN);
|
||||
$this->searchableNodes['0 comments']->save();
|
||||
$this->searchableNodes['1 comment']->set('comment', CommentItemInterface::HIDDEN);
|
||||
$this->searchableNodes['1 comment']->save();
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Search'));
|
||||
$this->assertNoText(t('0 comments'), 'Empty comment count does not display for nodes with comment status set to Hidden');
|
||||
$this->assertNoText(t('1 comment'), 'Non-empty comment count does not display for nodes with comment status set to Hidden');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests searching with date filters that exclude some translations.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchDateIntervalTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $modules = ['language', 'search_date_query_alter'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create and log in user.
|
||||
$test_user = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'administer nodes', 'administer languages', 'access administration pages', 'administer site configuration']);
|
||||
$this->drupalLogin($test_user);
|
||||
|
||||
// Add a new language.
|
||||
ConfigurableLanguage::createFromLangcode('es')->save();
|
||||
|
||||
// Set up times to be applied to the English and Spanish translations of the
|
||||
// node create time, so that they are filtered in/out in the
|
||||
// search_date_query_alter test module.
|
||||
$created_time_en = new \DateTime('February 10 2016 10PM');
|
||||
$created_time_es = new \DateTime('March 19 2016 10PM');
|
||||
$default_format = filter_default_format();
|
||||
|
||||
$node = $this->drupalCreateNode([
|
||||
'title' => 'Node EN',
|
||||
'type' => 'page',
|
||||
'body' => [
|
||||
'value' => $this->randomMachineName(32),
|
||||
'format' => $default_format,
|
||||
],
|
||||
'langcode' => 'en',
|
||||
'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->getTimestamp();
|
||||
$node->save();
|
||||
|
||||
// Update the index.
|
||||
$plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
$plugin->updateIndex();
|
||||
search_update_totals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests searching with date filters that exclude some translations.
|
||||
*/
|
||||
public function testDateIntervalQueryAlter() {
|
||||
// Search for keyword node.
|
||||
$edit = ['keys' => 'node'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
|
||||
// The nodes must have the same node ID but the created date is different.
|
||||
// So only the Spanish translation must appear.
|
||||
$this->assertLink('Node ES', 0, 'Spanish translation found in search results');
|
||||
$this->assertNoLink('Node EN', 'Search results do not contain English node');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests that searching for a phrase gets the correct page count.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchExactTest extends SearchTestBase {
|
||||
/**
|
||||
* Tests that the correct number of pager links are found for both keywords and phrases.
|
||||
*/
|
||||
public function testExactQuery() {
|
||||
// Log in with sufficient privileges.
|
||||
$user = $this->drupalCreateUser(['create page content', 'search content']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$settings = [
|
||||
'type' => 'page',
|
||||
'title' => 'Simple Node',
|
||||
];
|
||||
// Create nodes with exact phrase.
|
||||
for ($i = 0; $i <= 17; $i++) {
|
||||
$settings['body'] = [['value' => 'love pizza']];
|
||||
$this->drupalCreateNode($settings);
|
||||
}
|
||||
// Create nodes containing keywords.
|
||||
for ($i = 0; $i <= 17; $i++) {
|
||||
$settings['body'] = [['value' => 'love cheesy pizza']];
|
||||
$this->drupalCreateNode($settings);
|
||||
}
|
||||
// Create another node and save it for later.
|
||||
$settings['body'] = [['value' => 'Druplicon']];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Update the search index.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
search_update_totals();
|
||||
|
||||
// Refresh variables after the treatment.
|
||||
$this->refreshVariables();
|
||||
|
||||
// Test that the correct number of pager links are found for keyword search.
|
||||
$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.');
|
||||
$this->assertLinkByHref('page=3', 0, '4th page link is found for keyword search.');
|
||||
$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 = ['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.');
|
||||
|
||||
// Check that with post settings turned on the post information is displayed.
|
||||
$node_type_config = \Drupal::configFactory()->getEditable('node.type.page');
|
||||
$node_type_config->set('display_submitted', TRUE);
|
||||
$node_type_config->save();
|
||||
|
||||
$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.');
|
||||
|
||||
// Check that with post settings turned off the user and changed date
|
||||
// information is not displayed.
|
||||
$node_type_config->set('display_submitted', FALSE);
|
||||
$node_type_config->save();
|
||||
$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.');
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
|
||||
/**
|
||||
* Verify the search without keywords set and extra conditions.
|
||||
*
|
||||
* Verifies that a plugin can override the isSearchExecutable() method to allow
|
||||
* searching without keywords set and that GET query parameters are made
|
||||
* available to plugins during search execution.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchKeywordsConditionsTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['comment', 'search_extra_type', 'test_page_test'];
|
||||
|
||||
/**
|
||||
* A user with permission to search and post comments.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $searchingUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create searching user.
|
||||
$this->searchingUser = $this->drupalCreateUser(['search content', 'access content', 'access comments', 'skip comment approval']);
|
||||
// Log in with sufficient privileges.
|
||||
$this->drupalLogin($this->searchingUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the keywords are captured and conditions respected.
|
||||
*/
|
||||
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", ['query' => ['keys' => $keys]]);
|
||||
$this->assertText("Dummy search snippet to display. Keywords: {$keys}");
|
||||
$keys = 'blue drop ' . $this->randomMachineName();
|
||||
$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", ['query' => ['keys' => 'bike', 'search_conditions' => $keys]]);
|
||||
$this->assertText("Dummy search snippet to display.");
|
||||
$this->assertRaw(Html::escape(print_r(['keys' => 'bike', 'search_conditions' => $keys], TRUE)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
/**
|
||||
* Tests entities with multilingual fields.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchMultilingualEntityTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* List of searchable nodes.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface[]
|
||||
*/
|
||||
protected $searchableNodes = [];
|
||||
|
||||
/**
|
||||
* Node search plugin.
|
||||
*
|
||||
* @var \Drupal\node\Plugin\Search\NodeSearch
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
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(['administer search', 'search content', 'use advanced search', 'access content', 'access site reports', 'administer site configuration']);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Set up the search plugin.
|
||||
$this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
|
||||
// Check indexing counts before adding any nodes.
|
||||
$this->assertIndexCounts(0, 0, 'before adding nodes');
|
||||
$this->assertDatabaseCounts(0, 0, 'before adding nodes');
|
||||
|
||||
// Add two new languages.
|
||||
ConfigurableLanguage::createFromLangcode('hu')->save();
|
||||
ConfigurableLanguage::createFromLangcode('sv')->save();
|
||||
|
||||
// Make the body field translatable. The title is already translatable by
|
||||
// definition. The parent class has already created the article and page
|
||||
// content types.
|
||||
$field_storage = FieldStorageConfig::loadByName('node', 'body');
|
||||
$field_storage->setTranslatable(TRUE);
|
||||
$field_storage->save();
|
||||
|
||||
// Create a few page nodes with multilingual body values.
|
||||
$default_format = filter_default_format();
|
||||
$nodes = [
|
||||
[
|
||||
'title' => 'First node en',
|
||||
'type' => 'page',
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
],
|
||||
[
|
||||
'title' => 'Second node this is the English title',
|
||||
'type' => 'page',
|
||||
'body' => [['value' => $this->randomMachineName(32), 'format' => $default_format]],
|
||||
'langcode' => 'en',
|
||||
],
|
||||
[
|
||||
'title' => 'Third node en',
|
||||
'type' => 'page',
|
||||
'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.
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
[
|
||||
],
|
||||
];
|
||||
$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', ['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', ['title' => 'Third node this is the Hungarian title']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$translation = $this->searchableNodes[2]->addTranslation('sv', ['title' => 'Third node sv']);
|
||||
$translation->body->value = $this->randomMachineName(32);
|
||||
$this->searchableNodes[2]->save();
|
||||
|
||||
// Verify that we have 8 nodes left to do.
|
||||
$this->assertIndexCounts(8, 8, 'before updating the search index');
|
||||
$this->assertDatabaseCounts(0, 0, 'before updating the search index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the indexing throttle and search results with multilingual nodes.
|
||||
*/
|
||||
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();
|
||||
// Get a new search plugin, to make sure it has this setting.
|
||||
$this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
|
||||
// Update the index. This does the initial processing.
|
||||
$this->plugin->updateIndex();
|
||||
// Run the shutdown function. Testing is a unique case where indexing
|
||||
// and searching has to happen in the same request, so running the shutdown
|
||||
// function manually is needed to finish the indexing process.
|
||||
search_update_totals();
|
||||
$this->assertIndexCounts(6, 8, 'after updating partially');
|
||||
$this->assertDatabaseCounts(2, 0, 'after updating partially');
|
||||
|
||||
// Now index the rest of the nodes.
|
||||
// Make sure index throttle is high enough, via the UI.
|
||||
$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');
|
||||
|
||||
$this->plugin->updateIndex();
|
||||
search_update_totals();
|
||||
$this->assertIndexCounts(0, 8, 'after updating fully');
|
||||
$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', [], 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();
|
||||
search_update_totals();
|
||||
|
||||
// Test search results.
|
||||
|
||||
// This should find two results for the second and third node.
|
||||
$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 = [$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', ['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', [], []);
|
||||
$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', ['f' => ['language:hu']], []);
|
||||
$search_result = $this->plugin->execute();
|
||||
|
||||
$this->assertEqual(count($search_result), 2, 'The search found 2 results');
|
||||
|
||||
// Test to check for the language of result items.
|
||||
foreach ($search_result as $result) {
|
||||
$this->assertEqual($result['langcode'], 'hu', 'The search found the correct Hungarian result');
|
||||
}
|
||||
|
||||
// Mark one of the nodes for reindexing, using the API function, and
|
||||
// verify indexing status.
|
||||
search_mark_for_reindex('node_search', $this->searchableNodes[0]->id());
|
||||
$this->assertIndexCounts(1, 8, 'after marking one node to reindex via API function');
|
||||
|
||||
// Update the index and verify the totals again.
|
||||
$this->plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
|
||||
$this->plugin->updateIndex();
|
||||
search_update_totals();
|
||||
$this->assertIndexCounts(0, 8, 'after indexing again');
|
||||
|
||||
// Mark one node for reindexing by saving it, and verify indexing status.
|
||||
$this->searchableNodes[1]->save();
|
||||
$this->assertIndexCounts(1, 8, 'after marking one node to reindex via save');
|
||||
|
||||
// The request time is always the same throughout test runs. Update the
|
||||
// request time to a previous time, to simulate it having been marked
|
||||
// previously.
|
||||
$current = REQUEST_TIME;
|
||||
$old = $current - 10;
|
||||
db_update('search_dataset')
|
||||
->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', ['reindex'])
|
||||
->condition('type', 'node_search')
|
||||
->condition('sid', $this->searchableNodes[1]->id())
|
||||
->execute()
|
||||
->fetchField();
|
||||
$this->assertEqual($result, $old, 'Reindex time was not updated if node was already marked');
|
||||
|
||||
// Add a bogus entry to the search index table using a different search
|
||||
// type. This will not appear in the index status, because it is not
|
||||
// managed by a plugin.
|
||||
search_index('foo', $this->searchableNodes[0]->id(), 'en', 'some text');
|
||||
$this->assertIndexCounts(1, 8, 'after adding a different index item');
|
||||
|
||||
// Mark just this "foo" index for reindexing.
|
||||
search_mark_for_reindex('foo');
|
||||
$this->assertIndexCounts(1, 8, 'after reindexing the other search type');
|
||||
|
||||
// Mark everything for reindexing.
|
||||
search_mark_for_reindex();
|
||||
$this->assertIndexCounts(8, 8, 'after reindexing everything');
|
||||
|
||||
// Clear one item from the index, but with wrong language.
|
||||
$this->assertDatabaseCounts(8, 1, 'before clear');
|
||||
search_index_clear('node_search', $this->searchableNodes[0]->id(), 'hu');
|
||||
$this->assertDatabaseCounts(8, 1, 'after clear with wrong language');
|
||||
// Clear using correct language.
|
||||
search_index_clear('node_search', $this->searchableNodes[0]->id(), 'en');
|
||||
$this->assertDatabaseCounts(7, 1, 'after clear with right language');
|
||||
// Don't specify language.
|
||||
search_index_clear('node_search', $this->searchableNodes[1]->id());
|
||||
$this->assertDatabaseCounts(6, 1, 'unspecified language clear');
|
||||
// Clear everything in 'foo'.
|
||||
search_index_clear('foo');
|
||||
$this->assertDatabaseCounts(6, 0, 'other index clear');
|
||||
// Clear everything.
|
||||
search_index_clear();
|
||||
$this->assertDatabaseCounts(0, 0, 'complete clear');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the indexing status counts.
|
||||
*
|
||||
* @param int $remaining
|
||||
* Count of remaining items to verify.
|
||||
* @param int $total
|
||||
* Count of total items to verify.
|
||||
* @param string $message
|
||||
* Message to use, something like "after updating the search index".
|
||||
*/
|
||||
protected function assertIndexCounts($remaining, $total, $message) {
|
||||
// Check status via plugin method call.
|
||||
$status = $this->plugin->indexStatus();
|
||||
$this->assertEqual($status['remaining'], $remaining, 'Remaining items ' . $message . ' is ' . $remaining);
|
||||
$this->assertEqual($status['total'], $total, 'Total items ' . $message . ' is ' . $total);
|
||||
|
||||
// Check text in progress section of Search settings page. Note that this
|
||||
// test avoids using
|
||||
// \Drupal\Core\StringTranslation\TranslationInterface::formatPlural(), so
|
||||
// it tests for fragments of text.
|
||||
$indexed = $total - $remaining;
|
||||
$percent = ($total > 0) ? floor(100 * $indexed / $total) : 100;
|
||||
$this->drupalGet('admin/config/search/pages');
|
||||
$this->assertText($percent . '% of the site has been indexed.', 'Progress percent text at top of Search settings page is correct at: ' . $message);
|
||||
$this->assertText($remaining . ' item', 'Remaining text at top of Search settings page is correct at: ' . $message);
|
||||
|
||||
// Check text in pages section of Search settings page.
|
||||
$this->assertText($indexed . ' of ' . $total . ' indexed', 'Progress text in pages section of Search settings page is correct at: ' . $message);
|
||||
|
||||
// Check text on status report page.
|
||||
$this->drupalGet('admin/reports/status');
|
||||
$this->assertText('Search index progress', 'Search status section header is present on status report page');
|
||||
$this->assertText($percent . '%', 'Correct percentage is shown on status report page at: ' . $message);
|
||||
$this->assertText('(' . $remaining . ' remaining)', 'Correct remaining value is shown on status report page at: ' . $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks actual database counts of items in the search index.
|
||||
*
|
||||
* @param int $count_node
|
||||
* Count of node items to assert.
|
||||
* @param int $count_foo
|
||||
* Count of "foo" items to assert.
|
||||
* @param string $message
|
||||
* Message suffix to use.
|
||||
*/
|
||||
protected function assertDatabaseCounts($count_node, $count_foo, $message) {
|
||||
// Count number of distinct nodes by ID.
|
||||
$results = db_select('search_dataset', 'i')
|
||||
->fields('i', ['sid'])
|
||||
->condition('type', 'node_search')
|
||||
->groupBy('sid')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$this->assertEqual($count_node, count($results), 'Node count was ' . $count_node . ' for ' . $message);
|
||||
|
||||
// Count number of "foo" records.
|
||||
$results = db_select('search_dataset', 'i')
|
||||
->fields('i', ['sid'])
|
||||
->condition('type', 'foo')
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$this->assertEqual($count_foo, count($results), 'Foo count was ' . $count_foo . ' for ' . $message);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests search functionality with diacritics.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNodeDiacriticsTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* A user with permission to use advanced search.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
public $testUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
node_access_rebuild();
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that search returns results with diacritics in the search phrase.
|
||||
*/
|
||||
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(['body' => [['value' => $body_text]]]);
|
||||
|
||||
// Update the search index.
|
||||
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
|
||||
search_update_totals();
|
||||
|
||||
// Refresh variables after the treatment.
|
||||
$this->refreshVariables();
|
||||
|
||||
$edit = ['keys' => 'meklet'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>meklēt</strong>');
|
||||
|
||||
$edit = ['keys' => 'meklēt'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>meklēt</strong>');
|
||||
|
||||
$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 = ['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 = ['keys' => 'Enricþment'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>Enricþment</strong>');
|
||||
|
||||
$edit = ['keys' => 'Enritchment'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>Enricþment</strong>');
|
||||
|
||||
$edit = ['keys' => 'æll'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertRaw('<strong>æll</strong>');
|
||||
|
||||
$edit = ['keys' => 'all'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>æll</strong>');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests search functionality with punctuation and HTML entities.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchNodePunctuationTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* A user with permission to use advanced search.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
public $testUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
node_access_rebuild();
|
||||
|
||||
// Create a test user and log in.
|
||||
$this->testUser = $this->drupalCreateUser(['access content', 'search content', 'use advanced search', 'access user profiles']);
|
||||
$this->drupalLogin($this->testUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that search works with punctuation and HTML entities.
|
||||
*/
|
||||
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();
|
||||
search_update_totals();
|
||||
|
||||
// Refresh variables after the treatment.
|
||||
$this->refreshVariables();
|
||||
|
||||
// Submit a phrase wrapped in double quotes to include the punctuation.
|
||||
$edit = ['keys' => '"bunny\'s"'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertText($node->label());
|
||||
|
||||
// Check if the author is linked correctly to the user profile page.
|
||||
$username = $node->getOwner()->getUsername();
|
||||
$this->assertLink($username);
|
||||
|
||||
// Search for "&" and verify entities are not broken up in the output.
|
||||
$edit = ['keys' => '&'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>&</strong>amp;');
|
||||
$this->assertText('You must include at least one keyword');
|
||||
|
||||
$edit = ['keys' => '&'];
|
||||
$this->drupalPostForm('search/node', $edit, t('Search'));
|
||||
$this->assertNoRaw('<strong>&</strong>amp;');
|
||||
$this->assertText('You must include at least one keyword');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests if the result page can be overridden.
|
||||
*
|
||||
* Verifies that a plugin can override the buildResults() method to
|
||||
* control what the search results page looks like.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchPageOverrideTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['search_extra_type'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer search.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
public $searchUser;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Log in as a user that can create and search content.
|
||||
$this->searchUser = $this->drupalCreateUser(['search content', 'administer search']);
|
||||
$this->drupalLogin($this->searchUser);
|
||||
}
|
||||
|
||||
public function testSearchPageHook() {
|
||||
$keys = 'bike shed ' . $this->randomMachineName();
|
||||
$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');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
|
||||
/**
|
||||
* Tests that search works with numeric locale settings.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchSetLocaleTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['comment'];
|
||||
|
||||
/**
|
||||
* A node search plugin instance.
|
||||
*
|
||||
* @var \Drupal\search\Plugin\SearchInterface
|
||||
*/
|
||||
protected $nodeSearchPlugin;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// 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(['body' => [['value' => 'tapir']]]);
|
||||
// Update the search index.
|
||||
$this->nodeSearchPlugin->updateIndex();
|
||||
search_update_totals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that search works with a numeric locale set.
|
||||
*/
|
||||
public function testSearchWithNumericLocale() {
|
||||
// French decimal point is comma.
|
||||
setlocale(LC_NUMERIC, 'fr_FR');
|
||||
$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.
|
||||
$this->nodeSearchPlugin->execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Tests that the search_simply() function works as intended.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchSimplifyTest extends SearchTestBase {
|
||||
/**
|
||||
* Tests that all Unicode characters simplify correctly.
|
||||
*/
|
||||
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
|
||||
// boundary characters (punctuation, spaces, etc.) were split off into
|
||||
// their own lines). So the even-numbered lines should simplify to nothing,
|
||||
// and the odd-numbered lines we need to split into shorter chunks and
|
||||
// verify that simplification doesn't lose any characters.
|
||||
$input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt');
|
||||
$basestrings = explode(chr(10), $input);
|
||||
$strings = [];
|
||||
foreach ($basestrings as $key => $string) {
|
||||
if ($key % 2) {
|
||||
// Even line - should simplify down to a space.
|
||||
$simplified = search_simplify($string);
|
||||
$this->assertIdentical($simplified, ' ', "Line $key is excluded from the index");
|
||||
}
|
||||
else {
|
||||
// Odd line, should be word characters.
|
||||
// Split this into 30-character chunks, so we don't run into limits
|
||||
// of truncation in search_simplify().
|
||||
$start = 0;
|
||||
while ($start < Unicode::strlen($string)) {
|
||||
$newstr = Unicode::substr($string, $start, 30);
|
||||
// Special case: leading zeros are removed from numeric strings,
|
||||
// and there's one string in this file that is numbers starting with
|
||||
// zero, so prepend a 1 on that string.
|
||||
if (preg_match('/^[0-9]+$/', $newstr)) {
|
||||
$newstr = '1' . $newstr;
|
||||
}
|
||||
$strings[] = $newstr;
|
||||
$start += 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($strings as $key => $string) {
|
||||
$simplified = search_simplify($string);
|
||||
$this->assertTrue(Unicode::strlen($simplified) >= Unicode::strlen($string), "Nothing is removed from string $key.");
|
||||
}
|
||||
|
||||
// Test the low-numbered ASCII control characters separately. They are not
|
||||
// in the text file because they are problematic for diff, especially \0.
|
||||
$string = '';
|
||||
for ($i = 0; $i < 32; $i++) {
|
||||
$string .= chr($i);
|
||||
}
|
||||
$this->assertIdentical(' ', search_simplify($string), 'Search simplify works for ASCII control characters.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that search_simplify() does the right thing with punctuation.
|
||||
*/
|
||||
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]));
|
||||
$this->assertEqual($out, $case[1], $case[2]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\search\Functional;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Tests that CJK tokenizer works as intended.
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
class SearchTokenizerTest extends SearchTestBase {
|
||||
|
||||
/**
|
||||
* Verifies that strings of CJK characters are tokenized.
|
||||
*
|
||||
* The search_simplify() function does special things with numbers, symbols,
|
||||
* and punctuation. So we only test that CJK characters that are not in these
|
||||
* character classes are tokenized properly. See PREG_CLASS_CKJ for more
|
||||
* information.
|
||||
*/
|
||||
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')
|
||||
->set('index.minimum_word_size', 1)
|
||||
->set('index.overlap_cjk', TRUE)
|
||||
->save();
|
||||
$this->refreshVariables();
|
||||
|
||||
// Create a string of CJK characters from various character ranges in
|
||||
// the Unicode tables.
|
||||
|
||||
// Beginnings of the character ranges.
|
||||
$starts = [
|
||||
'CJK unified' => 0x4e00,
|
||||
'CJK Ext A' => 0x3400,
|
||||
'CJK Compat' => 0xf900,
|
||||
'Hangul Jamo' => 0x1100,
|
||||
'Hangul Ext A' => 0xa960,
|
||||
'Hangul Ext B' => 0xd7b0,
|
||||
'Hangul Compat' => 0x3131,
|
||||
'Half non-punct 1' => 0xff21,
|
||||
'Half non-punct 2' => 0xff41,
|
||||
'Half non-punct 3' => 0xff66,
|
||||
'Hangul Syllables' => 0xac00,
|
||||
'Hiragana' => 0x3040,
|
||||
'Katakana' => 0x30a1,
|
||||
'Katakana Ext' => 0x31f0,
|
||||
'CJK Reserve 1' => 0x20000,
|
||||
'CJK Reserve 2' => 0x30000,
|
||||
'Bomofo' => 0x3100,
|
||||
'Bomofo Ext' => 0x31a0,
|
||||
'Lisu' => 0xa4d0,
|
||||
'Yi' => 0xa000,
|
||||
];
|
||||
|
||||
// Ends of the character ranges.
|
||||
$ends = [
|
||||
'CJK unified' => 0x9fcf,
|
||||
'CJK Ext A' => 0x4dbf,
|
||||
'CJK Compat' => 0xfaff,
|
||||
'Hangul Jamo' => 0x11ff,
|
||||
'Hangul Ext A' => 0xa97f,
|
||||
'Hangul Ext B' => 0xd7ff,
|
||||
'Hangul Compat' => 0x318e,
|
||||
'Half non-punct 1' => 0xff3a,
|
||||
'Half non-punct 2' => 0xff5a,
|
||||
'Half non-punct 3' => 0xffdc,
|
||||
'Hangul Syllables' => 0xd7af,
|
||||
'Hiragana' => 0x309f,
|
||||
'Katakana' => 0x30ff,
|
||||
'Katakana Ext' => 0x31ff,
|
||||
'CJK Reserve 1' => 0x2fffd,
|
||||
'CJK Reserve 2' => 0x3fffd,
|
||||
'Bomofo' => 0x312f,
|
||||
'Bomofo Ext' => 0x31b7,
|
||||
'Lisu' => 0xa4fd,
|
||||
'Yi' => 0xa48f,
|
||||
];
|
||||
|
||||
// Generate characters consisting of starts, midpoints, and ends.
|
||||
$chars = [];
|
||||
$charcodes = [];
|
||||
foreach ($starts as $key => $value) {
|
||||
$charcodes[] = $starts[$key];
|
||||
$chars[] = $this->code2utf($starts[$key]);
|
||||
$mid = round(0.5 * ($starts[$key] + $ends[$key]));
|
||||
$charcodes[] = $mid;
|
||||
$chars[] = $this->code2utf($mid);
|
||||
$charcodes[] = $ends[$key];
|
||||
$chars[] = $this->code2utf($ends[$key]);
|
||||
}
|
||||
|
||||
// Merge into a string and tokenize.
|
||||
$string = implode('', $chars);
|
||||
$out = trim(search_simplify($string));
|
||||
$expected = Unicode::strtolower(implode(' ', $chars));
|
||||
|
||||
// Verify that the output matches what we expect.
|
||||
$this->assertEqual($out, $expected, 'CJK tokenizer worked on all supplied CJK characters');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that strings of non-CJK characters are not tokenized.
|
||||
*
|
||||
* This is just a sanity check - it verifies that strings of letters are
|
||||
* not tokenized.
|
||||
*/
|
||||
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')
|
||||
->set('index.minimum_word_size', 1)
|
||||
->set('index.overlap_cjk', TRUE)
|
||||
->save();
|
||||
$this->refreshVariables();
|
||||
|
||||
$letters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
$out = trim(search_simplify($letters));
|
||||
|
||||
$this->assertEqual($letters, $out, 'Letters are not CJK tokenized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Like PHP chr() function, but for unicode characters.
|
||||
*
|
||||
* chr() only works for ASCII characters up to character 255. This function
|
||||
* converts a number to the corresponding unicode character. Adapted from
|
||||
* functions supplied in comments on several functions on php.net.
|
||||
*/
|
||||
public function code2utf($num) {
|
||||
if ($num < 128) {
|
||||
return chr($num);
|
||||
}
|
||||
|
||||
if ($num < 2048) {
|
||||
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
|
||||
}
|
||||
|
||||
if ($num < 65536) {
|
||||
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
||||
}
|
||||
|
||||
if ($num < 2097152) {
|
||||
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
|
@ -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