Chris@0: drupalCreateUser([ Chris@0: 'create page content', Chris@0: 'edit own page content', Chris@0: 'search content', Chris@0: 'use advanced search', Chris@0: ]); Chris@0: $this->drupalLogin($web_user); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests that hook_search_preprocess() returns the correct langcode. Chris@0: */ Chris@0: public function testPreprocessLangcode() { Chris@0: // Create a node. Chris@0: $this->node = $this->drupalCreateNode(['body' => [[]], 'langcode' => 'en']); Chris@0: Chris@0: // First update the index. This does the initial processing. Chris@0: $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); Chris@0: Chris@0: // Then, run the shutdown function. Testing is a unique case where indexing Chris@0: // and searching has to happen in the same request, so running the shutdown Chris@0: // function manually is needed to finish the indexing process. Chris@0: search_update_totals(); Chris@0: Chris@0: // Search for the additional text that is added by the preprocess Chris@0: // function. If you search for text that is in the node, preprocess is Chris@0: // not invoked on the node during the search excerpt generation. Chris@0: $edit = ['or' => 'Additional text']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Advanced search')); Chris@0: Chris@0: // Checks if the langcode message has been set by hook_search_preprocess(). Chris@0: $this->assertText('Langcode Preprocess Test: en'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests stemming for hook_search_preprocess(). Chris@0: */ Chris@0: public function testPreprocessStemming() { Chris@0: // Create a node. Chris@0: $this->node = $this->drupalCreateNode([ Chris@0: 'title' => 'we are testing', Chris@0: 'body' => [[]], Chris@0: 'langcode' => 'en', Chris@0: ]); Chris@0: Chris@0: // First update the index. This does the initial processing. Chris@0: $this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex(); Chris@0: Chris@0: // Then, run the shutdown function. Testing is a unique case where indexing Chris@0: // and searching has to happen in the same request, so running the shutdown Chris@0: // function manually is needed to finish the indexing process. Chris@0: search_update_totals(); Chris@0: Chris@0: // Search for the title of the node with a POST query. Chris@0: $edit = ['or' => 'testing']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Advanced search')); Chris@0: Chris@0: // Check if the node has been found. Chris@0: $this->assertText('Search results'); Chris@0: $this->assertText('we are testing'); Chris@0: Chris@0: // Search for the same node using a different query. Chris@0: $edit = ['or' => 'test']; Chris@0: $this->drupalPostForm('search/node', $edit, t('Advanced search')); Chris@0: Chris@0: // Check if the node has been found. Chris@0: $this->assertText('Search results'); Chris@0: $this->assertText('we are testing'); Chris@0: } Chris@0: Chris@0: }