test: add AdminPageTest
Test that anonymous users cannot access the administration area and users with the 'access administration pages' can.
This commit is contained in:
parent
252729bb07
commit
4e0615281c
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Drupal\Tests\example\Functional;
|
||||||
|
|
||||||
|
use Drupal\Tests\BrowserTestBase;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
final class AdminPageTest extends BrowserTestBase {
|
||||||
|
|
||||||
|
public $defaultTheme = 'stark';
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function the_admin_page_is_not_accessible_to_anonymous_users(): void {
|
||||||
|
$this->drupalGet(path: '/admin');
|
||||||
|
|
||||||
|
$assert = $this->assertSession();
|
||||||
|
|
||||||
|
$assert->statusCodeEquals(Response::HTTP_FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function the_admin_page_is_accessible_by_admin_users(): void {
|
||||||
|
$adminUser = $this->createUser(
|
||||||
|
permissions: [
|
||||||
|
'access administration pages',
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->drupalLogin(account: $adminUser);
|
||||||
|
|
||||||
|
$this->drupalGet(path: '/admin');
|
||||||
|
|
||||||
|
$assert = $this->assertSession();
|
||||||
|
|
||||||
|
$assert->statusCodeEquals(Response::HTTP_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Drupal\Tests\example\Functional;
|
|
||||||
|
|
||||||
use Drupal\Tests\BrowserTestBase;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
|
|
||||||
final class ExamplePageTest extends BrowserTestBase {
|
|
||||||
|
|
||||||
public $defaultTheme = 'stark';
|
|
||||||
|
|
||||||
protected static $modules = [
|
|
||||||
// Core.
|
|
||||||
'node',
|
|
||||||
|
|
||||||
// Custom.
|
|
||||||
"example"
|
|
||||||
];
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function should_load_the_example_page_for_anonymous_users(): void {
|
|
||||||
// Arrange.
|
|
||||||
|
|
||||||
// Act.
|
|
||||||
$this->drupalGet('/@opdavies/drupal-module-template');
|
|
||||||
|
|
||||||
// Assert.
|
|
||||||
$this->assertSession()->statusCodeEquals(Response::HTTP_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Reference in a new issue