1441 |
ariadna |
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 core_sms;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Tests for sms gateway.
|
|
|
21 |
*
|
|
|
22 |
* @package core_sms
|
|
|
23 |
* @category test
|
|
|
24 |
* @copyright 2024 Andrew Lyons <andrew@nicols.co.uk>
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
* @covers \core_sms\gateway
|
|
|
27 |
*/
|
|
|
28 |
final class gateway_test extends \advanced_testcase {
|
|
|
29 |
public static function setUpBeforeClass(): void {
|
|
|
30 |
require_once(__DIR__ . "/fixtures/dummy_gateway.php");
|
|
|
31 |
parent::setUpBeforeClass();
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function test_update_message_status(): void {
|
|
|
35 |
$this->resetAfterTest();
|
|
|
36 |
|
|
|
37 |
$manager = \core\di::get(\core_sms\manager::class);
|
|
|
38 |
$config = new \stdClass();
|
|
|
39 |
$config->api_key = 'test_api_key';
|
|
|
40 |
|
|
|
41 |
$gw = $manager->create_gateway_instance(
|
|
|
42 |
classname: \smsgateway_dummy\gateway::class,
|
|
|
43 |
name: 'dummy',
|
|
|
44 |
enabled: true,
|
|
|
45 |
config: $config,
|
|
|
46 |
);
|
|
|
47 |
$othergw = $manager->create_gateway_instance(
|
|
|
48 |
classname: \smsgateway_dummy\gateway::class,
|
|
|
49 |
name: 'dummy',
|
|
|
50 |
enabled: true,
|
|
|
51 |
config: $config,
|
|
|
52 |
);
|
|
|
53 |
|
|
|
54 |
$message = new message(
|
|
|
55 |
recipientnumber: '1234567890',
|
|
|
56 |
content: 'Hello, world!',
|
|
|
57 |
component: 'core',
|
|
|
58 |
messagetype: 'test',
|
|
|
59 |
recipientuserid: null,
|
|
|
60 |
issensitive: false,
|
|
|
61 |
gatewayid: $gw->id,
|
|
|
62 |
);
|
|
|
63 |
$message2 = new message(
|
|
|
64 |
recipientnumber: '1234567890',
|
|
|
65 |
content: 'Hello, world!',
|
|
|
66 |
component: 'core',
|
|
|
67 |
messagetype: 'test',
|
|
|
68 |
recipientuserid: null,
|
|
|
69 |
issensitive: false,
|
|
|
70 |
gatewayid: $gw->id,
|
|
|
71 |
);
|
|
|
72 |
|
|
|
73 |
$updatedmessage = $gw->update_message_status($message);
|
|
|
74 |
$this->assertEquals($message, $updatedmessage);
|
|
|
75 |
|
|
|
76 |
$updatedmessages = $gw->update_message_statuses([$message, $message2]);
|
|
|
77 |
$this->assertEquals([$message, $message2], $updatedmessages);
|
|
|
78 |
|
|
|
79 |
$this->expectException(\coding_exception::class);
|
|
|
80 |
$othergw->update_message_status($message);
|
|
|
81 |
}
|
|
|
82 |
}
|