function SimpleFormBlockTest::testSimpleFormBlock

Same name and namespace in other branches
  1. 4.0.x modules/form_api_example/tests/src/Functional/SimpleFormBlockTest.php \Drupal\Tests\form_api_example\Functional\SimpleFormBlockTest::testSimpleFormBlock()

Test of paths through the example wizard form.

File

modules/form_api_example/tests/src/Functional/SimpleFormBlockTest.php, line 28

Class

SimpleFormBlockTest
Tests <a href="/api/examples/modules%21form_api_example%21src%21Plugin%21Block%21SimpleFormBlock.php/class/SimpleFormBlock/3.x" title="Provides a &#039;Example: Display a form&#039; block." class="local">\Drupal\form_api_example\Plugin\Block\SimpleFormBlock</a>.

Namespace

Drupal\Tests\form_api_example\Functional

Code

public function testSimpleFormBlock() {
    $assert = $this->assertSession();
    // Create user.
    $web_user = $this->drupalCreateUser([
        'administer blocks',
    ]);
    // Login the admin user.
    $this->drupalLogin($web_user);
    $theme_name = $this->config('system.theme')
        ->get('default');
    // Place the block.
    $label = 'SimpleFormBlock-' . $this->randomString();
    $settings = [
        'label' => $label,
        'id' => 'form_api_example_simple_form_block',
        'theme' => $theme_name,
    ];
    $this->drupalPlaceBlock('form_api_example_simple_form_block', $settings);
    // Verify the block is present.
    $this->drupalGet('');
    $assert->pageTextContains($label);
    $assert->fieldExists('title');
    // And that the form works.
    $edit = [];
    $edit['title'] = 'SimpleFormBlock title example';
    $this->submitForm($edit, t('Submit'));
    $assert->pageTextContains('You specified a title of SimpleFormBlock title example');
}