Chris@17
|
1 <?php
|
Chris@17
|
2
|
Chris@17
|
3 namespace Drupal\Tests\search\Functional;
|
Chris@17
|
4
|
Chris@17
|
5 use Drupal\Core\Language\LanguageInterface;
|
Chris@17
|
6 use Drupal\Tests\BrowserTestBase;
|
Chris@17
|
7 use Drupal\Tests\Traits\Core\CronRunTrait;
|
Chris@17
|
8
|
Chris@17
|
9 /**
|
Chris@17
|
10 * Tests that numbers can be searched.
|
Chris@17
|
11 *
|
Chris@17
|
12 * @group search
|
Chris@17
|
13 */
|
Chris@17
|
14 class SearchNumbersTest extends BrowserTestBase {
|
Chris@17
|
15
|
Chris@17
|
16 use CronRunTrait;
|
Chris@17
|
17
|
Chris@17
|
18 /**
|
Chris@17
|
19 * {@inheritdoc}
|
Chris@17
|
20 */
|
Chris@17
|
21 protected static $modules = ['dblog', 'node', 'search'];
|
Chris@17
|
22
|
Chris@17
|
23 /**
|
Chris@17
|
24 * A user with permission to administer nodes.
|
Chris@17
|
25 *
|
Chris@17
|
26 * @var \Drupal\user\UserInterface
|
Chris@17
|
27 */
|
Chris@17
|
28 protected $testUser;
|
Chris@17
|
29
|
Chris@17
|
30 /**
|
Chris@17
|
31 * An array containing a series of "numbers" for testing purposes.
|
Chris@17
|
32 *
|
Chris@17
|
33 * Create content with various numbers in it.
|
Chris@17
|
34 * Note: 50 characters is the current limit of the search index's word
|
Chris@17
|
35 * field.
|
Chris@17
|
36 *
|
Chris@17
|
37 * @var string[]
|
Chris@17
|
38 */
|
Chris@17
|
39 protected $numbers = [
|
Chris@17
|
40 'ISBN' => '978-0446365383',
|
Chris@17
|
41 'UPC' => '036000 291452',
|
Chris@17
|
42 'EAN bar code' => '5901234123457',
|
Chris@17
|
43 'negative' => '-123456.7890',
|
Chris@17
|
44 'quoted negative' => '"-123456.7890"',
|
Chris@17
|
45 'leading zero' => '0777777777',
|
Chris@17
|
46 'tiny' => '111',
|
Chris@17
|
47 'small' => '22222222222222',
|
Chris@17
|
48 'medium' => '333333333333333333333333333',
|
Chris@17
|
49 'large' => '444444444444444444444444444444444444444',
|
Chris@17
|
50 'gigantic' => '5555555555555555555555555555555555555555555555555',
|
Chris@17
|
51 'over fifty characters' => '666666666666666666666666666666666666666666666666666666666666',
|
Chris@17
|
52 'date' => '01/02/2009',
|
Chris@17
|
53 'commas' => '987,654,321',
|
Chris@17
|
54 ];
|
Chris@17
|
55
|
Chris@17
|
56 /**
|
Chris@17
|
57 * An array of nodes created for testing purposes.
|
Chris@17
|
58 *
|
Chris@17
|
59 * @var \Drupal\node\NodeInterface[]
|
Chris@17
|
60 */
|
Chris@17
|
61 protected $nodes;
|
Chris@17
|
62
|
Chris@17
|
63 protected function setUp() {
|
Chris@17
|
64 parent::setUp();
|
Chris@17
|
65
|
Chris@17
|
66 $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
Chris@17
|
67
|
Chris@17
|
68 $this->testUser = $this->drupalCreateUser(['search content', 'access content', 'administer nodes', 'access site reports']);
|
Chris@17
|
69 $this->drupalLogin($this->testUser);
|
Chris@17
|
70
|
Chris@17
|
71 foreach ($this->numbers as $doc => $num) {
|
Chris@17
|
72 $info = [
|
Chris@17
|
73 'body' => [['value' => $num]],
|
Chris@17
|
74 'type' => 'page',
|
Chris@17
|
75 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
Chris@17
|
76 'title' => $doc . ' number',
|
Chris@17
|
77 ];
|
Chris@17
|
78 $this->nodes[$doc] = $this->drupalCreateNode($info);
|
Chris@17
|
79 }
|
Chris@17
|
80
|
Chris@17
|
81 // Run cron to ensure the content is indexed.
|
Chris@17
|
82 $this->cronRun();
|
Chris@17
|
83 $this->drupalGet('admin/reports/dblog');
|
Chris@17
|
84 $this->assertText(t('Cron run completed'), 'Log shows cron run completed');
|
Chris@17
|
85 }
|
Chris@17
|
86
|
Chris@17
|
87 /**
|
Chris@17
|
88 * Tests that all the numbers can be searched.
|
Chris@17
|
89 */
|
Chris@17
|
90 public function testNumberSearching() {
|
Chris@17
|
91 $types = array_keys($this->numbers);
|
Chris@17
|
92
|
Chris@17
|
93 foreach ($types as $type) {
|
Chris@17
|
94 $number = $this->numbers[$type];
|
Chris@17
|
95 // If the number is negative, remove the - sign, because - indicates
|
Chris@17
|
96 // "not keyword" when searching.
|
Chris@17
|
97 $number = ltrim($number, '-');
|
Chris@17
|
98 $node = $this->nodes[$type];
|
Chris@17
|
99
|
Chris@17
|
100 // Verify that the node title does not appear on the search page
|
Chris@17
|
101 // with a dummy search.
|
Chris@17
|
102 $this->drupalPostForm('search/node',
|
Chris@17
|
103 ['keys' => 'foo'],
|
Chris@17
|
104 t('Search'));
|
Chris@17
|
105 $this->assertNoText($node->label(), $type . ': node title not shown in dummy search');
|
Chris@17
|
106
|
Chris@17
|
107 // Verify that the node title does appear as a link on the search page
|
Chris@17
|
108 // when searching for the number.
|
Chris@17
|
109 $this->drupalPostForm('search/node',
|
Chris@17
|
110 ['keys' => $number],
|
Chris@17
|
111 t('Search'));
|
Chris@17
|
112 $this->assertText($node->label(), format_string('%type: node title shown (search found the node) in search for number %number.', ['%type' => $type, '%number' => $number]));
|
Chris@17
|
113 }
|
Chris@17
|
114 }
|
Chris@17
|
115
|
Chris@17
|
116 }
|