AnonymousRedirectConfigTest.php in Anonymous Redirect 8.2
File
src/Tests/AnonymousRedirectConfigTest.php
View source
<?php
namespace Drupal\anonymous_redirect\Tests;
use Drupal\Tests\BrowserTestBase;
class AnonymousRedirectConfigTest extends BrowserTestBase {
public static $modules = [
'anonymous_redirect',
'node',
];
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'access content',
'administer site configuration',
]);
}
public function testConfigFormWorks() {
$this->user
->addRole('administrator');
$this->user
->removeRole('anonymous');
$this
->drupalLogin($this->user);
$this
->drupalGet('/admin/config/system/anonymous-redirect');
$this
->assertResponse(200);
$config = $this
->config('anonymous_redirect.settings');
$this
->assertFieldByName('enable_anonymous_redirect', $config
->get('enable_redirect'), 'The Enable Redirect field was found with the correct value');
$this
->assertFieldByName('redirect_base_url', $config
->get('redirect_url'), 'The redirect_base_url field exists and holds an appropriate value');
$this
->assertFieldByName('redirect_url_overrides', $config
->get('redirect_url_overrides'), 'The redirect_url_overrides field exists and holds an appropriate value');
$this
->drupalPostForm('/admin/config/system/anonymous-redirect', [
'enable_anonymous_redirect' => TRUE,
'redirect_base_url' => '<front>',
'redirect_url_overrides' => '/test',
], $this
->t('Save configuration'));
$this
->assertText('The configuration options have been saved.', 'The form was saved correctly.');
$this
->drupalGet('/admin/config/system/anonymous-redirect');
$this
->assertResponse(200);
$this
->assertFieldByName('enable_anonymous_redirect', TRUE, 'Value for the enable_redirect field was set successfully');
$this
->assertFieldByName('redirect_base_url', '<front>', 'Value for the redirect_base_url field was set successfully');
$this
->assertFieldByName('redirect_url_overrides', '/test', 'Value for the redirect_url_overrides field was set successfully');
}
}