diff --git a/.upgradenotes/MDL-83617-2025012010011285.yml b/.upgradenotes/MDL-83617-2025012010011285.yml new file mode 100644 index 00000000000..8202ccd2268 --- /dev/null +++ b/.upgradenotes/MDL-83617-2025012010011285.yml @@ -0,0 +1,10 @@ +issueNumber: MDL-83617 +notes: + tool_behat: + - message: > + New Behat step `\behat_general::the_url_should_match()` has been added + to allow checking the current URL. You can use it to check whether a + user has been redirected to the expected location. + + e.g. `And the url should match "/mod/forum/view\.php\?id=[0-9]+"` + type: improved diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index f780b84157a..534dd7ca75f 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -204,7 +204,7 @@ if ($numusers > $maxusers) { } $perpagedata = [ - 'baseurl' => new moodle_url('/grade/report/grader/index.php', ['id' => s($courseid), 'report' => 'grader']), + 'baseurl' => (new moodle_url('/grade/report/grader/index.php', ['id' => s($courseid), 'report' => 'grader']))->out(false), 'options' => [] ]; foreach ($pagingoptions as $key => $name) { diff --git a/grade/report/grader/templates/perpage.mustache b/grade/report/grader/templates/perpage.mustache index 64331b4fa36..2a23a413e24 100644 --- a/grade/report/grader/templates/perpage.mustache +++ b/grade/report/grader/templates/perpage.mustache @@ -43,7 +43,7 @@ {{#js}} document.getElementById('{{uniqid}}').addEventListener('change', function(e) { - var url = new URL('{{baseurl}}'); + var url = new URL('{{{baseurl}}}'); url.searchParams.set('perpage', e.target.value); window.location.href = url; diff --git a/grade/report/grader/tests/behat/pagination.feature b/grade/report/grader/tests/behat/pagination.feature index 983cb19759e..afa7396be7f 100644 --- a/grade/report/grader/tests/behat/pagination.feature +++ b/grade/report/grader/tests/behat/pagination.feature @@ -67,6 +67,7 @@ Feature: grader report pagination Then I should see "103" node occurrences of type "tr" in the "user-grades" "table" And I should see "2" in the ".stickyfooter .pagination" "css_element" And I should not see "3" in the ".stickyfooter .pagination" "css_element" + And the url should match "/grade/report/grader/index\.php\?id=[0-9]+&report=grader&perpage=100$" @javascript Scenario: The pagination bar is only displayed when there is more than one page diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index eee98d7c38f..35e04cc7499 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -99,6 +99,26 @@ class behat_general extends behat_base { $this->execute('behat_general::i_visit', ['/course/index.php']); } + /** + * Checks, that current page PATH matches regular expression + * + * Example: Then the url should match "/course/index\.php" + * Example: Then the url should match "/mod/forum/view\.php\?id=[0-9]+" + * Example: And the url should match "^http://moodle\.org" + * + * @Then /^the url should match (?P"(?:[^"]|\\")*")$/ + * @param string $pattern The pattern that must match to the current url. + */ + public function the_url_should_match($pattern) { + $url = $this->getSession()->getCurrentUrl(); + + if (preg_match($pattern, $url) === 1) { + return; + } + + throw new ExpectationException(sprintf('The url "%s" should match with %s', $url, $pattern), $this->getSession()); + } + /** * Reloads the current page. *