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