diff --git a/public/course/format/classes/local/cmactions.php b/public/course/format/classes/local/cmactions.php index fe300b1008c..4458fa44384 100644 --- a/public/course/format/classes/local/cmactions.php +++ b/public/course/format/classes/local/cmactions.php @@ -16,9 +16,11 @@ namespace core_courseformat\local; - +use core\exception\moodle_exception; use core_courseformat\sectiondelegatemodule; +use core_text; use course_modinfo; + /** * Course module course format actions. * @@ -68,6 +70,7 @@ class cmactions extends baseactions { * @param int $cmid the course module id. * @param string $name the new name. * @return bool true if the course module was renamed, false otherwise. + * @throws moodle_exception If the name is too long */ public function rename(int $cmid, string $name): bool { global $CFG, $DB; @@ -79,8 +82,8 @@ class cmactions extends baseactions { if (empty($name)) { return false; } - if (\core_text::strlen($name) > 255) { - throw new \moodle_exception('maximumchars', 'moodle', '', 255); + if (core_text::strlen($name) > 1333) { + throw new moodle_exception('maximumchars', 'moodle', '', 1333); } // The name is stored in the activity instance record. diff --git a/public/course/format/tests/local/cmactions_test.php b/public/course/format/tests/local/cmactions_test.php index e7bc2847762..8d0a3a65377 100644 --- a/public/course/format/tests/local/cmactions_test.php +++ b/public/course/format/tests/local/cmactions_test.php @@ -65,7 +65,7 @@ final class cmactions_test extends \advanced_testcase { $cminfo = get_fast_modinfo($course)->get_cm($activity->cmid); if ($result) { - $this->assertEquals('New name', $cminfo->name); + $this->assertEquals($newname, $cminfo->name); } else { $this->assertEquals('Old name', $cminfo->name); } @@ -84,7 +84,12 @@ final class cmactions_test extends \advanced_testcase { 'expectexception' => false, ], 'Maximum length' => [ - 'newname' => str_repeat('a', 256), + 'newname' => str_repeat('a', 1333), + 'expected' => true, + 'expectexception' => false, + ], + 'Beyond maximum length' => [ + 'newname' => str_repeat('a', 1334), 'expected' => false, 'expectexception' => true, ],