X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fsearch%2Ftests%2Fsrc%2FFunctional%2FSearchNumbersTest.php;fp=web%2Fcore%2Fmodules%2Fsearch%2Ftests%2Fsrc%2FFunctional%2FSearchNumbersTest.php;h=0901a270e5ffa4f4a9a2db9a6e4fe48ba6586c11;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/search/tests/src/Functional/SearchNumbersTest.php b/web/core/modules/search/tests/src/Functional/SearchNumbersTest.php new file mode 100644 index 000000000..0901a270e --- /dev/null +++ b/web/core/modules/search/tests/src/Functional/SearchNumbersTest.php @@ -0,0 +1,116 @@ + '978-0446365383', + 'UPC' => '036000 291452', + 'EAN bar code' => '5901234123457', + 'negative' => '-123456.7890', + 'quoted negative' => '"-123456.7890"', + 'leading zero' => '0777777777', + 'tiny' => '111', + 'small' => '22222222222222', + 'medium' => '333333333333333333333333333', + 'large' => '444444444444444444444444444444444444444', + 'gigantic' => '5555555555555555555555555555555555555555555555555', + 'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666', + 'date' => '01/02/2009', + 'commas' => '987,654,321', + ]; + + /** + * An array of nodes created for testing purposes. + * + * @var \Drupal\node\NodeInterface[] + */ + protected $nodes; + + protected function setUp() { + parent::setUp(); + + $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']); + + $this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']); + $this->drupalLogin($this->testUser); + + foreach ($this->numbers as $doc => $num) { + $info = [ + 'body' => [['value' => $num]], + 'type' => 'page', + 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED, + 'title' => $doc . ' number', + ]; + $this->nodes[$doc] = $this->drupalCreateNode($info); + } + + // Run cron to ensure the content is indexed. + $this->cronRun(); + $this->drupalGet('admin/reports/dblog'); + $this->assertText(t('Cron run completed'), 'Log shows cron run completed'); + } + + /** + * Tests that all the numbers can be searched. + */ + public function testNumberSearching() { + $types = array_keys($this->numbers); + + foreach ($types as $type) { + $number = $this->numbers[$type]; + // If the number is negative, remove the - sign, because - indicates + // "not keyword" when searching. + $number = ltrim($number, '-'); + $node = $this->nodes[$type]; + + // Verify that the node title does not appear on the search page + // with a dummy search. + $this->drupalPostForm('search/node', + ['keys' => 'foo'], + t('Search')); + $this->assertNoText($node->label(), $type . ': node title not shown in dummy search'); + + // Verify that the node title does appear as a link on the search page + // when searching for the number. + $this->drupalPostForm('search/node', + ['keys' => $number], + t('Search')); + $this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number])); + } + } + +}