Skip to content

Commit

Permalink
MDL-78782 behat: optimize with editing mode step
Browse files Browse the repository at this point in the history
The current I am on course homepage with editing mode loads twice the
course page. This patch prevents this from happening by going directly
to editmode.php.
  • Loading branch information
ferranrecio committed Jul 26, 2023
1 parent e774522 commit 965d556
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
7 changes: 6 additions & 1 deletion editmode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
$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);
Expand Down
28 changes: 13 additions & 15 deletions lib/tests/behat/behat_navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,22 +970,20 @@ public function i_am_on_course_homepage_with_editing_mode_on($coursefullname) {
* @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]);
}

/**
Expand Down

0 comments on commit 965d556

Please sign in to comment.