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