diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index f780b84157a02..534dd7ca75fae 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -204,7 +204,7 @@ } $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 64331b4fa36f5..2a23a413e24bf 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 983cb19759eb4..afa7396be7f98 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 5913f13bf4e3f..e4233acf338cb 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -99,6 +99,26 @@ public function i_am_on_course_index() { $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. *