function SearchEmbedFormTest::testEmbeddedForm

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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 66

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;
}

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