From 1646e0136736b51f5207ee0975b5b7a704950b30 Mon Sep 17 00:00:00 2001 From: Igor Biki <ibiki@uwaterloo.ca> Date: Fri, 14 May 2021 16:12:19 -0400 Subject: [PATCH] ISTWCMS-4818: Adding tests for ofis module. --- tests/src/Functional/UwWcmsBasicTest.php | 46 ++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/tests/src/Functional/UwWcmsBasicTest.php b/tests/src/Functional/UwWcmsBasicTest.php index c18d1e2dc..ed2034525 100644 --- a/tests/src/Functional/UwWcmsBasicTest.php +++ b/tests/src/Functional/UwWcmsBasicTest.php @@ -2420,19 +2420,45 @@ class UwWcmsBasicTest extends BrowserTestBase { * * Testing: * - has module been enabled by default. - * - check config page, default api endopoint, and disabled profiles. - * - check ofis profile (without contact), expect 404. - * - create contact (unpublished), check ofis again, expect 404. - * - publish contact, check ofis again, expect profile display. - * - update contact so its watiam is missing, check ofis, expect 404. - * - * Note: - * Service test should be in kernel tests. And using actual live ofis - * profile may not be good, profile may be disabled/deleted and would cause - * tests to fail. So, mocking service response may be needed. + * - admin role checks: + * - check config page, default api endopoint, and disabled profiles. + * - site owner checks: + * - login as site owner, and check if you have access to config page. + * - confirm api_endpoint field is not on config form. */ public function ofisTest() { + // Check if module is enabled with profile install. + $module_enabled = \Drupal::moduleHandler()->moduleExists('uw_ws_ofis'); + $this->assertTrue($module_enabled, 'Module uw_ws_ofis not enabled.'); + + // Login as administrator and check ofis config form. + $this->drupalLogin($this->drupalUsers['administrator']); + $this->drupalGet('admin/config/uw_ws_ofis'); + $this->assertSession()->statusCodeEquals(200); + + // Validate settings form fields for administrator. + $this->assertSession()->pageTextContains('Clear OFIS caches'); + $this->assertSession()->fieldExists('API endpoint'); + $this->assertSession()->fieldExists('Enable OFIS profiles'); + + $this->drupalLogout(); + + // Login as site owner. + $this->drupalLogin($this->drupalUsers['uw_role_site_owner']); + + // Get to config form using dashboard. + $this->drupalGet('dashboard/my_dashboard'); + $this->assertSession()->linkExists('OFIS settings'); + $this->clickLink('OFIS settings'); + $this->assertSession()->statusCodeEquals(200); + + // Make sure enable/disable profiles is available. + $this->assertSession()->fieldExists('Enable OFIS profiles'); + + // API endpoint and cache clear should not be visible to site owner. + $this->assertSession()->fieldNotExists('API endpoint'); + $this->assertSession()->pageTextNotContains('Clear OFIS caches'); } } -- GitLab