SecuritytxtBaseTest.php in Security.txt 8
File
tests/src/Functional/SecuritytxtBaseTest.php
View source
<?php
namespace Drupal\Tests\securitytxt\Functional;
use Drupal\Tests\BrowserTestBase;
abstract class SecuritytxtBaseTest extends BrowserTestBase {
public static $modules = [
'securitytxt',
];
protected $authenticatedUser;
protected $viewPermissionUser;
protected $administerPermissionUser;
protected $viewAndAdministerPermissionUser;
protected function setUp() {
parent::setUp();
$this->authenticatedUser = $this
->drupalCreateUser([]);
$this->viewPermissionUser = $this
->drupalCreateUser([
'view securitytxt',
]);
$this->administerPermissionUser = $this
->drupalCreateUser([
'administer securitytxt',
]);
$this->viewAndAdministerPermissionUser = $this
->drupalCreateUser([
'view securitytxt',
'administer securitytxt',
]);
}
protected function getValidConfiguration() {
$valid_configuration = [];
$valid_configuration['enabled'] = TRUE;
$valid_configuration['contact_email'] = $this
->randomMachineName(16) . '@example.com';
$valid_configuration['contact_phone'] = '+44-7700-900' . rand(100, 999);
$valid_configuration['contact_url'] = 'https://example.com/contact/' . $this
->randomMachineName(16);
$valid_configuration['encryption_key_url'] = 'https://example.com/key/' . $this
->randomMachineName(16);
$valid_configuration['policy_url'] = 'https://example.com/policy/' . $this
->randomMachineName(16);
$valid_configuration['acknowledgement_url'] = 'https://example.com/acknowledgement/' . $this
->randomMachineName(16);
$valid_configuration['signature_text'] = $this
->randomMachineName(512);
return $valid_configuration;
}
protected function submitConfigureForm(array $edit) {
$path = 'admin/config/system/securitytxt';
$submit = 'Save configuration';
$options = [];
$this
->drupalPostForm($path, $edit, $submit, $options);
}
protected function submitSignForm(array $edit) {
$path = 'admin/config/system/securitytxt/sign';
$submit = 'Save configuration';
$options = [];
$this
->drupalPostForm($path, $edit, $submit, $options);
}
protected function submitValidConfiguration() {
$this
->drupalLogin($this->administerPermissionUser);
$this
->assertSession()
->statusCodeEquals(200);
$valid_configuration = $this
->getValidConfiguration();
$configure_edit = $valid_configuration;
unset($configure_edit['signature_text']);
$this
->submitConfigureForm($configure_edit);
$sign_edit['signature_text'] = $valid_configuration['signature_text'];
$this
->submitSignForm($sign_edit);
$this
->drupalLogout();
$this
->assertSession()
->statusCodeEquals(200);
return $valid_configuration;
}
}