From 5ea1b832a6ff9c8b6ba77dd3994419f1f315d732 Mon Sep 17 00:00:00 2001 From: Juampy Date: Sat, 6 Feb 2016 05:11:56 +0100 Subject: [PATCH] [#51] Add permission to administer Redirect settings --- redirect.permissions.yml | 2 ++ redirect.routing.yml | 4 ++-- src/Tests/RedirectUITest.php | 44 +++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/redirect.permissions.yml b/redirect.permissions.yml index d5cf137..7dc1ad5 100644 --- a/redirect.permissions.yml +++ b/redirect.permissions.yml @@ -1,2 +1,4 @@ administer redirects: title: 'Administer URL redirections' +change redirect settings: + title: 'Change redirect settings' diff --git a/redirect.routing.yml b/redirect.routing.yml index 36b433d..1a15c67 100644 --- a/redirect.routing.yml +++ b/redirect.routing.yml @@ -44,7 +44,7 @@ redirect.settings: _form: '\Drupal\redirect\Form\RedirectSettingsForm' _title: 'Settings' requirements: - _permission: 'administer redirects' + _permission: 'change redirect settings' redirect.fix_404: path: '/admin/config/search/redirect/404' @@ -52,7 +52,7 @@ redirect.fix_404: _title: 'Fix 404 pages' _form: '\Drupal\redirect\Form\RedirectFix404Form' requirements: - _permission: 'administer redirects' + _permission: 'change redirect settings' #redirect.devel_generate: # requirements: diff --git a/src/Tests/RedirectUITest.php b/src/Tests/RedirectUITest.php index 9aa2c66..496460d 100644 --- a/src/Tests/RedirectUITest.php +++ b/src/Tests/RedirectUITest.php @@ -21,6 +21,11 @@ */ class RedirectUITest extends WebTestBase { + /** + * @var array + */ + protected $userPermissions; + /** * @var \Drupal\Core\Session\AccountInterface */ @@ -48,7 +53,7 @@ protected function setUp() { parent::setUp(); $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); - $this->adminUser = $this->drupalCreateUser(array( + $this->userPermissions = [ 'administer redirects', 'access site reports', 'access content', @@ -56,7 +61,8 @@ protected function setUp() { 'create url aliases', 'administer taxonomy', 'administer url aliases', - )); + ]; + $this->adminUser = $this->drupalCreateUser($this->userPermissions); $this->repository = \Drupal::service('redirect.repository'); @@ -228,6 +234,18 @@ public function testRedirectUI() { public function testFix404Pages() { $this->drupalLogin($this->adminUser); + // Test the permission "Change Redirect settings". + $this->drupalGet('admin/config/search/redirect/404'); + $this->assertResponse(403); + + // Now create and log in a user with the proper permissions. + $adminUser = $this->drupalCreateUser(array_merge($this->userPermissions, ['change redirect settings'])); + $this->drupalLogin($adminUser); + + // Test access again. + $this->drupalGet('admin/config/search/redirect/404'); + $this->assertResponse(200); + // Visit a non existing page to have the 404 watchdog entry. $this->drupalGet('non-existing'); @@ -251,6 +269,25 @@ public function testFix404Pages() { $this->assertUrl('node'); } + /** + * Tests the Settings page. + */ + public function testSettingsPage() { + $this->drupalLogin($this->adminUser); + + // Test the permission "Change Redirect settings". + $this->drupalGet('admin/config/search/redirect/settings'); + $this->assertResponse(403); + + // Now create and log in a user with the proper permissions. + $adminUser = $this->drupalCreateUser(array_merge($this->userPermissions, ['change redirect settings'])); + $this->drupalLogin($adminUser); + + // Test access again. + $this->drupalGet('admin/config/search/redirect/settings'); + $this->assertResponse(200); + } + /** * Tests redirects being automatically created upon path alias change. */ @@ -474,7 +511,8 @@ public function testExternal() { $redirect->setStatusCode(301); $redirect->save(); $this->assertRedirect('a-path', 'https://www.example.org'); - $this->drupalLogin($this->adminUser); + $adminUser = $this->drupalCreateUser(array_merge($this->userPermissions, ['change redirect settings'])); + $this->drupalLogin($adminUser); $this->drupalPostForm('admin/config/search/redirect/settings', ['redirect_deslash' => 1], t('Save configuration')); $this->drupalGet('/2015/10/10/'); $this->assertResponse(404);