Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 28... Línea 28...
28
 */
28
 */
29
final class moodle_url_test extends \advanced_testcase {
29
final class moodle_url_test extends \advanced_testcase {
30
    /**
30
    /**
31
     * Test basic moodle_url construction.
31
     * Test basic moodle_url construction.
32
     */
32
     */
33
    public function test_moodle_url_constructor() {
33
    public function test_moodle_url_constructor(): void {
34
        global $CFG;
34
        global $CFG;
Línea 35... Línea 35...
35
 
35
 
36
        $url = new \moodle_url('/index.php');
36
        $url = new \moodle_url('/index.php');
Línea 57... Línea 57...
57
    }
57
    }
Línea 58... Línea 58...
58
 
58
 
59
    /**
59
    /**
60
     * Tests \moodle_url::get_path().
60
     * Tests \moodle_url::get_path().
61
     */
61
     */
62
    public function test_moodle_url_get_path() {
62
    public function test_moodle_url_get_path(): void {
63
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
63
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
Línea 64... Línea 64...
64
        $this->assertSame('/my/file/is/here.txt', $url->get_path());
64
        $this->assertSame('/my/file/is/here.txt', $url->get_path());
65
 
65
 
Línea 69... Línea 69...
69
        $url = new \moodle_url('http://www.example.org/pluginfile.php/slash/arguments');
69
        $url = new \moodle_url('http://www.example.org/pluginfile.php/slash/arguments');
70
        $this->assertSame('/pluginfile.php/slash/arguments', $url->get_path());
70
        $this->assertSame('/pluginfile.php/slash/arguments', $url->get_path());
71
        $this->assertSame('/pluginfile.php', $url->get_path(false));
71
        $this->assertSame('/pluginfile.php', $url->get_path(false));
72
    }
72
    }
Línea 73... Línea 73...
73
 
73
 
74
    public function test_moodle_url_round_trip() {
74
    public function test_moodle_url_round_trip(): void {
75
        $strurl = 'http://moodle.org/course/view.php?id=5';
75
        $strurl = 'http://moodle.org/course/view.php?id=5';
76
        $url = new \moodle_url($strurl);
76
        $url = new \moodle_url($strurl);
Línea 77... Línea 77...
77
        $this->assertSame($strurl, $url->out(false));
77
        $this->assertSame($strurl, $url->out(false));
Línea 82... Línea 82...
82
    }
82
    }
Línea 83... Línea 83...
83
 
83
 
84
    /**
84
    /**
85
     * Test Moodle URL objects created with a param with empty value.
85
     * Test Moodle URL objects created with a param with empty value.
86
     */
86
     */
87
    public function test_moodle_url_empty_param_values() {
87
    public function test_moodle_url_empty_param_values(): void {
88
        $strurl = 'http://moodle.org/course/view.php?id=0';
88
        $strurl = 'http://moodle.org/course/view.php?id=0';
89
        $url = new \moodle_url($strurl, array('id' => 0));
89
        $url = new \moodle_url($strurl, array('id' => 0));
Línea 90... Línea 90...
90
        $this->assertSame($strurl, $url->out(false));
90
        $this->assertSame($strurl, $url->out(false));
Línea 107... Línea 107...
107
    }
107
    }
Línea 108... Línea 108...
108
 
108
 
109
    /**
109
    /**
110
     * Test set good scheme on Moodle URL objects.
110
     * Test set good scheme on Moodle URL objects.
111
     */
111
     */
112
    public function test_moodle_url_set_good_scheme() {
112
    public function test_moodle_url_set_good_scheme(): void {
113
        $url = new \moodle_url('http://moodle.org/foo/bar');
113
        $url = new \moodle_url('http://moodle.org/foo/bar');
114
        $url->set_scheme('myscheme');
114
        $url->set_scheme('myscheme');
115
        $this->assertSame('myscheme://moodle.org/foo/bar', $url->out());
115
        $this->assertSame('myscheme://moodle.org/foo/bar', $url->out());
Línea 116... Línea 116...
116
    }
116
    }
117
 
117
 
118
    /**
118
    /**
119
     * Test set bad scheme on Moodle URL objects.
119
     * Test set bad scheme on Moodle URL objects.
120
     */
120
     */
121
    public function test_moodle_url_set_bad_scheme() {
121
    public function test_moodle_url_set_bad_scheme(): void {
122
        $url = new \moodle_url('http://moodle.org/foo/bar');
122
        $url = new \moodle_url('http://moodle.org/foo/bar');
123
        $this->expectException(\coding_exception::class);
123
        $this->expectException(\coding_exception::class);
Línea 124... Línea 124...
124
        $url->set_scheme('not a valid $ scheme');
124
        $url->set_scheme('not a valid $ scheme');
125
    }
125
    }
126
 
126
 
127
    public function test_moodle_url_round_trip_array_params() {
127
    public function test_moodle_url_round_trip_array_params(): void {
Línea 128... Línea 128...
128
        $strurl = 'http://example.com/?a%5B1%5D=1&a%5B2%5D=2';
128
        $strurl = 'http://example.com/?a%5B1%5D=1&a%5B2%5D=2';
Línea 136... Línea 136...
136
        $strurl = 'http://example.com/?a%5B0%5D=0&a%5B1%5D=1';
136
        $strurl = 'http://example.com/?a%5B0%5D=0&a%5B1%5D=1';
137
        $url = new \moodle_url('http://example.com/?a[]=0&a[]=1');
137
        $url = new \moodle_url('http://example.com/?a[]=0&a[]=1');
138
        $this->assertSame($strurl, $url->out(false));
138
        $this->assertSame($strurl, $url->out(false));
139
    }
139
    }
Línea 140... Línea 140...
140
 
140
 
141
    public function test_compare_url() {
141
    public function test_compare_url(): void {
142
        $url1 = new \moodle_url('index.php', array('var1' => 1, 'var2' => 2));
142
        $url1 = new \moodle_url('index.php', array('var1' => 1, 'var2' => 2));
Línea 143... Línea 143...
143
        $url2 = new \moodle_url('index2.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
143
        $url2 = new \moodle_url('index2.php', array('var1' => 1, 'var2' => 2, 'var3' => 3));
144
 
144
 
Línea 173... Línea 173...
173
        $this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
173
        $this->assertTrue($url1->compare($url2, URL_MATCH_BASE));
174
        $this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
174
        $this->assertTrue($url1->compare($url2, URL_MATCH_PARAMS));
175
        $this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
175
        $this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
176
    }
176
    }
Línea 177... Línea 177...
177
 
177
 
178
    public function test_out_as_local_url() {
178
    public function test_out_as_local_url(): void {
179
        global $CFG;
179
        global $CFG;
180
        // Test http url.
180
        // Test http url.
181
        $url1 = new \moodle_url('/lib/tests/weblib_test.php');
181
        $url1 = new \moodle_url('/lib/tests/weblib_test.php');
Línea 193... Línea 193...
193
        // Test http url matching wwwroot ending with slash (/).
193
        // Test http url matching wwwroot ending with slash (/).
194
        $url3 = new \moodle_url($CFG->wwwroot.'/');
194
        $url3 = new \moodle_url($CFG->wwwroot.'/');
195
        $this->assertSame('/', $url3->out_as_local_url());
195
        $this->assertSame('/', $url3->out_as_local_url());
196
    }
196
    }
Línea 197... Línea 197...
197
 
197
 
198
    public function test_out_as_local_url_error() {
198
    public function test_out_as_local_url_error(): void {
199
        $url2 = new \moodle_url('http://www.google.com/lib/tests/weblib_test.php');
199
        $url2 = new \moodle_url('http://www.google.com/lib/tests/weblib_test.php');
200
        $this->expectException(\coding_exception::class);
200
        $this->expectException(\coding_exception::class);
201
        $url2->out_as_local_url();
201
        $url2->out_as_local_url();
Línea 202... Línea 202...
202
    }
202
    }
203
 
203
 
204
    /**
204
    /**
205
     * You should get error with modified url
205
     * You should get error with modified url
206
     */
206
     */
Línea 207... Línea 207...
207
    public function test_modified_url_out_as_local_url_error() {
207
    public function test_modified_url_out_as_local_url_error(): void {
208
        global $CFG;
208
        global $CFG;
209
 
209
 
Línea 214... Línea 214...
214
    }
214
    }
Línea 215... Línea 215...
215
 
215
 
216
    /**
216
    /**
217
     * Try get local url from external https url and you should get error
217
     * Try get local url from external https url and you should get error
218
     */
218
     */
219
    public function test_https_out_as_local_url_error() {
219
    public function test_https_out_as_local_url_error(): void {
220
        $url4 = new \moodle_url('https://www.google.com/lib/tests/weblib_test.php');
220
        $url4 = new \moodle_url('https://www.google.com/lib/tests/weblib_test.php');
221
        $this->expectException(\coding_exception::class);
221
        $this->expectException(\coding_exception::class);
222
        $url4->out_as_local_url();
222
        $url4->out_as_local_url();
Línea 223... Línea 223...
223
    }
223
    }
224
 
224
 
225
    public function test_moodle_url_get_scheme() {
225
    public function test_moodle_url_get_scheme(): void {
226
        // Should return the scheme only.
226
        // Should return the scheme only.
Línea 227... Línea 227...
227
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
227
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
Línea 234... Línea 234...
234
        // Should return an empty string if no scheme is specified.
234
        // Should return an empty string if no scheme is specified.
235
        $url = new \moodle_url('www.example.org:447/my/file/is/here.txt?really=1');
235
        $url = new \moodle_url('www.example.org:447/my/file/is/here.txt?really=1');
236
        $this->assertSame('', $url->get_scheme());
236
        $this->assertSame('', $url->get_scheme());
237
    }
237
    }
Línea 238... Línea 238...
238
 
238
 
239
    public function test_moodle_url_get_host() {
239
    public function test_moodle_url_get_host(): void {
240
        // Should return the host part only.
240
        // Should return the host part only.
241
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
241
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
242
        $this->assertSame('www.example.org', $url->get_host());
242
        $this->assertSame('www.example.org', $url->get_host());
Línea 243... Línea 243...
243
    }
243
    }
244
 
244
 
245
    public function test_moodle_url_get_port() {
245
    public function test_moodle_url_get_port(): void {
246
        // Should return the port if one provided.
246
        // Should return the port if one provided.
Línea 247... Línea 247...
247
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
247
        $url = new \moodle_url('http://www.example.org:447/my/file/is/here.txt?really=1');
Línea 326... Línea 326...
326
     * @dataProvider make_pluginfile_url_provider
326
     * @dataProvider make_pluginfile_url_provider
327
     * @param   bool    $slashargs
327
     * @param   bool    $slashargs
328
     * @param   array   $args Args to be provided to make_pluginfile_url
328
     * @param   array   $args Args to be provided to make_pluginfile_url
329
     * @param   string  $expected The expected result
329
     * @param   string  $expected The expected result
330
     */
330
     */
331
    public function test_make_pluginfile_url($slashargs, $args, $expected) {
331
    public function test_make_pluginfile_url($slashargs, $args, $expected): void {
332
        global $CFG;
332
        global $CFG;
Línea 333... Línea 333...
333
 
333
 
Línea 334... Línea 334...
334
        $this->resetAfterTest();
334
        $this->resetAfterTest();