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
namespace smsgateway_aws;
18
 
19
/**
20
 * AWS SMS gateway helper tests.
21
 *
22
 * @package    smsgateway_aws
23
 * @category   test
24
 * @copyright  2024 Safat Shahin <safat.shahin@moodle.com>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @covers     \smsgateway_aws\helper
27
 */
28
final class helper_test extends \advanced_testcase {
29
 
30
    /**
31
     * Data provider for test_format_number().
32
     *
33
     * @return array of different country codes and phone numbers.
34
     */
35
    public static function format_number_provider(): array {
36
 
37
        return [
38
            'Phone number with local format' => [
39
                'phonenumber' => '0123456789',
40
                'expected' => '+34123456789',
41
                'countrycode' => '34',
42
            ],
43
            'Phone number with international format' => [
44
                'phonenumber' => '+39123456789',
45
                'expected' => '+39123456789',
46
            ],
47
            'Phone number with spaces using international format' => [
48
                'phonenumber' => '+34 123 456 789',
49
                'expected' => '+34123456789',
50
            ],
51
            'Phone number with spaces using local format with country code' => [
52
                'phonenumber' => '0 123 456 789',
53
                'expected' => '+34123456789',
54
                'countrycode' => '34',
55
            ],
56
            'Phone number with spaces using local format without country code' => [
57
                'phonenumber' => '0 123 456 789',
58
                'expected' => '123456789',
59
            ],
60
        ];
61
    }
62
 
63
    /**
64
     * Test format number with different phones and different country codes.
65
     *
66
     * @dataProvider format_number_provider
67
     * @param string $phonenumber Phone number.
68
     * @param string $expected Expected value.
69
     * @param string|null $countrycode Country code.
70
     */
71
    public function test_format_number(
72
        string $phonenumber,
73
        string $expected,
74
        ?string $countrycode = null,
75
    ): void {
76
        $this->resetAfterTest();
77
        $this->assertEquals($expected, \core_sms\manager::format_number($phonenumber, $countrycode));
78
    }
79
 
80
    /**
81
     * Test the proxy strings.
82
     */
83
    public function test_get_proxy_string(): void {
84
        global $CFG;
85
        $this->resetAfterTest();
86
        // Confirm with no config an empty string is returned.
87
        $CFG->proxyhost = '';
88
        $this->assertEquals('', helper::get_proxy_string());
89
 
90
        // Now set some configs.
91
        $CFG->proxyhost = '127.0.0.1';
92
        $CFG->proxyuser = 'user';
93
        $CFG->proxypassword = 'password';
94
        $CFG->proxyport = '1337';
95
        $this->assertEquals('user:password@127.0.0.1:1337', helper::get_proxy_string());
96
 
97
        // Now change to SOCKS proxy.
98
        $CFG->proxytype = 'SOCKS5';
99
        $this->assertEquals('socks5://user:password@127.0.0.1:1337', helper::get_proxy_string());
100
    }
101
}