Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
declare(strict_types=1);
18
 
19
namespace core_sms\external;
20
 
21
defined('MOODLE_INTERNAL') || die();
22
 
23
global $CFG;
24
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
25
 
26
/**
27
 * Test the webservice to change the status of a gateway.
28
 *
29
 * @package    core_sms
30
 * @copyright  2024 Safat Shahin <safat.shahin@moodle.com>
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @covers     \core_sms\external\sms_gateway_status::execute
33
 */
34
final class sms_gateway_status_test extends \externallib_advanced_testcase {
35
 
36
    public function test_execute(): void {
37
        $this->resetAfterTest();
38
        $this->setAdminUser();
39
 
40
        $config = (object) [
41
            'data' => 'goeshere',
42
        ];
43
        $dummy = $this->getMockBuilder(\core_sms\gateway::class)
44
            ->setConstructorArgs([
45
                'enabled' => true,
46
                'name' => 'dummy',
47
                'config' => json_encode($config),
48
            ])
49
            ->onlyMethods(['get_send_priority', 'send'])
50
            ->getMock();
51
        $dummygw = get_class($dummy);
52
 
53
        $manager = \core\di::get(\core_sms\manager::class);
54
        $gateway = $manager->create_gateway_instance(
55
            classname: $dummygw,
56
            name: 'dummy',
57
            enabled: true,
58
            config: $config,
59
        );
60
 
61
        // Now let's disable the gateway.
62
        sms_gateway_status::execute(
63
            plugin: $gateway->id,
64
            state: 0,
65
        );
66
        $gatewaymanagers = $manager->get_gateway_instances(
67
            filter: ['id' => $gateway->id],
68
        );
69
        $gatewaymanager = reset($gatewaymanagers);
70
        $this->assertFalse($gatewaymanager->enabled);
71
 
72
        // Let's enable again.
73
        sms_gateway_status::execute(
74
            plugin: $gateway->id,
75
            state: 1,
76
        );
77
        $gatewaymanagers = $manager->get_gateway_instances(
78
            filter: ['id' => $gateway->id],
79
        );
80
        $gatewaymanager = reset($gatewaymanagers);
81
        $this->assertTrue($gatewaymanager->enabled);
82
    }
83
}