Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 24... Línea 24...
24
 * @package    tool_moodlenet
24
 * @package    tool_moodlenet
25
 * @category   test
25
 * @category   test
26
 * @copyright  2020 Jake Dallimore <jrhdallimore@gmail.com>
26
 * @copyright  2020 Jake Dallimore <jrhdallimore@gmail.com>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
28
 */
29
class url_test extends \advanced_testcase {
29
final class url_test extends \advanced_testcase {
Línea 30... Línea 30...
30
 
30
 
31
    /**
31
    /**
32
     * Test the parsing to host + path components.
32
     * Test the parsing to host + path components.
33
     *
33
     *
34
     * @dataProvider url_provider
34
     * @dataProvider url_provider
35
     * @param string $urlstring The full URL string
35
     * @param string $url The full URL string
36
     * @param string $host the expected host component of the URL.
36
     * @param string $host the expected host component of the URL.
37
     * @param string $path the expected path component of the URL.
37
     * @param string $path the expected path component of the URL.
38
     * @param bool $exception whether or not an exception is expected during construction.
38
     * @param bool $exception whether or not an exception is expected during construction.
39
     */
39
     */
Línea 53... Línea 53...
53
    /**
53
    /**
54
     * Data provider.
54
     * Data provider.
55
     *
55
     *
56
     * @return array
56
     * @return array
57
     */
57
     */
58
    public function url_provider() {
58
    public static function url_provider(): array {
59
        return [
59
        return [
60
            'No path' => [
60
            'No path' => [
61
                'url' => 'https://example.moodle.net',
61
                'urlstring' => 'https://example.moodle.net',
62
                'host' => 'example.moodle.net',
62
                'host' => 'example.moodle.net',
63
                'path' => null,
63
                'path' => null,
64
                'exception' => false,
64
                'exception' => false,
65
            ],
65
            ],
66
            'Slash path' => [
66
            'Slash path' => [
67
                'url' => 'https://example.moodle.net/',
67
                'urlstring' => 'https://example.moodle.net/',
68
                'host' => 'example.moodle.net',
68
                'host' => 'example.moodle.net',
69
                'path' => '/',
69
                'path' => '/',
70
                'exception' => false,
70
                'exception' => false,
71
            ],
71
            ],
72
            'Path includes file and extension' => [
72
            'Path includes file and extension' => [
73
                'url' => 'https://example.moodle.net/uploads/123456789/pic.png',
73
                'urlstring' => 'https://example.moodle.net/uploads/123456789/pic.png',
74
                'host' => 'example.moodle.net',
74
                'host' => 'example.moodle.net',
75
                'path' => '/uploads/123456789/pic.png',
75
                'path' => '/uploads/123456789/pic.png',
76
                'exception' => false,
76
                'exception' => false,
77
            ],
77
            ],
78
            'Path includes file, extension and params' => [
78
            'Path includes file, extension and params' => [
79
                'url' => 'https://example.moodle.net/uploads/123456789/pic.png?option=1&option2=test',
79
                'urlstring' => 'https://example.moodle.net/uploads/123456789/pic.png?option=1&option2=test',
80
                'host' => 'example.moodle.net',
80
                'host' => 'example.moodle.net',
81
                'path' => '/uploads/123456789/pic.png',
81
                'path' => '/uploads/123456789/pic.png',
82
                'exception' => false,
82
                'exception' => false,
83
            ],
83
            ],
84
            'Malformed - invalid' => [
84
            'Malformed - invalid' => [
85
                'url' => 'invalid',
85
                'urlstring' => 'invalid',
86
                'host' => null,
86
                'host' => null,
87
                'path' => null,
87
                'path' => null,
88
                'exception' => true,
88
                'exception' => true,
89
            ],
89
            ],
90
            'Direct, non-encoded utf8 - invalid' => [
90
            'Direct, non-encoded utf8 - invalid' => [
91
                'url' => 'http://москва.рф/services/',
91
                'urlstring' => 'http://москва.рф/services/',
92
                'host' => 'москва.рф',
92
                'host' => 'москва.рф',
93
                'path' => '/services/',
93
                'path' => '/services/',
94
                'exception' => true,
94
                'exception' => true,
95
            ],
95
            ],
96
        ];
96
        ];