Skip to content

Commit ce100cf

Browse files
committed
Add short descriptions to data generators
1 parent fc68f78 commit ce100cf

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

tests/generator/lib.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public function create_section($record = null): stdClass {
6262
if (!isset($record->name)) {
6363
$record->name = 'Section ' . $this->sectioncount;
6464
}
65+
if (trim($record->shortdescription ?? '') === '') {
66+
$record->shortdescription = 'Description of section ' . $record->name;
67+
}
6568

6669
return section::create($record);
6770
}
@@ -112,6 +115,9 @@ public function create_collection($record = null): stdClass {
112115
if (!isset($record->name)) {
113116
$record->name = 'Collection ' . $this->collectioncount;
114117
}
118+
if (trim($record->shortdescription ?? '') === '') {
119+
$record->shortdescription = 'Description of collection ' . $record->name;
120+
}
115121

116122
return collection::create($record);
117123
}

tests/phpunit/generator_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function test_create_section(): void {
5555
$this->setCurrentTimeStart();
5656
$section = $generator->create_section();
5757
$this->assertSame('Section 1', $section->name);
58+
$this->assertSame('Description of section Section 1', $section->shortdescription);
5859
$this->assertSame((string)$syscontext->id, $section->contextid);
5960
$this->assertSame(null, $section->frontpagepriority);
6061
$this->assertSame((string)util::STATUS_ACTIVE, $section->status);
@@ -70,6 +71,7 @@ public function test_create_section(): void {
7071

7172
$section = $generator->create_section([
7273
'name' => 'Some section',
74+
'shortdescription' => 'Some desc',
7375
'contextid' => $categorycontext->id,
7476
'frontpagepriority' => '777',
7577
'status' => util::STATUS_DRAFT,
@@ -78,6 +80,7 @@ public function test_create_section(): void {
7880
'cohortvisible' => [$cohort1->id, $cohort2->id],
7981
]);
8082
$this->assertSame('Some section', $section->name);
83+
$this->assertSame('Some desc', $section->shortdescription);
8184
$this->assertSame('777', $section->frontpagepriority);
8285
$this->assertSame((string)util::STATUS_DRAFT, $section->status);
8386
$this->assertSame('1', $section->guestvisible);
@@ -183,6 +186,7 @@ public function test_create_collection(): void {
183186
$this->setCurrentTimeStart();
184187
$collection = $generator->create_collection();
185188
$this->assertSame('Collection 1', $collection->name);
189+
$this->assertSame('Description of collection Collection 1', $collection->shortdescription);
186190
$this->assertSame((string)$syscontext->id, $collection->contextid);
187191
$this->assertSame(null, $collection->frontpagepriority);
188192
$this->assertSame('0', $collection->guestvisible);
@@ -197,13 +201,15 @@ public function test_create_collection(): void {
197201

198202
$collection = $generator->create_collection([
199203
'name' => 'Some collection',
204+
'shortdescription' => 'Some desc',
200205
'contextid' => $categorycontext->id,
201206
'frontpagepriority' => '777',
202207
'guestvisible' => 1,
203208
'uservisible' => 0,
204209
'cohortvisible' => [$cohort1->id, $cohort2->id],
205210
]);
206211
$this->assertSame('Some collection', $collection->name);
212+
$this->assertSame('Some desc', $collection->shortdescription);
207213
$this->assertSame('777', $collection->frontpagepriority);
208214
$this->assertSame('1', $collection->guestvisible);
209215
$this->assertSame('0', $collection->uservisible);

0 commit comments

Comments
 (0)