1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace communication_matrix; 18 19 /** 20 * Tests for the matrix_room class. 21 * 22 * @package communication_matrix 23 * @category test 24 * @copyright 2023 Safat Shahin <safat.shahin@moodle.com> 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 * @coversDefaultClass \communication_matrix\matrix_room 27 */ 28 class matrix_room_test extends \advanced_testcase { 29 /** 30 * Test for load_by_processor_id with no record. 31 * 32 * @covers ::load_by_processor_id 33 */ 34 public function test_load_by_processor_id_none(): void { 35 $this->assertNull(matrix_room::load_by_processor_id(999999999)); 36 } 37 38 /** 39 * Test for load_by_processor_id with valid records. 40 * 41 * @covers ::create_room_record 42 * @covers ::__construct 43 * @covers ::load_by_processor_id 44 * @covers ::get_processor_id 45 * @covers ::get_room_id 46 * @covers ::get_topic 47 */ 48 public function test_create_room_record(): void { 49 $this->resetAfterTest(); 50 51 $room = matrix_room::create_room_record( 52 processorid: 10000, 53 topic: null, 54 ); 55 $this->assertInstanceOf(matrix_room::class, $room); 56 $this->assertEquals(10000, $room->get_processor_id()); 57 $this->assertNotNull('', $room->get_topic()); 58 $this->assertEquals('', $room->get_topic()); 59 $this->assertNull($room->get_room_id()); 60 61 $room = matrix_room::create_room_record( 62 processorid: 12345, 63 topic: 'The topic of this room is thusly', 64 ); 65 66 $this->assertInstanceOf(matrix_room::class, $room); 67 $this->assertEquals(12345, $room->get_processor_id()); 68 $this->assertEquals('The topic of this room is thusly', $room->get_topic()); 69 $this->assertNull($room->get_room_id()); 70 71 $room = matrix_room::create_room_record( 72 processorid: 54321, 73 topic: 'The topic of this room is thusly', 74 roomid: 'This is a roomid', 75 ); 76 77 $this->assertInstanceOf(matrix_room::class, $room); 78 $this->assertEquals(54321, $room->get_processor_id()); 79 $this->assertEquals('The topic of this room is thusly', $room->get_topic()); 80 $this->assertEquals('This is a roomid', $room->get_room_id()); 81 82 $reloadedroom = matrix_room::load_by_processor_id(54321); 83 $this->assertEquals(54321, $reloadedroom->get_processor_id()); 84 $this->assertEquals('The topic of this room is thusly', $reloadedroom->get_topic()); 85 $this->assertEquals('This is a roomid', $reloadedroom->get_room_id()); 86 } 87 88 /** 89 * Test for update_room_record. 90 * 91 * @covers ::update_room_record 92 */ 93 public function test_update_room_record(): void { 94 $this->resetAfterTest(); 95 96 $room = matrix_room::create_room_record( 97 processorid: 12345, 98 topic: 'The topic of this room is that', 99 ); 100 101 // Add a roomid. 102 $room->update_room_record( 103 roomid: 'This is a roomid', 104 ); 105 106 $this->assertEquals('This is a roomid', $room->get_room_id()); 107 $this->assertEquals('The topic of this room is that', $room->get_topic()); 108 $this->assertEquals(12345, $room->get_processor_id()); 109 110 // Alter the roomid and topic. 111 $room->update_room_record( 112 roomid: 'updatedRoomId', 113 topic: 'updatedTopic is here', 114 ); 115 116 $this->assertEquals('updatedRoomId', $room->get_room_id()); 117 $this->assertEquals('updatedTopic is here', $room->get_topic()); 118 $this->assertEquals(12345, $room->get_processor_id()); 119 } 120 121 /** 122 * Tests for delete_room_record. 123 * 124 * @covers ::delete_room_record 125 */ 126 public function test_delete_room_record(): void { 127 global $DB; 128 129 $this->resetAfterTest(); 130 131 $room = matrix_room::create_room_record( 132 processorid: 12345, 133 topic: 'The topic of this room is that', 134 ); 135 $this->assertCount(1, $DB->get_records('matrix_room')); 136 137 $room->delete_room_record(); 138 $this->assertCount(0, $DB->get_records('matrix_room')); 139 } 140 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body