Skip to content
Snippets Groups Projects
Commit bd5dd633 authored by Tim Rohaly's avatar Tim Rohaly
Browse files

Merge branch '3225738-add-test-case' into '2.0.x'

Issue #3225738 by TR: Add test case for settings form

See merge request !10
parents 07aa4113 ffcdfa24
Branches
Tags
No related merge requests found
Pipeline #273063 passed
<?php
declare(strict_types=1);
namespace Drupal\Tests\regcode\Functional;
use Drupal\Tests\BrowserTestBase;
// cspell:ignore unpriv
/**
* Tests operation of the Regcode settings page.
*
* @group Regcode
*/
class RegcodeSettingsTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['regcode', 'help', 'block'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Admin user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $adminUser;
/**
* Authenticated but unprivileged user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $unprivUser;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// System help block is needed to see output from hook_help().
$this->drupalPlaceBlock('help_block', ['region' => 'help']);
// Create our test users.
$this->adminUser = $this->createUser([
'administer site configuration',
'access administration pages',
'administer registration codes',
]);
$this->unprivUser = $this->createUser();
}
/**
* Tests module permissions / access to configuration page.
*/
public function testUserAccess() {
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this->assertSession();
// Test as anonymous user.
$this->drupalGet('admin/config/people/regcode/settings');
$assert->statusCodeEquals(403);
$assert->pageTextContains('Access denied');
$assert->pageTextContains('You are not authorized to access this page.');
// Test as authenticated but unprivileged user.
$this->drupalLogin($this->unprivUser);
$this->drupalGet('admin/config/people/regcode/settings');
$assert->statusCodeEquals(403);
$this->drupalLogout();
// Test as admin user.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/people/regcode/settings');
$assert->statusCodeEquals(200);
$assert->pageTextContains('Configure the registration code module.');
$this->drupalLogout();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment