MOBILE-3320 behat: Test activity deep links
parent
561206b785
commit
dd7db580e7
|
@ -532,6 +532,24 @@ class behat_app extends behat_base {
|
|||
$this->wait_for_pending_js();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace arguments from the content in the given activity field.
|
||||
*
|
||||
* @Given /^I replace the arguments in "([^"]+)" "([^"]+)"$/
|
||||
*/
|
||||
public function i_replace_arguments_in_the_activity(string $idnumber, string $field) {
|
||||
global $DB;
|
||||
|
||||
$coursemodule = $DB->get_record('course_modules', compact('idnumber'));
|
||||
$module = $DB->get_record('modules', ['id' => $coursemodule->module]);
|
||||
$activity = $DB->get_record($module->name, ['id' => $coursemodule->instance]);
|
||||
|
||||
$DB->update_record($module->name, [
|
||||
'id' => $coursemodule->instance,
|
||||
$field => $this->replace_arguments($activity->{$field}),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a custom link.
|
||||
*
|
||||
|
@ -889,4 +907,31 @@ class behat_app extends behat_base {
|
|||
return str_replace('$WWWROOT', $CFG->behat_wwwroot, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace arguments with the format "${activity:field}" from a string, where "activity" is
|
||||
* the idnumber of an activity and "field" is the activity's field to get replacement from.
|
||||
*
|
||||
* At the moment, the only field supported is "cmid", the id of the course module for this activity.
|
||||
*
|
||||
* @param string $text Original text.
|
||||
* @return string Text with arguments replaced.
|
||||
*/
|
||||
protected function replace_arguments(string $text): string {
|
||||
global $DB;
|
||||
|
||||
preg_match_all("/\\$\\{([^:}]+):([^}]+)\\}/", $text, $matches);
|
||||
|
||||
foreach ($matches[0] as $index => $match) {
|
||||
switch ($matches[2][$index]) {
|
||||
case 'cmid':
|
||||
$coursemodule = $DB->get_record('course_modules', ['idnumber' => $matches[1][$index]]);
|
||||
$text = str_replace($match, $coursemodule->id, $text);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
@app @javascript
|
||||
Feature: It navigates properly within activities.
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username |
|
||||
| student |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname |
|
||||
| Course 1 | C1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| student | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | idnumber | course | name | intro | content |
|
||||
| label | label | C1 | Label | Label description | - |
|
||||
| page | page | C1 | Page | - | <a href="/mod/label/view.php?id=${label:cmid}">Go to label</a> |
|
||||
And I replace the arguments in "page" "content"
|
||||
|
||||
Scenario: Navigates using deep links
|
||||
When I enter the app
|
||||
And I log in as "student"
|
||||
And I press "Course 1" in the app
|
||||
And I press "Page" in the app
|
||||
And I press "Go to label" in the app
|
||||
Then I should find "Label description" in the app
|
||||
|
||||
When I press the back button in the app
|
||||
Then I should find "Go to label" in the app
|
||||
|
||||
When I press the back button in the app
|
||||
Then I should find "Label description" in the app
|
Loading…
Reference in New Issue