diff --git a/grade/report/grader/index.php b/grade/report/grader/index.php index b884c72084f..cbbb94a5639 100644 --- a/grade/report/grader/index.php +++ b/grade/report/grader/index.php @@ -203,7 +203,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 fa392d06b67..ea7e002a606 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. * diff --git a/lib/upgrade.txt b/lib/upgrade.txt index db783d571c1..7eb4f38d3ca 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -20,6 +20,11 @@ method normalizes a string containing a series of Internet addresses. * The method `count_modules_completed` now delegate the logic to count the completed modules to the DBMS improving the performance of the method. +* 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]+"` + === 4.4.5 === * All uses of the following PHPUnit methods have been removed as these methods are deprecated upstream without direct replacement: