You are here

function SearchNumberMatchingTestCase::testNumberSearching in Drupal 7

Tests that all the numbers can be searched.

File

modules/search/search.test, line 1408
Tests for search.module.

Class

SearchNumberMatchingTestCase
Tests that numbers can be searched, with more complex matching.

Code

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
      ->drupalPost('search/node', array(
      'keys' => 'foo',
    ), t('Search'));
    $this
      ->assertNoText($node->title, format_string('%number: node title not shown in dummy search', array(
      '%number' => $i,
    )));

    // 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
        ->drupalPost('search/node', array(
        'keys' => $number,
      ), t('Search'));
      $this
        ->assertText($node->title, format_string('%i: node title shown (search found the node) in search for number %number', array(
        '%i' => $i,
        '%number' => $number,
      )));
    }
  }
}