Merge branch 'MDL-77462_401' of https://github.com/timhunt/moodle into MOODLE_401_STABLE

This commit is contained in:
Andrew Nicols 2023-03-05 22:12:35 +08:00
commit 91ae0abd0a
2 changed files with 4 additions and 3 deletions

View File

@ -1982,7 +1982,7 @@ function core_question_find_next_unused_idnumber(?string $oldidnumber, int $cate
global $DB;
// The the old idnumber is not of the right form, bail now.
if (!preg_match('~\d+$~', $oldidnumber, $matches)) {
if ($oldidnumber === null || !preg_match('~\d+$~', $oldidnumber, $matches)) {
return null;
}

View File

@ -1998,6 +1998,7 @@ class questionlib_test extends \advanced_testcase {
*/
public function find_next_unused_idnumber_cases(): array {
return [
[null, null],
['id', null],
['id1a', null],
['id001', 'id002'],
@ -2020,10 +2021,10 @@ class questionlib_test extends \advanced_testcase {
* Test core_question_find_next_unused_idnumber in the case when there are no other questions.
*
* @dataProvider find_next_unused_idnumber_cases
* @param string $oldidnumber value to pass to core_question_find_next_unused_idnumber.
* @param string|null $oldidnumber value to pass to core_question_find_next_unused_idnumber.
* @param string|null $expectednewidnumber expected result.
*/
public function test_core_question_find_next_unused_idnumber(string $oldidnumber, ?string $expectednewidnumber) {
public function test_core_question_find_next_unused_idnumber(?string $oldidnumber, ?string $expectednewidnumber) {
$this->assertSame($expectednewidnumber, core_question_find_next_unused_idnumber($oldidnumber, 0));
}