diff --git a/tests/php/Dev/DevAdminControllerTest.php b/tests/php/Dev/DevAdminControllerTest.php index 60e93fed0a5..8517385968d 100644 --- a/tests/php/Dev/DevAdminControllerTest.php +++ b/tests/php/Dev/DevAdminControllerTest.php @@ -2,11 +2,13 @@ namespace SilverStripe\Dev\Tests; +use Exception; +use ReflectionMethod; +use SilverStripe\Control\Director; use SilverStripe\Dev\DevelopmentAdmin; use SilverStripe\Dev\FunctionalTest; -use SilverStripe\Control\Director; -use Exception; use SilverStripe\Dev\Tests\DevAdminControllerTest\Controller1; +use SilverStripe\Dev\Tests\DevAdminControllerTest\ControllerWithPermissions; /** * Note: the running of this test is handled by the thing it's testing (DevelopmentAdmin controller). @@ -21,19 +23,25 @@ protected function setUp(): void DevelopmentAdmin::config()->merge( 'registered_controllers', [ - 'x1' => [ - 'controller' => Controller1::class, - 'links' => [ - 'x1' => 'x1 link description', - 'x1/y1' => 'x1/y1 link description' - ] - ], - 'x2' => [ - 'controller' => 'DevAdminControllerTest_Controller2', // intentionally not a class that exists - 'links' => [ - 'x2' => 'x2 link description' - ] - ] + 'x1' => [ + 'controller' => Controller1::class, + 'links' => [ + 'x1' => 'x1 link description', + 'x1/y1' => 'x1/y1 link description' + ] + ], + 'x2' => [ + 'controller' => 'DevAdminControllerTest_Controller2', // intentionally not a class that exists + 'links' => [ + 'x2' => 'x2 link description' + ] + ], + 'x3' => [ + 'controller' => ControllerWithPermissions::class, + 'links' => [ + 'x3' => 'x3 link description' + ] + ], ] ); } @@ -57,7 +65,33 @@ public function testGoodRegisteredControllerStatus() $this->assertEquals(true, $this->getAndCheckForError('/dev/x2')); } + /** + * @dataProvider getLinksPermissionsProvider + */ + public function testGetLinks(string $permission, int $count): void + { + DevelopmentAdmin::config()->set('allow_all_cli', false); + $this->logInWithPermission($permission); + $controller = new DevelopmentAdmin(); + $method = new ReflectionMethod($controller, 'getLinks'); + $method->setAccessible(true); + + $this->assertCount( + $count, + $method->invoke($controller), + 'Incorrect amount of links shown for permission level' + ); + } + protected function getLinksPermissionsProvider() : array + { + return [ + ['ADMIN', 8], + ['ALL_DEV_ADMIN', 8], + ['DEV_ADMIN_TEST_PERMISSION', 1], + ['NOTHING', 0], + ]; + } protected function getCapture($url) { diff --git a/tests/php/Dev/DevAdminControllerTest/ControllerWithPermissions.php b/tests/php/Dev/DevAdminControllerTest/ControllerWithPermissions.php new file mode 100644 index 00000000000..ddf6971355a --- /dev/null +++ b/tests/php/Dev/DevAdminControllerTest/ControllerWithPermissions.php @@ -0,0 +1,39 @@ + 'index', + ]; + + private static $allowed_actions = [ + 'index', + ]; + + + public function index() + { + echo self::OK_MSG; + } + + public function canInit() + { + return Permission::check('DEV_ADMIN_TEST_PERMISSION'); + } + + public function providePermissions() + { + return [ + 'DEV_ADMIN_TEST_PERMISSION' => 'Dev admin test permission', + ]; + } +}