From 8c0d9042b2416083f1b0473b46a139cd1371226b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 31 Jan 2022 13:12:36 +0100 Subject: [PATCH] MOBILE-3833 behat: Test custom URL that calls WS when logged out --- tests/behat/behat_app.php | 24 +++++++++++++++++++++--- tests/behat/navigation_deeplinks.feature | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/tests/behat/behat_app.php b/tests/behat/behat_app.php index 3bd63c9f2..e9a1901ad 100644 --- a/tests/behat/behat_app.php +++ b/tests/behat/behat_app.php @@ -691,9 +691,27 @@ class behat_app extends behat_base { public function i_open_a_custom_link(TableNode $data) { global $DB, $CFG; - $data = (object) $data->getColumnsHash()[0]; - $discussion = $DB->get_record('forum_discussions', ['name' => $data->discussion]); - $pageurl = "{$CFG->behat_wwwroot}/mod/forum/discuss.php?d={$discussion->id}"; + $data = $data->getColumnsHash()[0]; + $title = array_keys($data)[0]; + $data = (object) $data; + + switch ($title) { + case 'discussion': + $discussion = $DB->get_record('forum_discussions', ['name' => $data->discussion]); + $pageurl = "{$CFG->behat_wwwroot}/mod/forum/discuss.php?d={$discussion->id}"; + + break; + + case 'forum': + $forumdata = $DB->get_record('forum', ['name' => $data->forum]); + $cm = get_coursemodule_from_instance('forum', $forumdata->id); + $pageurl = "{$CFG->behat_wwwroot}/mod/forum/view.php?id={$cm->id}"; + break; + + default: + throw new DriverException('Invalid custom link title - ' . $title); + } + $url = "moodlemobile://link=" . urlencode($pageurl); $this->evaluate_script("return window.urlSchemes.handleCustomURL('$url')"); diff --git a/tests/behat/navigation_deeplinks.feature b/tests/behat/navigation_deeplinks.feature index 0b7ec9a82..b59d89794 100644 --- a/tests/behat/navigation_deeplinks.feature +++ b/tests/behat/navigation_deeplinks.feature @@ -20,7 +20,8 @@ Feature: It navigates properly using deep links. | forum | user | name | message | | Test forum | student1 | Forum topic | Forum message | And the following config values are set as admin: - | forcelogout | 1 | tool_mobile | + | forcelogout | 1 | tool_mobile | + | defaulthomepage | 0 | | Scenario: Receive a push notification When I enter the app @@ -64,3 +65,22 @@ Feature: It navigates properly using deep links. Then I should find "Site home" in the app But I should not find "Forum topic" in the app And I should not find "Forum message" in the app + + Scenario: Open a link with a custom URL that calls WebServices for a logged out site + When I enter the app + And I log in as "student2" + And I press the user menu button in the app + And I press "Log out" in the app + And I wait the app to restart + And I open a custom link in the app for: + | forum | + | Test forum | + Then I should find "Reconnect" in the app + + When I set the field "Password" to "student2" in the app + And I press "Log in" in the app + Then I should find "Test forum" in the app + + When I press the back button in the app + Then I should find "Site home" in the app + But I should not find "Test forum" in the app