HoneypotAdminFormTest.php in Honeypot 2.0.x
File
tests/src/Functional/HoneypotAdminFormTest.php
View source
<?php
namespace Drupal\Tests\honeypot\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class HoneypotAdminFormTest extends BrowserTestBase {
use StringTranslationTrait;
protected $adminUser;
protected $defaultTheme = 'stark';
public static $modules = [
'honeypot',
];
public function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer honeypot',
'bypass honeypot protection',
]);
}
public function testElementNameUpdateSuccess() {
$this
->drupalLogin($this->adminUser);
$edit['element_name'] = "test";
$this
->drupalPostForm('admin/config/content/honeypot', $edit, $this
->t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
$edit['element_name'] = "test-1";
$this
->drupalPostForm('admin/config/content/honeypot', $edit, $this
->t('Save configuration'));
$this
->assertSession()
->pageTextContains('The configuration options have been saved.');
}
public function testElementNameUpdateFirstCharacterFail() {
$this
->drupalLogin($this->adminUser);
$edit['element_name'] = "1test";
$this
->drupalPostForm('admin/config/content/honeypot', $edit, $this
->t('Save configuration'));
$this
->assertSession()
->pageTextContains('The element name must start with a letter.');
}
public function testElementNameUpdateInvalidCharacterFail() {
$this
->drupalLogin($this->adminUser);
$edit['element_name'] = "special-character-&";
$this
->drupalPostForm('admin/config/content/honeypot', $edit, $this
->t('Save configuration'));
$this
->assertSession()
->pageTextContains('The element name cannot contain spaces or other special characters.');
$edit['element_name'] = "space in name";
$this
->drupalPostForm('admin/config/content/honeypot', $edit, $this
->t('Save configuration'));
$this
->assertSession()
->pageTextContains('The element name cannot contain spaces or other special characters.');
}
}