function SearchBlockTestCase::testBlock

7.x search.test SearchBlockTestCase::testBlock()

Test that the search block form works correctly.

File

drupal-7.x/modules/search/search.test, line 615
Tests for search.module.

Class

SearchBlockTestCase

Code

function testBlock() {
  // Enable the block, and place it in the 'content' region so that it isn't
  // hidden on 404 pages.
  $edit = array('blocks[search_form][region]' => 'content');
  $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));

  // Test a normal search via the block form, from the front page.
  $terms = array('search_block_form' => 'test');
  $this->drupalPost('node', $terms, t('Search'));
  $this->assertText('Your search yielded no results');

  // Test a search from the block on a 404 page.
  $this->drupalGet('foo');
  $this->assertResponse(404);
  $this->drupalPost(NULL, $terms, t('Search'));
  $this->assertResponse(200);
  $this->assertText('Your search yielded no results');

  // Test a search from the block when it doesn't appear on the search page.
  $edit = array('pages' => 'search');
  $this->drupalPost('admin/structure/block/manage/search/form/configure', $edit, t('Save block'));
  $this->drupalPost('node', $terms, t('Search'));
  $this->assertText('Your search yielded no results');

  // Confirm that the user is redirected to the search page.
  $this->assertEqual(
  $this->getUrl(), 
  url('search/node/' . $terms['search_block_form'], array('absolute' => TRUE)), 
  'Redirected to correct url.'
  );

  // Test an empty search via the block form, from the front page.
  $terms = array('search_block_form' => '');
  $this->drupalPost('node', $terms, t('Search'));
  $this->assertText('Please enter some keywords');

  // Confirm that the user is redirected to the search page, when form is submitted empty.
  $this->assertEqual(
  $this->getUrl(), 
  url('search/node/', array('absolute' => TRUE)), 
  'Redirected to correct url.'
  );
}