ConfirmFormTest.php in Drupal 10
File
core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Form;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class ConfirmFormTest extends BrowserTestBase {
protected static $modules = [
'form_test',
];
protected $defaultTheme = 'stark';
public function testConfirmForm() {
$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().');
$this
->clickLink('ConfirmFormTestForm::getCancelText().');
$this
->assertSession()
->addressEquals('form-test/autocomplete');
$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('');
$this
->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => 'admin/config',
],
]);
$this
->submitForm([], 'ConfirmFormTestForm::getConfirmText().');
$this
->assertSession()
->addressEquals('admin/config');
$this
->drupalGet('form-test/confirm-form-array-path');
$this
->clickLink('ConfirmFormArrayPathTestForm::getCancelText().');
$this
->assertSession()
->addressEquals('form-test/confirm-form?destination=admin/config');
}
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());
$this
->drupalGet('form-test/confirm-form', [
'query' => [
'destination' => '/http://example.com',
],
]);
$this
->assertSession()
->linkByHrefExists(Url::fromRoute('form_test.route8')
->toString());
}
}