From d38c3dfc8eaed71eadec85748e253da96cdda90f Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 24 Aug 2023 23:13:35 +0800 Subject: [PATCH] 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. --- communication/provider/matrix/classes/matrix_rooms.php | 6 +++--- .../provider/matrix/tests/matrix_rooms_test.php | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/communication/provider/matrix/classes/matrix_rooms.php b/communication/provider/matrix/classes/matrix_rooms.php index 2a00f55128d..157351cd352 100644 --- a/communication/provider/matrix/classes/matrix_rooms.php +++ b/communication/provider/matrix/classes/matrix_rooms.php @@ -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 ?? ''; } } diff --git a/communication/provider/matrix/tests/matrix_rooms_test.php b/communication/provider/matrix/tests/matrix_rooms_test.php index f7f43c57bf1..7f9788252ba 100644 --- a/communication/provider/matrix/tests/matrix_rooms_test.php +++ b/communication/provider/matrix/tests/matrix_rooms_test.php @@ -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',