From 1bb6231b323c550386db5d33478181ebbb5b98a6 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Fri, 1 May 2020 10:49:32 +0800 Subject: [PATCH] MDL-67813 core_contentbank: Add content name parameter in the generator --- contentbank/tests/generator/lib.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contentbank/tests/generator/lib.php b/contentbank/tests/generator/lib.php index 8bb9ae04f56..4d7e0228cae 100644 --- a/contentbank/tests/generator/lib.php +++ b/contentbank/tests/generator/lib.php @@ -45,10 +45,12 @@ class core_contentbank_generator extends \component_generator_base { * @param context $context The context where the content will be created. * @param bool $convert2class Whether the class should return stdClass or plugin instance. * @param string $filepath The filepath of the file associated to the content to create. + * @param string $contentname The name of the content that will be created. * @return array An array with all the records added to the content bank. */ public function generate_contentbank_data(?string $contenttype, int $itemstocreate = 1, int $userid = 0, - ?\context $context = null, bool $convert2class = true, string $filepath = 'contentfile.h5p'): array { + ?\context $context = null, bool $convert2class = true, string $filepath = 'contentfile.h5p', + string $contentname = 'Test content '): array { global $DB, $USER; $records = []; @@ -67,7 +69,8 @@ class core_contentbank_generator extends \component_generator_base { for ($i = 0; $i < $itemstocreate; $i++) { // Create content. $record = new stdClass(); - $record->name = 'Test content ' . $i; + // If only 1 item is being created, do not add a number suffix to the content name. + $record->name = ($itemstocreate === 1) ? $contentname : $contentname . $i; $record->configdata = ''; $record->usercreated = $userid ?? $USER->id;