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->format('U')]);
     // 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');
     $node->save();
     // Update the index.
     $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $plugin->updateIndex();
     search_update_totals();
 }
 /**
  * Tests that the correct number of pager links are found for both keywords and phrases.
  */
 function testExactQuery()
 {
     // Login with sufficient privileges.
     $this->drupalLogin($this->drupalCreateUser(array('create page content', 'search content')));
     $settings = array('type' => 'page', 'title' => 'Simple Node');
     // Create nodes with exact phrase.
     for ($i = 0; $i <= 17; $i++) {
         $settings['body'] = array(array('value' => 'love pizza'));
         $this->drupalCreateNode($settings);
     }
     // Create nodes containing keywords.
     for ($i = 0; $i <= 17; $i++) {
         $settings['body'] = array(array('value' => 'love cheesy pizza'));
         $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 = array('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 = array('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.');
 }
 protected function setUp()
 {
     parent::setUp();
     // Create searching user.
     $this->searchingUser = $this->drupalCreateUser(array('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 = array('type' => 'article', 'body' => array(array('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['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();
 }
 /**
  * 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 &amp; Quieligo meus natu quae quia te. Damnum&copy; erat&mdash; 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 = array('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 = array('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' => '&amp;');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertNoRaw('<strong>&</strong>amp;');
     $this->assertText('You must include at least one keyword');
 }
 function setUp()
 {
     parent::setUp();
     // Create and login user.
     $test_user = $this->drupalCreateUser(array('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.
     $language = new Language(array('id' => 'es', 'name' => 'Spanish'));
     language_save($language);
     // 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->translatable = TRUE;
     $field_storage->save();
     // Create a few page nodes with multilingual body values.
     $default_format = filter_default_format();
     $nodes = array(array('title' => 'First node en', 'type' => 'page', 'body' => array(array('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)), 'langcode' => 'es'), array('title' => 'Third node en', 'type' => 'page', 'body' => array(array('value' => $this->randomMachineName(32), 'format' => $default_format)), 'langcode' => 'en'));
     $this->searchable_nodes = array();
     foreach ($nodes as $setting) {
         $this->searchable_nodes[] = $this->drupalCreateNode($setting);
     }
     // Add English translation to the second node.
     $translation = $this->searchable_nodes[1]->addTranslation('en', array('title' => 'Second node en'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchable_nodes[1]->save();
     // Add Spanish translation to the third node.
     $translation = $this->searchable_nodes[2]->addTranslation('es', array('title' => 'Third node es'));
     $translation->body->value = $this->randomMachineName(32);
     $this->searchable_nodes[2]->save();
     // Update the index and then run the shutdown method.
     $plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     $plugin->updateIndex();
     search_update_totals();
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create user.
     $this->searchingUser = $this->drupalCreateUser(array('search content', 'access user profiles'));
     // Create a node and update the search index.
     $this->node = $this->drupalCreateNode(['title' => 'bike shed shop']);
     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
 }
Beispiel #7
0
 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(array('body' => array(array('value' => 'tapir'))));
     // Update the search index.
     $this->nodeSearchPlugin->updateIndex();
     search_update_totals();
 }
Beispiel #8
0
 /**
  * Tests that the correct number of pager links are found for both keywords and phrases.
  */
 function testExactQuery()
 {
     // Login with sufficient privileges.
     $user = $this->drupalCreateUser(array('create page content', 'search content'));
     $this->drupalLogin($user);
     $settings = array('type' => 'page', 'title' => 'Simple Node');
     // Create nodes with exact phrase.
     for ($i = 0; $i <= 17; $i++) {
         $settings['body'] = array(array('value' => 'love pizza'));
         $this->drupalCreateNode($settings);
     }
     // Create nodes containing keywords.
     for ($i = 0; $i <= 17; $i++) {
         $settings['body'] = array(array('value' => 'love cheesy pizza'));
         $this->drupalCreateNode($settings);
     }
     // Create another node and save it for later.
     $settings['body'] = array(array('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 = array('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 = array('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 = array('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 = array('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.');
 }
 function setUp()
 {
     parent::setUp();
     // Create a user and a node, and update the search index.
     $test_user = $this->drupalCreateUser(array('access content', 'search content', 'administer nodes'));
     $this->drupalLogin($test_user);
     $this->node = $this->drupalCreateNode();
     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
     // Set up a dummy initial count of times the form has been submitted.
     $this->submit_count = \Drupal::state()->get('search_embedded_form.submit_count');
     $this->refreshVariables();
 }
 /**
  * Tests that search returns results with punctuation in the search phrase.
  */
 function testPhraseSearchPunctuation()
 {
     $node = $this->drupalCreateNode(array('body' => array(array('value' => "The bunny's ears were fluffy."))));
     // 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 = array('keys' => '"bunny\'s"');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertText($node->label());
 }
 protected function setUp()
 {
     parent::setUp();
     // Create and login user.
     $test_user = $this->drupalCreateUser(array('access content', 'search content', 'use advanced search', 'administer nodes'));
     $this->drupalLogin($test_user);
     // Create initial node.
     $this->node = $this->drupalCreateNode();
     // 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();
 }
Beispiel #12
0
 /**
  * Set up a small index of items to test against.
  */
 function _setup()
 {
     $this->config('search.settings')->set('index.minimum_word_size', 3)->save();
     for ($i = 1; $i <= 7; ++$i) {
         search_index(SEARCH_TYPE, $i, LanguageInterface::LANGCODE_NOT_SPECIFIED, $this->getText($i));
     }
     for ($i = 1; $i <= 5; ++$i) {
         search_index(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(13 => '以呂波耳・ほへとち。リヌルヲ。', 14 => 'ドルーパルが大好きよ!', 15 => 'コーヒーとケーキ') as $i => $jpn) {
         search_index(SEARCH_TYPE_JPN, $i, LanguageInterface::LANGCODE_NOT_SPECIFIED, $jpn);
     }
     search_update_totals();
 }
 protected function setUp()
 {
     parent::setUp();
     // Login 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->drupalLogin($this->searchUser);
     // Add a single piece of content and index it.
     $node = $this->drupalCreateNode();
     $this->searchNode = $node;
     // Link the node to itself to test that it's only indexed once. The content
     // also needs the word "pizza" so we can use it as the search keyword.
     $body_key = 'body[0][value]';
     $edit[$body_key] = \Drupal::l($node->label(), $node->urlInfo()) . ' pizza sandwich';
     $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
     // Enable the search block.
     $this->drupalPlaceBlock('search_form_block');
 }
 /**
  * Tests that the query alter works.
  */
 function testQueryAlter()
 {
     // Login with sufficient privileges.
     $this->drupalLogin($this->drupalCreateUser(array('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('type' => 'page', 'title' => 'test page', 'body' => array(array('value' => 'pizza')));
     $this->drupalCreateNode($data);
     $data['type'] = 'article';
     $data['title'] = 'test article';
     $this->drupalCreateNode($data);
     // Update the search index.
     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
     // Search for the body keyword 'pizza'.
     $this->drupalPostForm('search/node', array('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');
 }
 /**
  * Tests that search returns results with diacritics in the search phrase.
  */
 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))));
     // 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 = array('keys' => 'meklet');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertRaw('<strong>meklēt</strong>');
     $edit = array('keys' => 'meklēt');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertRaw('<strong>meklēt</strong>');
     $edit = array('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');
     $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');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertRaw('<strong>Enricþment</strong>');
     $edit = array('keys' => 'Enritchment');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertNoRaw('<strong>Enricþment</strong>');
     $edit = array('keys' => 'æll');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertRaw('<strong>æll</strong>');
     $edit = array('keys' => 'all');
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertNoRaw('<strong>æll</strong>');
 }
 /**
  * Tests stemming for hook_search_preprocess().
  */
 function testPreprocessStemming()
 {
     // Create a node.
     $this->node = $this->drupalCreateNode(array('title' => 'we are testing', 'body' => array(array()), 'langcode' => 'en'));
     // 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();
     // Search for the title of the node with a POST query.
     $edit = array('or' => 'testing');
     $this->drupalPostForm('search/node', $edit, t('Advanced search'));
     // Check if the node has been found.
     $this->assertText('Search results');
     $this->assertText('we are testing');
     // Search for the same node using a different query.
     $edit = array('or' => 'test');
     $this->drupalPostForm('search/node', $edit, t('Advanced search'));
     // Check if the node has been found.
     $this->assertText('Search results');
     $this->assertText('we are testing');
 }
 /**
  * Tests that the search index info is updated when a node is deleted.
  */
 function testSearchIndexUpdateOnNodeDeletion()
 {
     // Create a node.
     $node = $this->drupalCreateNode(array('title' => 'No dragons here', 'body' => array(array('value' => 'Again: No dragons here')), 'type' => 'page'));
     $node_search_plugin = $this->container->get('plugin.manager.search')->createInstance('node_search');
     // Update the search index.
     $node_search_plugin->updateIndex();
     search_update_totals();
     // Search the node to verify it appears in search results
     $edit = array('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'))->fetchField();
     $this->assertNotEqual($search_index_dataset, FALSE, t('Node info found on the search_index'));
     // Delete the node.
     $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'))->fetchField();
     $this->assertFalse($search_index_dataset, t('Node info successfully removed from search_index'));
     // Search again to verify the node doesn't appear anymore.
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertNoText($node->label());
 }
Beispiel #18
0
 /**
  * @Given /^I update search index for "([^"]*)"$/
  */
 public function iUpdateSearchIndexFor($node_title)
 {
     // We want to find both campaigns and card art.
     $nodes = db_select('node')->fields('node', ['nid'])->condition('title', $node_title)->condition('type', ['card_art', 'campaign'])->execute();
     foreach ($nodes as $node) {
         search_touch_node($node->nid);
         _node_index_node($node);
         search_update_totals();
     }
 }
 /**
  * Tests the presence of expected cache tags with referenced entities.
  */
 public function testSearchTagsBubbling()
 {
     // Install field UI and entity reference modules.
     $this->container->get('module_installer')->install(['field_ui', 'entity_reference']);
     $this->resetAll();
     // Creates a new content type that will have an entity reference.
     $type_name = 'entity_reference_test';
     $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
     $bundle_path = 'admin/structure/types/manage/' . $type->id();
     // Create test user.
     $admin_user = $this->drupalCreateUser(['access content', 'create ' . $type_name . ' content', 'administer node fields', 'administer node display']);
     $this->drupalLogin($admin_user);
     // First step: 'Add new field' on the 'Manage fields' page.
     $this->drupalGet($bundle_path . '/fields/add-field');
     $this->drupalPostForm(NULL, ['label' => 'Test label', 'field_name' => 'test__ref', 'new_storage_type' => 'entity_reference'], t('Save and continue'));
     // Second step: 'Field settings' form.
     $this->drupalPostForm(NULL, [], t('Save field settings'));
     // Create a new node of our newly created node type and fill in the entity
     // reference field.
     $edit = ['title[0][value]' => 'Llama shop', 'field_test__ref[0][target_id]' => $this->node->getTitle()];
     $this->drupalPostForm('node/add/' . $type->id(), $edit, t('Save'));
     // Test that the value of the entity reference field is shown.
     $this->drupalGet('node/2');
     $this->assertText('bike shed shop');
     // Refresh the search index.
     $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
     // Log in with searching user again.
     $this->drupalLogin($this->searchingUser);
     // Default search cache tags.
     $default_search_tags = ['config:search.page.node_search', 'search_index', 'search_index:node_search', 'rendered', 'node_list'];
     // 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['keys'] = 'shop';
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertText('bike shed shop');
     $this->assertText('Llama shop');
     $expected_cache_tags = Cache::mergeTags($default_search_tags, ['node:1', 'user:2', 'node:2', 'user:3', 'node_view', 'config:filter.format.plain_text']);
     $cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertEqual(explode(' ', $cache_tags), $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['keys'] = 'Llama';
     $this->drupalPostForm('search/node', $edit, t('Search'));
     $this->assertText('Llama shop');
     $expected_cache_tags = Cache::mergeTags($default_search_tags, ['node:1', 'node:2', 'user:3', 'node_view']);
     $cache_tags = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertEqual(explode(' ', $cache_tags), $expected_cache_tags);
 }
Beispiel #20
0
 /**
  * Tests the "Updated date" facets.
  */
 public function testUpdatedDate()
 {
     $facet_name = 'Tardigrade';
     $facet_id = 'tardigrade';
     $this->addFacet($facet_id, $facet_name, 'changed');
     $this->blocks[$facet_id] = $this->createBlock($facet_id);
     $this->setShowAmountOfResults($facet_id, TRUE);
     // Update the changed date. The nodes were created on February/March 2016
     // and the changed date is December 2016.
     $node = Node::load(1);
     $changed_date = new \DateTime('December 3 2016 1PM');
     $node->changed = $changed_date->format('U');
     $node->save();
     // Index the content.
     \Drupal::service('plugin.manager.search')->createInstance('node_search')->updateIndex();
     search_update_totals();
     $this->drupalGet('search/node', ['query' => ['keys' => 'test']]);
     $this->assertRaw('December 2016 <span class="facet-count">(1)</span>');
     $this->clickLinkPartialName('December 2016');
     $this->assertResponse(200);
     $this->assertRaw('December 3, 2016 <span class="facet-count">(1)</span>');
     $this->clickLinkPartialName('December 3, 2016');
     $this->assertResponse(200);
 }
Beispiel #21
0
 /**
  * Test rankings of HTML tags.
  */
 public function testHTMLRankings()
 {
     $full_html_format = entity_create('filter_format', array('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');
     $shuffled_tags = $sorted_tags;
     // Shuffle tags to ensure HTML tags are ranked properly.
     shuffle($shuffled_tags);
     $settings = array('type' => 'page', 'title' => 'Simple node');
     $nodes = array();
     foreach ($shuffled_tags as $tag) {
         switch ($tag) {
             case 'a':
                 $settings['body'] = array(array('value' => \Drupal::l('Drupal Rocks', new Url('<front>')), 'format' => 'full_html'));
                 break;
             case 'notag':
                 $settings['body'] = array(array('value' => 'Drupal Rocks'));
                 break;
             default:
                 $settings['body'] = array(array('value' => "<{$tag}>Drupal Rocks</{$tag}>", 'format' => 'full_html'));
                 break;
         }
         $nodes[$tag] = $this->drupalCreateNode($settings);
     }
     // Update the search index.
     $this->nodeSearch->getPlugin()->updateIndex();
     search_update_totals();
     $this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
     // Do the search and assert the results.
     $set = $this->nodeSearch->getPlugin()->execute();
     // Test the ranking of each tag.
     foreach ($sorted_tags as $tag_rank => $tag) {
         // Assert the results.
         if ($tag == 'notag') {
             $this->assertEqual($set[$tag_rank]['node']->id(), $nodes[$tag]->id(), 'Search tag ranking for plain text order.');
         } else {
             $this->assertEqual($set[$tag_rank]['node']->id(), $nodes[$tag]->id(), 'Search tag ranking for "&lt;' . $sorted_tags[$tag_rank] . '&gt;" order.');
         }
     }
     // Test tags with the same weight against the sorted tags.
     $unsorted_tags = array('u', 'b', 'i', 'strong', 'em');
     foreach ($unsorted_tags as $tag) {
         $settings['body'] = array(array('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());
         // Do the search and assert the results.
         $set = $this->nodeSearch->getPlugin()->execute();
         // Ranking should always be second to last.
         $set = array_slice($set, -2, 1);
         // Assert the results.
         $this->assertEqual($set[0]['node']->id(), $node->id(), 'Search tag ranking for "&lt;' . $tag . '&gt;" order.');
         // Delete node so it doesn't show up in subsequent search results.
         $node->delete();
     }
 }
 /**
  * Verifies that if we combine two rankings, search still works.
  *
  * See issue http://drupal.org/node/771596
  */
 function testDoubleRankings()
 {
     // Login with sufficient privileges.
     $this->drupalLogin($this->drupalCreateUser(array('skip comment approval', 'create page content')));
     // Create two nodes that will match the search, one that is sticky.
     $settings = array('type' => 'page', 'title' => 'Drupal rocks', 'body' => array(array('value' => "Drupal's search rocks")));
     $this->drupalCreateNode($settings);
     $settings['sticky'] = 1;
     $node = $this->drupalCreateNode($settings);
     // Update the search index.
     $this->nodeSearch->getPlugin()->updateIndex();
     search_update_totals();
     // Set up for ranking sticky and lots of comments; make sure others are
     // disabled.
     $node_ranks = array('sticky', 'promote', 'relevance', 'recent', 'comments', 'views');
     $configuration = $this->nodeSearch->getPlugin()->getConfiguration();
     foreach ($node_ranks as $var) {
         $value = $var == 'sticky' || $var == 'comments' ? 10 : 0;
         $configuration['rankings'][$var] = $value;
     }
     $this->nodeSearch->getPlugin()->setConfiguration($configuration);
     $this->nodeSearch->save();
     // Do the search and assert the results.
     $this->nodeSearch->getPlugin()->setSearch('rocks', array(), array());
     // Do the search and assert the results.
     $set = $this->nodeSearch->getPlugin()->execute();
     $this->assertEqual($set[0]['node']->id(), $node->id(), 'Search double ranking order.');
 }
 /**
  * Tests the indexing throttle and search results with multilingual nodes.
  */
 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', array('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', array(), t('Re-index site'));
     $this->drupalPostForm(NULL, array(), 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', array(), array());
     $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']);
     $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());
     $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());
     $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());
     $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(array('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'))->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');
 }