Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile 4028 #4245

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion local_moodleappbehat/tests/behat/behat_app.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ public function i_open_a_custom_link(TableNode $data) {
$data = $data->getColumnsHash()[0];
$title = array_keys($data)[0];
$data = (object) $data;
$username = $data->user ?? '';

switch ($title) {
case 'discussion':
Expand Down Expand Up @@ -645,7 +646,7 @@ public function i_open_a_custom_link(TableNode $data) {
throw new DriverException('Invalid custom link title - ' . $title);
}

$this->open_moodleapp_custom_url($pageurl);
$this->open_moodleapp_custom_url($pageurl, '', $username);
}

/**
Expand Down
77 changes: 60 additions & 17 deletions local_moodleappbehat/tests/behat/behat_app_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,15 @@ protected function runtime_js(string $script) {
*
* @param string $script
* @param bool $blocking
* @param string $texttofind If set, when this text is found the operation is considered finished. This is useful for
* operations that might expect user input before finishing, like a confirm modal.
* @return mixed Result.
*/
protected function zone_js(string $script, bool $blocking = false) {
protected function zone_js(string $script, bool $blocking = false, string $texttofind = '') {
$blockingjson = json_encode($blocking);
$locatortofind = !empty($texttofind) ? json_encode((object) ['text' => $texttofind]) : null;

return $this->runtime_js("runInZone(() => window.behat.$script, $blockingjson)");
return $this->runtime_js("runInZone(() => window.behat.$script, $blockingjson, $locatortofind)");
}

/**
Expand Down Expand Up @@ -411,16 +414,14 @@ protected function open_moodleapp_custom_login_url($username, $path = '', string
$privatetoken = $usertoken->privatetoken;
}

// Generate custom URL.
$parsed_url = parse_url($CFG->behat_wwwroot);
$site = $parsed_url['host'] ?? '';
$site .= isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
$site .= $parsed_url['path'] ?? '';
$url = $this->get_mobile_url_scheme() . "://$username@$site?token=$token&privatetoken=$privatetoken";
$url = $this->generate_custom_url([
'username' => $username,
'token' => $token,
'privatetoken' => $privatetoken,
'redirect' => $path,
]);

if (!empty($path)) {
$url .= '&redirect='.urlencode($CFG->behat_wwwroot.$path);
} else {
if (empty($path)) {
$successXPath = '//page-core-mainmenu';
}

Expand All @@ -434,24 +435,66 @@ protected function open_moodleapp_custom_login_url($username, $path = '', string
*
* @param string $path To navigate.
* @param string $successXPath The XPath of the element to lookat after navigation.
* @param string $username The username to use.
*/
protected function open_moodleapp_custom_url(string $path, string $successXPath = '', string $username = '') {
global $CFG;

$url = $this->generate_custom_url([
'username' => $username,
'redirect' => $path,
]);

$this->handle_url($url, $successXPath, $username ? 'This link belongs to another site' : '');
}

/**
* Generates a custom URL to be treated by the app.
*
* @param array $data Data to generate the URL.
*/
protected function open_moodleapp_custom_url(string $path, string $successXPath = '') {
protected function generate_custom_url(array $data): string {
global $CFG;

$urlscheme = $this->get_mobile_url_scheme();
$url = "$urlscheme://link=" . urlencode($CFG->behat_wwwroot.$path);
$parsed_url = parse_url($CFG->behat_wwwroot);
$parameters = [];

$url = $this->get_mobile_url_scheme() . '://' . ($parsed_url['scheme'] ?? 'http') . '://';
if (!empty($data['username'])) {
$url .= $data['username'] . '@';
}
$url .= $parsed_url['host'] ?? '';
$url .= isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
$url .= $parsed_url['path'] ?? '';

if (!empty($data['token'])) {
$parameters[] = 'token=' . $data['token'];
if (!empty($data['privatetoken'])) {
$parameters[] = 'privatetoken=' . $data['privatetoken'];
}
}

if (!empty($data['redirect'])) {
$parameters[] = 'redirect=' . urlencode($data['redirect']);
}

if (!empty($parameters)) {
$url .= '?' . implode('&', $parameters);
}

$this->handle_url($url);
return $url;
}

/**
* Handles the custom URL on the Moodle App (and waits to finish.)
*
* @param string $customurl To navigate.
* @param string $successXPath The XPath of the element to lookat after navigation.
* @param string $texttofind If set, when this text is found the operation is considered finished. This is useful for
* operations that might expect user input before finishing, like a confirm modal.
*/
protected function handle_url(string $customurl, string $successXPath = '') {
$result = $this->zone_js("customUrlSchemes.handleCustomURL('$customurl')");
protected function handle_url(string $customurl, string $successXPath = '', string $texttofind = '') {
$result = $this->zone_js("customUrlSchemes.handleCustomURL('$customurl')", false, $texttofind);

if ($result !== 'OK') {
throw new DriverException('Error handling url - ' . $customurl . ' - '.$result);
Expand Down
14 changes: 9 additions & 5 deletions src/addons/mod/assign/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ Feature: Test basic usage of assignment activity in app
Then I should find "No attempt" in the app

Scenario: Add submission offline (online text) & Submit for grading offline & Sync submissions
Given I entered the assign activity "assignment1" on course "Course 1" as "student1" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "assignment1" in the app
When I press "Add submission" in the app
And I switch network connection to offline
And I set the field "Online text submissions" to "Submission test" in the app
Expand All @@ -150,7 +151,8 @@ Feature: Test basic usage of assignment activity in app
But I should not find "This Assignment has offline data to be synchronised." in the app

Scenario: Edit an offline submission before synchronising it
Given I entered the assign activity "assignment1" on course "Course 1" as "student1" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "assignment1" in the app
When I press "Add submission" in the app
And I switch network connection to offline
And I set the field "Online text submissions" to "Submission test original offline" in the app
Expand Down Expand Up @@ -178,8 +180,9 @@ Feature: Test basic usage of assignment activity in app

@lms_from4.5
Scenario: Remove submission offline and syncrhonize it
Given I entered the assign activity "assignment1" on course "Course 1" as "student1" in the app
And I press "Add submission" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "assignment1" in the app
When I press "Add submission" in the app
And I set the field "Online text submissions" to "Submission test" in the app
And I press "Save" in the app
Then I should find "Draft (not submitted)" in the app
Expand Down Expand Up @@ -223,7 +226,8 @@ Feature: Test basic usage of assignment activity in app

@lms_from4.5
Scenario: Add submission offline after removing a submission offline
Given I entered the assign activity "assignment1" on course "Course 1" as "student1" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "assignment1" in the app
When I press "Add submission" in the app
And I set the field "Online text submissions" to "Submission test online" in the app
And I press "Save" in the app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Feature: Test basic usage of BBB activity in app
| bigbluebuttonbn | BBB 1 | Test BBB description | C1 | bbb1 | 0 | ## 1 January 2050 00:00 ## | 0 |
| bigbluebuttonbn | BBB 2 | Test BBB description | C1 | bbb2 | 0 | 0 | ## 1 January 2000 00:00 ## |
| bigbluebuttonbn | BBB 3 | Test BBB description | C1 | bbb3 | 0 | ## 1 January 2000 00:00 ## | ## 1 January 2050 00:00 ## |
And I entered the bigbluebuttonbn activity "BBB 1" on course "Course 1" as "student1" in the app
And I entered the course "Course 1" as "student1" in the app
And I press "BBB 1" in the app
Then I should find "The session has not started yet." in the app
And I should find "Saturday, 1 January 2050, 12:00 AM" within "Open" "ion-item" in the app

Expand Down Expand Up @@ -107,7 +108,8 @@ Feature: Test basic usage of BBB activity in app
| bigbluebuttonbn | Room & recordings | C1 | bbb1 | 0 |
| bigbluebuttonbn | Room only | C1 | bbb2 | 1 |
| bigbluebuttonbn | Recordings only | C1 | bbb3 | 2 |
And I entered the bigbluebuttonbn activity "Room & recordings" on course "Course 1" as "student1" in the app
And I entered the course "Course 1" as "student1" in the app
And I press "Room & recordings" in the app
Then I should find "This room is ready. You can join the session now." in the app
And I should be able to press "Join session" in the app
And I should find "Recordings" in the app
Expand Down
6 changes: 4 additions & 2 deletions src/addons/mod/choice/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Feature: Test basic usage of choice activity in app
Given the following "activities" exist:
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
| choice | Test single choice name | Test single choice description | C1 | choice1 | Option 1, Option 2, Option 3 | 0 | 0 | 1 |
And I entered the choice activity "Test single choice name" on course "Course 1" as "student1" in the app
And I entered the course "Course 1" as "student1" in the app
And I press "Test single choice name" in the app
When I select "Option 1" in the app
And I select "Option 2" in the app
And I press "Save my choice" in the app
Expand Down Expand Up @@ -74,7 +75,8 @@ Feature: Test basic usage of choice activity in app
Given the following "activities" exist:
| activity | name | intro | course | idnumber | option | allowmultiple | allowupdate | showresults |
| choice | Test single choice name | Test single choice description | C1 | choice1 | Option 1, Option 2, Option 3 | 0 | 0 | 1 |
And I entered the choice activity "Test single choice name" on course "Course 1" as "student1" in the app
And I entered the course "Course 1" as "student1" in the app
And I press "Test single choice name" in the app
When I select "Option 1" in the app
And I switch network connection to offline
And I select "Option 2" in the app
Expand Down
71 changes: 43 additions & 28 deletions src/addons/mod/data/tests/behat/sync.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ Feature: Users can store entries in database activities when offline and sync wh
| data1 | text | Description | Link description |

Scenario: Create entry (offline)
Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "Web links" in the app
And I switch network connection to offline
And I should find "No entries yet" in the app
Then I should find "No entries yet" in the app

When I press "Add entry" in the app
And I set the following fields to these values in the app:
| URL | https://moodle.org/ |
Expand All @@ -39,29 +41,33 @@ Feature: Users can store entries in database activities when offline and sync wh
Then I should find "https://moodle.org/" in the app
And I should find "Moodle community site" in the app
And I should find "This Database has offline data to be synchronised" in the app
And I go back in the app

When I go back in the app
And I switch network connection to wifi
And I press "Web links" near "General" in the app
And I should find "https://moodle.org/" in the app
Then I should find "https://moodle.org/" in the app
And I should find "Moodle community site" in the app
And I should not find "This Database has offline data to be synchronised" in the app

Scenario: Update entry (offline) & Delete entry (offline)
Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app
And I should find "No entries yet" in the app
And I press "Add entry" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "Web links" in the app
Then I should find "No entries yet" in the app

When I press "Add entry" in the app
And I set the following fields to these values in the app:
| URL | https://moodle.org/ |
| Description | Moodle community site |
And I press "Save" near "Web links" in the app
And I should find "https://moodle.org/" in the app
Then I should find "https://moodle.org/" in the app
And I should find "Moodle community site" in the app
And I press "Information" in the app

When I press "Information" in the app
And I press "Download" in the app
And I wait until the page is ready
And I close the popup in the app
And I switch network connection to offline
When I press "Actions menu" in the app
And I press "Actions menu" in the app
And I press "Edit" in the app
And I set the following fields to these values in the app:
| URL | https://moodlecloud.com/ |
Expand All @@ -72,55 +78,64 @@ Feature: Users can store entries in database activities when offline and sync wh
And I should find "https://moodlecloud.com/" in the app
And I should find "Moodle Cloud" in the app
And I should find "This Database has offline data to be synchronised" in the app
And I go back in the app

When I go back in the app
And I switch network connection to wifi
And I press "Web links" near "General" in the app
And I should not find "https://moodle.org/" in the app
Then I should not find "https://moodle.org/" in the app
And I should not find "Moodle community site" in the app
And I should find "https://moodlecloud.com/" in the app
And I should find "Moodle Cloud" in the app
And I should not find "This Database has offline data to be synchronised" in the app
And I press "Information" in the app

When I press "Information" in the app
And I press "Refresh" in the app
And I wait until the page is ready
And I switch network connection to offline
And I press "Actions menu" in the app
And I press "Delete" in the app
And I should find "Are you sure you want to delete this entry?" in the app
And I press "Delete" in the app
And I should find "https://moodlecloud.com/" in the app
Then I should find "Are you sure you want to delete this entry?" in the app

When I press "Delete" in the app
Then I should find "https://moodlecloud.com/" in the app
And I should find "Moodle Cloud" in the app
And I should find "This Database has offline data to be synchronised" in the app
And I go back in the app

When I go back in the app
And I switch network connection to wifi
And I press "Web links" near "General" in the app
And I should not find "https://moodlecloud.com/" in the app
Then I should not find "https://moodlecloud.com/" in the app
And I should not find "Moodle Cloud" in the app
And I should not find "This Database has offline data to be synchronised" in the app

Scenario: Students can undo deleting entries to a database in the app while offline
Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app
And I should find "No entries yet" in the app
And I press "Add entry" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "Web links" in the app
Then I should find "No entries yet" in the app

When I press "Add entry" in the app
And I set the following fields to these values in the app:
| URL | https://moodle.org/ |
| Description | Moodle community site |
And I press "Save" near "Web links" in the app
And I should find "https://moodle.org/" in the app
Then I should find "https://moodle.org/" in the app
And I should find "Moodle community site" in the app
And I press "Information" in the app

When I press "Information" in the app
And I press "Download" in the app
And I wait until the page is ready
And I close the popup in the app
When I switch network connection to offline
And I switch network connection to offline
And I press "Actions menu" in the app
And I press "Delete" in the app
And I should find "Are you sure you want to delete this entry?" in the app
And I press "Delete" in the app
And I should find "https://moodle.org/" in the app
Then I should find "Are you sure you want to delete this entry?" in the app

When I press "Delete" in the app
Then I should find "https://moodle.org/" in the app
And I should find "Moodle community site" in the app
And I should find "This Database has offline data to be synchronised" in the app
And I press "Actions menu" in the app

When I press "Actions menu" in the app
And I press "Restore" in the app
And I go back in the app
And I switch network connection to wifi
Expand Down
3 changes: 2 additions & 1 deletion src/addons/mod/forum/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ Feature: Test basic usage of forum activity in app
But I should not find "Not sent" in the app

Scenario: New discussion offline & Sync Forum
Given I entered the forum activity "Test forum name" on course "Course 1" as "student1" in the app
Given I entered the course "Course 1" as "student1" in the app
And I press "Test forum name" in the app
When I switch network connection to offline
And I press "Add discussion topic" in the app
And I set the following fields to these values in the app:
Expand Down
Loading