function SearchNodePunctuationTest::testPhraseSearchPunctuation in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/search/src/Tests/SearchNodePunctuationTest.php \Drupal\search\Tests\SearchNodePunctuationTest::testPhraseSearchPunctuation()
Tests that search works with punctuation and HTML entities.
File
- core/
modules/ search/ src/ Tests/ SearchNodePunctuationTest.php, line 36 - Contains \Drupal\search\Tests\SearchNodePunctuationTest.
Class
- SearchNodePunctuationTest
- Tests search functionality with punctuation and HTML entities.
Namespace
Drupal\search\TestsCode
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 & 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 = 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' => '&',
);
$this
->drupalPostForm('search/node', $edit, t('Search'));
$this
->assertNoRaw('<strong>&</strong>amp;');
$this
->assertText('You must include at least one keyword');
}