MDL-77917 communication_matrix: Topic must not be null

The Matrix space/room topic must always be a string. We should normalise
this on the way out of the API.
This commit is contained in:
Andrew Nicols
2023-08-24 23:19:38 +08:00
parent 6d1bd4787f
commit d38c3dfc8e
2 changed files with 13 additions and 3 deletions
@@ -136,9 +136,9 @@ class matrix_rooms {
/**
* Get the matrix room topic.
*
* @return string|null
* @return string
*/
public function get_topic(): ?string {
return $this->record->topic;
public function get_topic(): string {
return $this->record->topic ?? '';
}
}
@@ -49,6 +49,16 @@ class matrix_rooms_test extends \advanced_testcase {
public function test_create_room_record(): void {
$this->resetAfterTest();
$room = matrix_rooms::create_room_record(
processorid: 10000,
topic: null,
);
$this->assertInstanceOf(matrix_rooms::class, $room);
$this->assertEquals(10000, $room->get_processor_id());
$this->assertNotNull('', $room->get_topic());
$this->assertEquals('', $room->get_topic());
$this->assertNull($room->get_room_id());
$room = matrix_rooms::create_room_record(
processorid: 12345,
topic: 'The topic of this room is thusly',