You are here

public function PermissionsTest::testPermissionToExecuteCode in Devel PHP 8

Tests user permissions to execute code.

File

tests/src/Functional/PermissionsTest.php, line 35

Class

PermissionsTest
Tests permissions.

Namespace

Drupal\Tests\devel_php\Functional

Code

public function testPermissionToExecuteCode() {
  $url = Url::fromRoute('devel_php.execute_php');

  // Anonymous user.
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // User without permissions.
  $user = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $user = $this
    ->drupalCreateUser([
    'execute php code',
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementExists('xpath', "//form[@id='devel-execute-form']");
}