diff --git a/tests/src/Functional/UwWcmsBasicTest.php b/tests/src/Functional/UwWcmsBasicTest.php index c18d1e2dce11b30fa3b51f01f3208432f140a0c4..ed2034525caffa3c7a6a2a43d5fa73facb5d509f 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'); } }