3 namespace Drupal\Tests\search\Functional;
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\Tests\BrowserTestBase;
7 use Drupal\Tests\Traits\Core\CronRunTrait;
10 * Tests that numbers can be searched.
14 class SearchNumbersTest extends BrowserTestBase {
21 protected static $modules = ['dblog', 'node', 'search'];
24 * A user with permission to administer nodes.
26 * @var \Drupal\user\UserInterface
31 * An array containing a series of "numbers" for testing purposes.
33 * Create content with various numbers in it.
34 * Note: 50 characters is the current limit of the search index's word
39 protected $numbers = [
40 'ISBN' => '978-0446365383',
41 'UPC' => '036000 291452',
42 'EAN bar code' => '5901234123457',
43 'negative' => '-123456.7890',
44 'quoted negative' => '"-123456.7890"',
45 'leading zero' => '0777777777',
47 'small' => '22222222222222',
48 'medium' => '333333333333333333333333333',
49 'large' => '444444444444444444444444444444444444444',
50 'gigantic' => '5555555555555555555555555555555555555555555555555',
51 'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666',
52 'date' => '01/02/2009',
53 'commas' => '987,654,321',
57 * An array of nodes created for testing purposes.
59 * @var \Drupal\node\NodeInterface[]
63 protected function setUp() {
66 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
68 $this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
69 $this->drupalLogin($this->testUser);
71 foreach ($this->numbers as $doc => $num) {
73 'body' => [['value' => $num]],
75 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
76 'title' => $doc . ' number',
78 $this->nodes[$doc] = $this->drupalCreateNode($info);
81 // Run cron to ensure the content is indexed.
83 $this->drupalGet('admin/reports/dblog');
84 $this->assertText(t('Cron run completed'), 'Log shows cron run completed');
88 * Tests that all the numbers can be searched.
90 public function testNumberSearching() {
91 $types = array_keys($this->numbers);
93 foreach ($types as $type) {
94 $number = $this->numbers[$type];
95 // If the number is negative, remove the - sign, because - indicates
96 // "not keyword" when searching.
97 $number = ltrim($number, '-');
98 $node = $this->nodes[$type];
100 // Verify that the node title does not appear on the search page
101 // with a dummy search.
102 $this->drupalPostForm('search/node',
105 $this->assertNoText($node->label(), $type . ': node title not shown in dummy search');
107 // Verify that the node title does appear as a link on the search page
108 // when searching for the number.
109 $this->drupalPostForm('search/node',
112 $this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number]));