Merge branch 'MDL-78782-master' of https://github.com/ferranrecio/moodle

This commit is contained in:
Ilya Tregubov 2023-07-27 09:58:25 +08:00 committed by Jun Pataleta
commit 70174bb754
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 19 additions and 16 deletions

View File

@ -28,7 +28,12 @@ $setmode = optional_param('setmode', false, PARAM_BOOL);
$contextid = required_param('context', PARAM_INT);
$pageurl = required_param('pageurl', PARAM_LOCALURL);
require_sesskey();
// Behat requires JS to get the session. To allow goutte
// to enable edit mode sesskey validation is skipped for behat scripts.
if (!defined('BEHAT_SITE_RUNNING')) {
require_sesskey();
}
require_login();
$context = \context_helper::instance_by_id($contextid);

View File

@ -970,22 +970,20 @@ class behat_navigation extends behat_base {
* @param string $onoroff Whehter to switch editing on, or off.
*/
public function i_am_on_course_homepage_with_editing_mode_set_to(string $coursefullname, string $onoroff): void {
$courseid = $this->get_course_id($coursefullname);
$url = new moodle_url('/course/view.php', ['id' => $courseid]);
// Visit the course page.
$this->execute('behat_general::i_visit', [$url]);
switch ($onoroff) {
case 'on':
$this->execute('behat_navigation::i_turn_editing_mode_on');
break;
case 'off':
$this->execute('behat_navigation::i_turn_editing_mode_off');
break;
default:
throw new \coding_exception("Unknown editing mode '{$onoroff}'. Accepted values are 'on' and 'off'");
if ($onoroff !== 'on' && $onoroff !== 'off') {
throw new coding_exception("Unknown editing mode '{$onoroff}'. Accepted values are 'on' and 'off'");
}
$courseid = $this->get_course_id($coursefullname);
$context = context_course::instance($courseid);
$courseurl = new moodle_url('/course/view.php', ['id' => $courseid]);
$editmodeurl = new moodle_url('/editmode.php', [
'context' => $context->id,
'pageurl' => $courseurl->out(true),
'setmode' => ($onoroff === 'on' ? 1 : 0),
]);
$this->execute('behat_general::i_visit', [$editmodeurl]);
}
/**