function SearchNumberMatchingTest::testNumberSearching

Same name in other branches
  1. 8.9.x core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php \Drupal\Tests\search\Functional\SearchNumberMatchingTest::testNumberSearching()
  2. 10 core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php \Drupal\Tests\search\Functional\SearchNumberMatchingTest::testNumberSearching()
  3. 11.x core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php \Drupal\Tests\search\Functional\SearchNumberMatchingTest::testNumberSearching()

Tests that all the numbers can be searched.

File

core/modules/search/tests/src/Functional/SearchNumberMatchingTest.php, line 96

Class

SearchNumberMatchingTest
Tests that numbers can be searched with more complex matching.

Namespace

Drupal\Tests\search\Functional

Code

public function testNumberSearching() {
    for ($i = 0; $i < count($this->numbers); $i++) {
        $node = $this->nodes[$i];
        // Verify that the node title does not appear on the search page
        // with a dummy search.
        $this->drupalGet('search/node');
        $this->submitForm([
            'keys' => 'foo',
        ], 'Search');
        $this->assertSession()
            ->pageTextNotContains($node->label());
        // Now verify that we can find node i by searching for any of the
        // numbers.
        for ($j = 0; $j < count($this->numbers); $j++) {
            $number = $this->numbers[$j];
            // If the number is negative, remove the - sign, because - indicates
            // "not keyword" when searching.
            $number = ltrim($number, '-');
            $this->drupalGet('search/node');
            $this->submitForm([
                'keys' => $number,
            ], 'Search');
            $this->assertSession()
                ->pageTextContains($node->label());
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.