MDL-78782 behat: optimize with editing mode step

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.
This commit is contained in:
Ferran Recio 2023-07-21 10:17:11 +02:00
parent 533ce56743
commit dcd7261175
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);
// 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

@ -941,22 +941,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]);
}
/**