View source
<?php
namespace Drupal\Tests\webform\Functional\Element;
use Drupal\webform\Entity\Webform;
use Drupal\webform\WebformInterface;
class WebformElementTest extends WebformElementBrowserTestBase {
public static $modules = [
'webform_test_element',
];
public function testWebform() {
$webform = Webform::load('contact');
$this
->drupalGet('/webform_test_element');
$this
->assertFieldByName('email', '');
$this
->assertFieldByName('name', '');
$this
->assertFieldByName('subject', '');
$this
->assertFieldByName('message', '');
$this
->drupalGet('/webform_test_element', [
'query' => [
'default_data' => 'email: test',
],
]);
$this
->assertFieldByName('email', 'test');
$this
->drupalGet('/webform_test_element', [
'query' => [
'action' => 'http://drupal.org',
],
]);
$this
->assertRaw('action="http://drupal.org"');
$edit = [
'email' => 'example@example.com',
'name' => '{name}',
'subject' => '{subject}',
'message' => '{message}',
];
$this
->drupalPostForm('/webform_test_element', $edit, 'Send message');
$this
->assertUrl('/');
$this
->assertRaw('Your message has been sent.');
$sid = $this
->getLastSubmissionId($webform);
$this
->drupalGet('/webform_test_element', [
'query' => [
'sid' => $sid,
],
]);
$this
->assertNoFieldByName('email', 'example@example.com');
$webform
->setSetting('form_access_denied', WebformInterface::ACCESS_DENIED_MESSAGE);
$webform
->save();
$this
->drupalGet('/webform_test_element', [
'query' => [
'sid' => $sid,
],
]);
$this
->assertRaw("Please login to access this form.");
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/webform_test_element', [
'query' => [
'sid' => $sid,
],
]);
$this
->assertFieldByName('email', 'example@example.com');
$this
->assertFieldByName('name', '{name}');
$this
->assertFieldByName('subject', '{subject}');
$this
->assertFieldByName('message', '{message}');
$this
->assertRaw('Submission information');
$this
->drupalGet('/webform_test_element', [
'query' => [
'sid' => $sid,
'information' => 'false',
],
]);
$this
->assertNoRaw('Submission information');
}
}