MDL-86760 course: observe maximum size of activity name with renaming.

This commit is contained in:
Paul Holden
2025-09-29 20:30:12 +01:00
parent a828ba12c1
commit 2e8f42ee28
2 changed files with 13 additions and 5 deletions
@@ -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.
@@ -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,
],