From 6d288c54f2fa10ea3fbeaf1a5e31dcbc661cc1ff Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Thu, 28 Apr 2022 09:50:48 +1200 Subject: [PATCH] Add new permission group --- src/Model/BrokenExternalLink.php | 2 +- tests/php/Model/BrokenExternalLinkTest.php | 37 +++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Model/BrokenExternalLink.php b/src/Model/BrokenExternalLink.php index d7a1bea..1a896df 100644 --- a/src/Model/BrokenExternalLink.php +++ b/src/Model/BrokenExternalLink.php @@ -58,7 +58,7 @@ public function canEdit($member = false) public function canView($member = false) { $member = $member ? $member : Security::getCurrentUser(); - $codes = array('content-authors', 'administrators'); + $codes = ['CMS_ACCESS_CMSMain']; return Permission::checkMember($member, $codes); } diff --git a/tests/php/Model/BrokenExternalLinkTest.php b/tests/php/Model/BrokenExternalLinkTest.php index 4160304..ddfeb13 100644 --- a/tests/php/Model/BrokenExternalLinkTest.php +++ b/tests/php/Model/BrokenExternalLinkTest.php @@ -8,21 +8,16 @@ class BrokenExternalLinkTest extends SapphireTest { /** - * @param int $httpCode - * @param string $expected * @dataProvider httpCodeProvider */ - public function testGetHTTPCodeDescription($httpCode, $expected) + public function testGetHTTPCodeDescription(int $httpCode, string $expected) { $link = new BrokenExternalLink(); $link->HTTPCode = $httpCode; $this->assertSame($expected, $link->getHTTPCodeDescription()); } - - /** - * @return array[] - */ - public function httpCodeProvider() + + public function httpCodeProvider(): array { return [ [200, '200 (OK)'], @@ -32,4 +27,30 @@ public function httpCodeProvider() [789, '789 (Unknown Response Code)'], ]; } + + public function permissionProvider(): array + { + return [ + ['admin', 'ADMIN'], + ['content-author', 'CMS_ACCESS_CMSMain'], + ['asset-admin', 'CMS_ACCESS_AssetAdmin'], + ]; + } + + /** + * @dataProvider permissionProvider + */ + public function testCanViewReport(string $user, string $permission) + { + $this->logOut(); + $this->logInWithPermission($permission); + + $link = new BrokenExternalLink(); + + if ($user === 'asset-admin') { + $this->assertFalse($link->canView()); + } else { + $this->assertTrue($link->canView()); + } + } }