From 0399150fdd0d24532b3939f38fd9fe77dfe9f5a1 Mon Sep 17 00:00:00 2001 From: Liam Morland <lkmorlan@uwaterloo.ca> Date: Tue, 1 Jun 2021 19:05:41 -0400 Subject: [PATCH] ISTWCMS-4635: Test dashboard dropbutton link display --- tests/src/Functional/UwWcmsBasicTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/src/Functional/UwWcmsBasicTest.php b/tests/src/Functional/UwWcmsBasicTest.php index 3a423a52d..ceca0f8f4 100644 --- a/tests/src/Functional/UwWcmsBasicTest.php +++ b/tests/src/Functional/UwWcmsBasicTest.php @@ -1414,6 +1414,17 @@ class UwWcmsBasicTest extends BrowserTestBase { * Test default dashboard. */ private function dashboardTest() { + // Used by dropbutton test. + $layout_link_xpath = $this->buildXPathQuery('//ul[@class=:class]/li/a[contains(@href, :href)]', [ + ':class' => 'dropbutton', + ':href' => '/home/layout', + ]); + $layout_link_no_access_roles = [ + 'uw_role_site_owner', + 'uw_role_form_editor', + 'uw_role_form_results_access', + ]; + // Anonymous user cannot view "Who's online" block in dashboard. if ($this->loggedInUser) { $this->drupalLogout(); @@ -1446,6 +1457,16 @@ class UwWcmsBasicTest extends BrowserTestBase { $this->assertSession()->linkNotExists('People'); $this->assertSession()->linkNotExists('Reports'); } + + // Test that dropbuttons do not have links to which the user has no + // access. + $link_exists = (bool) $this->xpath($layout_link_xpath); + if (in_array($role, $layout_link_no_access_roles)) { + $this->assertFalse($link_exists, 'No access to layout dropbutton.'); + } + else { + $this->assertTrue($link_exists, 'Has access to layout dropbutton.'); + } } else { $this->assertSession()->statusCodeEquals(403); -- GitLab