You are here

public function SearchEmbedFormTest::testEmbeddedForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/search/tests/src/Functional/SearchEmbedFormTest.php \Drupal\Tests\search\Functional\SearchEmbedFormTest::testEmbeddedForm()
  2. 10 core/modules/search/tests/src/Functional/SearchEmbedFormTest.php \Drupal\Tests\search\Functional\SearchEmbedFormTest::testEmbeddedForm()

Tests that the embedded form appears and can be submitted.

File

core/modules/search/tests/src/Functional/SearchEmbedFormTest.php, line 63

Class

SearchEmbedFormTest
Verifies that a form embedded in search results works.

Namespace

Drupal\Tests\search\Functional

Code

public function testEmbeddedForm() {

  // First verify we can submit the form from the module's page.
  $this
    ->drupalGet('search_embedded_form');
  $this
    ->submitForm([
    'name' => 'John',
  ], 'Send away');
  $this
    ->assertSession()
    ->pageTextContains('Test form was submitted');
  $count = \Drupal::state()
    ->get('search_embedded_form.submit_count');
  $this
    ->assertEquals($this->submitCount + 1, $count, 'Form submission count is correct');
  $this->submitCount = $count;

  // Now verify that we can see and submit the form from the search results.
  $this
    ->drupalGet('search/node', [
    'query' => [
      'keys' => $this->node
        ->label(),
    ],
  ]);
  $this
    ->assertSession()
    ->pageTextContains('Your name');
  $this
    ->submitForm([
    'name' => 'John',
  ], 'Send away');
  $this
    ->assertSession()
    ->pageTextContains('Test form was submitted');
  $count = \Drupal::state()
    ->get('search_embedded_form.submit_count');
  $this
    ->assertEquals($this->submitCount + 1, $count, 'Form submission count is correct');
  $this->submitCount = $count;

  // Now verify that if we submit the search form, it doesn't count as
  // our form being submitted.
  $this
    ->drupalGet('search');
  $this
    ->submitForm([
    'keys' => 'foo',
  ], 'Search');
  $this
    ->assertSession()
    ->pageTextNotContains('Test form was submitted');
  $count = \Drupal::state()
    ->get('search_embedded_form.submit_count');
  $this
    ->assertEquals($this->submitCount, $count, 'Form submission count is correct');
  $this->submitCount = $count;
}