protected function SearchBlockTest::testSearchFormBlock

Test that the search form block can be placed and works.

File

drupal/core/modules/search/lib/Drupal/search/Tests/SearchBlockTest.php, line 41
Definition of Drupal\search\Tests\SearchBlockTest.

Class

SearchBlockTest
Tests the rendering of the search block.

Namespace

Drupal\search\Tests

Code

protected function testSearchFormBlock() {
  $block = $this
    ->drupalPlaceBlock('search_form_block');
  $this
    ->drupalGet('');
  $this
    ->assertText($block
    ->label(), 'Block title was found.');

  // 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');
  $visibility = $block
    ->get('visibility');
  $visibility['path']['pages'] = 'search';
  $block
    ->set('visibility', $visibility);
  $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.');
}