From 214f30b9976c3d28f30ff6260a1bbc1858fa549c Mon Sep 17 00:00:00 2001
From: Raveen Thakur <63303-raveeny@users.noreply.drupalcode.org>
Date: Sun, 27 Oct 2024 05:54:24 +0000
Subject: [PATCH] Issue #3476179 by tr, sorlov: Route "regcode.admin_list" does
 not exist

---
 regcode.links.menu.yml                       |  2 +-
 regcode.links.task.yml                       | 18 ++--
 regcode.module                               |  2 +-
 tests/src/Functional/RegcodeSettingsTest.php | 87 +++++++++++++++++++-
 4 files changed, 92 insertions(+), 17 deletions(-)

diff --git a/regcode.links.menu.yml b/regcode.links.menu.yml
index f905e70..6e08521 100644
--- a/regcode.links.menu.yml
+++ b/regcode.links.menu.yml
@@ -1,5 +1,5 @@
 regcode.admin_list:
-  route_name: regcode.admin_list
   title: 'Registration codes'
   description: 'Manage registration codes.'
+  route_name: view.regcode.page_admin
   parent: user.admin_index
diff --git a/regcode.links.task.yml b/regcode.links.task.yml
index 0d8a423..521e206 100644
--- a/regcode.links.task.yml
+++ b/regcode.links.task.yml
@@ -1,23 +1,17 @@
-regcode.admin_list:
-  route_name: regcode.admin_list
-  title: List
-  weight: 10
-  base_route: regcode.admin_list
-  
 regcode.admin_create:
-  route_name: regcode.admin_create
   title: Create
+  route_name: regcode.admin_create
+  base_route: view.regcode.page_admin
   weight: 20
-  base_route: regcode.admin_list
 
 regcode.admin_manage:
-  route_name: regcode.admin_manage
   title: Manage
+  route_name: regcode.admin_manage
+  base_route: view.regcode.page_admin
   weight: 30
-  base_route: regcode.admin_list
   
 regcode.admin_settings:
-  route_name: regcode.admin_settings
   title: Settings
+  route_name: regcode.admin_settings
+  base_route: view.regcode.page_admin
   weight: 40
-  base_route: regcode.admin_list
diff --git a/regcode.module b/regcode.module
index 972f257..4116fcc 100644
--- a/regcode.module
+++ b/regcode.module
@@ -18,7 +18,7 @@ use Drupal\regcode\RegistrationCodeInterface;
 function regcode_help($path, $arg) {
   $output = '';
   switch ($path) {
-    case 'regcode.admin_list':
+    case 'view.regcode.page_admin':
       $output = '<p>' . t('View and manage created registration codes.') . '</p>';
       break;
 
diff --git a/tests/src/Functional/RegcodeSettingsTest.php b/tests/src/Functional/RegcodeSettingsTest.php
index b0bf1bc..fb917eb 100644
--- a/tests/src/Functional/RegcodeSettingsTest.php
+++ b/tests/src/Functional/RegcodeSettingsTest.php
@@ -18,7 +18,7 @@ class RegcodeSettingsTest extends BrowserTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['regcode', 'help', 'block'];
+  protected static $modules = ['regcode', 'help', 'block', 'views'];
 
   /**
    * {@inheritdoc}
@@ -58,9 +58,9 @@ class RegcodeSettingsTest extends BrowserTestBase {
   }
 
   /**
-   * Tests module permissions / access to configuration page.
+   * Tests access to module settings tab.
    */
-  public function testUserAccess(): void {
+  public function testSettingsTab(): void {
     /** @var \Drupal\Tests\WebAssert $assert */
     $assert = $this->assertSession();
 
@@ -84,4 +84,85 @@ class RegcodeSettingsTest extends BrowserTestBase {
     $this->drupalLogout();
   }
 
+  /**
+   * Tests access to code list tab.
+   */
+  public function testListTab(): void {
+    /** @var \Drupal\Tests\WebAssert $assert */
+    $assert = $this->assertSession();
+
+    // Test as anonymous user.
+    $this->drupalGet('admin/config/people/regcode');
+    $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');
+    $assert->statusCodeEquals(403);
+    $this->drupalLogout();
+
+    // Test as admin user.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('admin/config/people/regcode');
+    $assert->statusCodeEquals(200);
+    $assert->pageTextContains('View and manage created registration codes.');
+    $this->drupalLogout();
+  }
+
+  /**
+   * Tests access to code creation tab.
+   */
+  public function testCreateTab(): void {
+    /** @var \Drupal\Tests\WebAssert $assert */
+    $assert = $this->assertSession();
+
+    // Test as anonymous user.
+    $this->drupalGet('admin/config/people/regcode/create');
+    $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/create');
+    $assert->statusCodeEquals(403);
+    $this->drupalLogout();
+
+    // Test as admin user.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('admin/config/people/regcode/create');
+    $assert->statusCodeEquals(200);
+    $assert->pageTextContains('Create manually or generate new registration codes.');
+    $this->drupalLogout();
+  }
+
+  /**
+   * Tests access to code manage tab.
+   */
+  public function testManageTab(): void {
+    /** @var \Drupal\Tests\WebAssert $assert */
+    $assert = $this->assertSession();
+
+    // Test as anonymous user.
+    $this->drupalGet('admin/config/people/regcode/manage');
+    $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/manage');
+    $assert->statusCodeEquals(403);
+    $this->drupalLogout();
+
+    // Test as admin user.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('admin/config/people/regcode/manage');
+    $assert->statusCodeEquals(200);
+    $assert->pageTextContains('Provides bulk management features for created registration codes.');
+    $this->drupalLogout();
+  }
+
 }
-- 
GitLab