Chris@4: '978-0446365383', Chris@4: 'UPC' => '036000 291452', Chris@4: 'EAN bar code' => '5901234123457', Chris@4: 'negative' => '-123456.7890', Chris@4: 'quoted negative' => '"-123456.7890"', Chris@4: 'leading zero' => '0777777777', Chris@4: 'tiny' => '111', Chris@4: 'small' => '22222222222222', Chris@4: 'medium' => '333333333333333333333333333', Chris@4: 'large' => '444444444444444444444444444444444444444', Chris@4: 'gigantic' => '5555555555555555555555555555555555555555555555555', Chris@4: 'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666', Chris@4: 'date' => '01/02/2009', Chris@4: 'commas' => '987,654,321', Chris@4: ]; Chris@4: Chris@4: /** Chris@4: * An array of nodes created for testing purposes. Chris@4: * Chris@4: * @var \Drupal\node\NodeInterface[] Chris@4: */ Chris@4: protected $nodes; Chris@4: Chris@4: protected function setUp() { Chris@4: parent::setUp(); Chris@4: Chris@4: $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); Chris@4: Chris@4: $this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']); Chris@4: $this->drupalLogin($this->testUser); Chris@4: Chris@4: foreach ($this->numbers as $doc => $num) { Chris@4: $info = [ Chris@4: 'body' => [['value' => $num]], Chris@4: 'type' => 'page', Chris@4: 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED, Chris@4: 'title' => $doc . ' number', Chris@4: ]; Chris@4: $this->nodes[$doc] = $this->drupalCreateNode($info); Chris@4: } Chris@4: Chris@4: // Run cron to ensure the content is indexed. Chris@4: $this->cronRun(); Chris@4: $this->drupalGet('admin/reports/dblog'); Chris@4: $this->assertText(t('Cron run completed'), 'Log shows cron run completed'); Chris@4: } Chris@4: Chris@4: /** Chris@4: * Tests that all the numbers can be searched. Chris@4: */ Chris@4: public function testNumberSearching() { Chris@4: $types = array_keys($this->numbers); Chris@4: Chris@4: foreach ($types as $type) { Chris@4: $number = $this->numbers[$type]; Chris@4: // If the number is negative, remove the - sign, because - indicates Chris@4: // "not keyword" when searching. Chris@4: $number = ltrim($number, '-'); Chris@4: $node = $this->nodes[$type]; Chris@4: Chris@4: // Verify that the node title does not appear on the search page Chris@4: // with a dummy search. Chris@4: $this->drupalPostForm('search/node', Chris@4: ['keys' => 'foo'], Chris@4: t('Search')); Chris@4: $this->assertNoText($node->label(), $type . ': node title not shown in dummy search'); Chris@4: Chris@4: // Verify that the node title does appear as a link on the search page Chris@4: // when searching for the number. Chris@4: $this->drupalPostForm('search/node', Chris@4: ['keys' => $number], Chris@4: t('Search')); Chris@4: $this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number])); Chris@4: } Chris@4: } Chris@4: Chris@4: }