class ConfirmFormTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest
- 7.x modules/system/system.test \ConfirmFormTest
- 10 core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest
- 8.9.x core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest
Tests confirmation forms.
@group Form
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Form\ConfirmFormTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ConfirmFormTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ ConfirmFormTest.php, line 13
Namespace
Drupal\Tests\system\Functional\FormView source
class ConfirmFormTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'form_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
public function testConfirmForm() {
// Test the building of the form.
$this->drupalGet('form-test/confirm-form');
$site_name = $this->config('system.site')
->get('name');
$this->assertSession()
->titleEquals("ConfirmFormTestForm::getQuestion(). | {$site_name}");
$this->assertSession()
->pageTextContains('ConfirmFormTestForm::getDescription().');
$this->assertSession()
->buttonExists('ConfirmFormTestForm::getConfirmText().');
// Test cancelling the form.
$this->clickLink('ConfirmFormTestForm::getCancelText().');
$this->assertSession()
->addressEquals('form-test/autocomplete');
// Test submitting the form.
$this->drupalGet('form-test/confirm-form');
$this->submitForm([], 'ConfirmFormTestForm::getConfirmText().');
$this->assertSession()
->pageTextContains('The ConfirmFormTestForm::submitForm() method was used for this form.');
$this->assertSession()
->addressEquals('');
// Test submitting the form with a destination.
$this->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => 'admin/config',
],
]);
$this->submitForm([], 'ConfirmFormTestForm::getConfirmText().');
$this->assertSession()
->addressEquals('admin/config');
// Test cancelling the form with a complex destination.
$this->drupalGet('form-test/confirm-form-array-path');
$this->clickLink('ConfirmFormArrayPathTestForm::getCancelText().');
// Verify that the form's complex cancel link was followed.
$this->assertSession()
->addressEquals('form-test/confirm-form?destination=admin/config');
}
/**
* Tests that the confirm form does not use external destinations.
*/
public function testConfirmFormWithExternalDestination() {
$this->drupalGet('form-test/confirm-form');
$this->assertSession()
->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
$this->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => 'node',
],
]);
$this->assertSession()
->linkByHrefExists(Url::fromUri('internal:/node')->toString());
$this->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => 'http://example.com',
],
]);
$this->assertSession()
->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
$this->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => '<front>',
],
]);
$this->assertSession()
->linkByHrefExists(Url::fromRoute('<front>')->toString());
// Other invalid destinations, should fall back to the form default.
$this->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => '/http://example.com',
],
]);
$this->assertSession()
->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.