From 4e0615281c45aa6c3416c80af7839153cbda24e8 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 8 Aug 2023 12:00:00 +0100 Subject: [PATCH] test: add AdminPageTest Test that anonymous users cannot access the administration area and users with the 'access administration pages' can. --- .../tests/src/Functional/AdminPageTest.php | 40 +++++++++++++++++++ .../tests/src/Functional/ExamplePageTest.php | 31 -------------- 2 files changed, 40 insertions(+), 31 deletions(-) create mode 100644 web/modules/custom/example/tests/src/Functional/AdminPageTest.php delete mode 100644 web/modules/custom/example/tests/src/Functional/ExamplePageTest.php diff --git a/web/modules/custom/example/tests/src/Functional/AdminPageTest.php b/web/modules/custom/example/tests/src/Functional/AdminPageTest.php new file mode 100644 index 0000000..e5253b6 --- /dev/null +++ b/web/modules/custom/example/tests/src/Functional/AdminPageTest.php @@ -0,0 +1,40 @@ +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); + } + +} diff --git a/web/modules/custom/example/tests/src/Functional/ExamplePageTest.php b/web/modules/custom/example/tests/src/Functional/ExamplePageTest.php deleted file mode 100644 index 5ecb1b8..0000000 --- a/web/modules/custom/example/tests/src/Functional/ExamplePageTest.php +++ /dev/null @@ -1,31 +0,0 @@ -drupalGet('/@opdavies/drupal-module-template'); - - // Assert. - $this->assertSession()->statusCodeEquals(Response::HTTP_OK); - } - -}