AntibotJavaScriptTest.php in Antibot 8
File
tests/src/FunctionalJavascript/AntibotJavaScriptTest.php
View source
<?php
namespace Drupal\Tests\antibot\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class AntibotJavaScriptTest extends WebDriverTestBase {
protected static $modules = [
'antibot',
];
protected $defaultTheme = 'stark';
public function testJavaScript() {
$this
->drupalGet('/user/password');
$page = $this
->getSession()
->getPage();
$driver = $this
->getSession()
->getDriver();
$page
->fillField('Username or email address', $this
->randomMachineName());
$javascript = <<<javascript
jQuery('form[data-drupal-selector="user-pass"]').submit();
javascript;
$this
->assertJsCondition($javascript);
$this
->assertSession()
->pageTextContains('Submission failed');
$this
->assertSession()
->pageTextContains('You have reached this page because you submitted a form that required JavaScript to be enabled on your browser. This protection is in place to attempt to prevent automated submissions made on forms. Please return to the page that you came from and enable JavaScript on your browser before attempting to submit the form again.');
$this
->drupalGet('/user/password');
$name = $this
->randomMachineName();
$page
->fillField('Username or email address', $name);
$driver
->mouseOver('//h1[text() = "Reset your password"]');
$this
->assertJsCondition($javascript);
$this
->assertSession()
->pageTextContains("{$name} is not recognized as a username or an email address.");
$driver
->dragTo('//h1[text() = "Reset your password"]', '//p[text() = "Password reset instructions will be sent to your registered email address."]');
$name = $this
->randomMachineName();
$page
->fillField('Username or email address', $name);
$this
->assertJsCondition($javascript);
$this
->assertSession()
->pageTextContains("{$name} is not recognized as a username or an email address.");
}
}