mirror of
https://github.com/moodle/moodle.git
synced 2025-08-10 11:26:41 +02:00
MDL-81960 core: Move moodle_url tests to correct location
This commit is contained in:
parent
b637f8cc4e
commit
097b3fbee3
3 changed files with 1 additions and 150 deletions
|
@ -390,6 +390,7 @@ class core_component {
|
|||
$keyclasses = [
|
||||
\core\exception\moodle_exception::class,
|
||||
\core\output\bootstrap_renderer::class,
|
||||
\core\url::class,
|
||||
];
|
||||
foreach ($keyclasses as $classname) {
|
||||
if (!array_key_exists($classname, $cache['classmap'])) {
|
||||
|
|
|
@ -175,26 +175,6 @@ final class url_test extends \advanced_testcase {
|
|||
$this->assertTrue($url1->compare($url2, URL_MATCH_EXACT));
|
||||
}
|
||||
|
||||
public function test_out_as_local_url(): void {
|
||||
global $CFG;
|
||||
// Test http url.
|
||||
$url1 = new url('/lib/tests/weblib_test.php');
|
||||
$this->assertSame('/lib/tests/weblib_test.php', $url1->out_as_local_url());
|
||||
|
||||
// Test https url.
|
||||
$httpswwwroot = str_replace("http://", "https://", $CFG->wwwroot);
|
||||
$url2 = new url($httpswwwroot . '/login/profile.php');
|
||||
$this->assertSame('/login/profile.php', $url2->out_as_local_url());
|
||||
|
||||
// Test http url matching wwwroot.
|
||||
$url3 = new url($CFG->wwwroot);
|
||||
$this->assertSame('', $url3->out_as_local_url());
|
||||
|
||||
// Test http url matching wwwroot ending with slash (/).
|
||||
$url3 = new url($CFG->wwwroot . '/');
|
||||
$this->assertSame('/', $url3->out_as_local_url());
|
||||
}
|
||||
|
||||
public function test_out_as_local_url_error(): void {
|
||||
$url2 = new url('http://www.google.com/lib/tests/weblib_test.php');
|
||||
$this->expectException(\coding_exception::class);
|
||||
|
|
|
@ -1199,136 +1199,6 @@ EXPECTED;
|
|||
$this->assertEquals($expected, get_html_lang_attribute_value($langcode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the coding exceptions when returning URL as relative path from $CFG->wwwroot.
|
||||
*
|
||||
* @param moodle_url $url The URL pointing to a web resource.
|
||||
* @param string $exmessage The expected output URL.
|
||||
* @throws coding_exception If called on a non-local URL.
|
||||
* @see \moodle_url::out_as_local_url()
|
||||
* @covers \moodle_url::out_as_local_url
|
||||
* @dataProvider out_as_local_url_coding_exception_provider
|
||||
*/
|
||||
public function test_out_as_local_url_coding_exception(\moodle_url $url, string $exmessage): void {
|
||||
$this->expectException(\coding_exception::class);
|
||||
$this->expectExceptionMessage($exmessage);
|
||||
$localurl = $url->out_as_local_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for throwing coding exceptions in <u>\moodle_url::out_as_local_url()</u>.
|
||||
*
|
||||
* @return array
|
||||
* @throws moodle_exception On seriously malformed URLs (<u>parse_url</u>).
|
||||
* @see \moodle_url::out_as_local_url()
|
||||
* @see parse_url()
|
||||
*/
|
||||
public function out_as_local_url_coding_exception_provider() {
|
||||
return [
|
||||
'Google Maps CDN (HTTPS)' => [
|
||||
new \moodle_url('https://maps.googleapis.com/maps/api/js', ['key' => 'googlemapkey3', 'sensor' => 'false']),
|
||||
'Coding error detected, it must be fixed by a programmer: out_as_local_url called on a non-local URL'
|
||||
],
|
||||
'Google Maps CDN (HTTP)' => [
|
||||
new \moodle_url('http://maps.googleapis.com/maps/api/js', ['key' => 'googlemapkey3', 'sensor' => 'false']),
|
||||
'Coding error detected, it must be fixed by a programmer: out_as_local_url called on a non-local URL'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test URL as relative path from $CFG->wwwroot.
|
||||
*
|
||||
* @param moodle_url $url The URL pointing to a web resource.
|
||||
* @param string $expected The expected local URL.
|
||||
* @throws coding_exception If called on a non-local URL.
|
||||
* @see \moodle_url::out_as_local_url()
|
||||
* @covers \moodle_url::out_as_local_url
|
||||
* @dataProvider out_as_local_url_provider
|
||||
*/
|
||||
public function test_out_as_local_url(\moodle_url $url, string $expected): void {
|
||||
$this->assertEquals($expected, $url->out_as_local_url(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for returning local paths via <u>\moodle_url::out_as_local_url()</u>.
|
||||
*
|
||||
* @return array
|
||||
* @throws moodle_exception On seriously malformed URLs (<u>parse_url</u>).
|
||||
* @see \moodle_url::out_as_local_url()
|
||||
* @see parse_url()
|
||||
*/
|
||||
public function out_as_local_url_provider() {
|
||||
global $CFG;
|
||||
$wwwroot = rtrim($CFG->wwwroot, '/');
|
||||
|
||||
return [
|
||||
'Environment XML file' => [
|
||||
new \moodle_url('/admin/environment.xml'),
|
||||
'/admin/environment.xml'
|
||||
],
|
||||
'H5P JS internal resource' => [
|
||||
new \moodle_url('/h5p/js/embed.js'),
|
||||
'/h5p/js/embed.js'
|
||||
],
|
||||
'A Moodle JS resource using the full path including the proper JS Handler' => [
|
||||
new \moodle_url($wwwroot . '/lib/javascript.php/1/lib/editor/tiny/js/tinymce/tinymce.js'),
|
||||
'/lib/javascript.php/1/lib/editor/tiny/js/tinymce/tinymce.js'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test URL as relative path from $CFG->wwwroot.
|
||||
*
|
||||
* @param moodle_url $url The URL pointing to a web resource.
|
||||
* @param bool $expected The expected result.
|
||||
* @see \moodle_url::is_local_url()
|
||||
* @covers \moodle_url::is_local_url
|
||||
* @dataProvider is_local_url_provider
|
||||
*/
|
||||
public function test_is_local_url(\moodle_url $url, bool $expected): void {
|
||||
$this->assertEquals($expected, $url->is_local_url(), "'{$url}' is not a local URL!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testing <u>\moodle_url::is_local_url()</u>.
|
||||
*
|
||||
* @return array
|
||||
* @see \moodle_url::is_local_url()
|
||||
*/
|
||||
public function is_local_url_provider() {
|
||||
global $CFG;
|
||||
$wwwroot = rtrim($CFG->wwwroot, '/');
|
||||
|
||||
return [
|
||||
'Google Maps CDN (HTTPS)' => [
|
||||
new \moodle_url('https://maps.googleapis.com/maps/api/js', ['key' => 'googlemapkey3', 'sensor' => 'false']),
|
||||
false
|
||||
],
|
||||
'Google Maps CDN (HTTP)' => [
|
||||
new \moodle_url('http://maps.googleapis.com/maps/api/js', ['key' => 'googlemapkey3', 'sensor' => 'false']),
|
||||
false
|
||||
],
|
||||
'wwwroot' => [
|
||||
new \moodle_url($wwwroot),
|
||||
true
|
||||
],
|
||||
'wwwroot/' => [
|
||||
new \moodle_url($wwwroot . '/'),
|
||||
true
|
||||
],
|
||||
'Environment XML file' => [
|
||||
new \moodle_url('/admin/environment.xml'),
|
||||
true
|
||||
],
|
||||
'H5P JS internal resource' => [
|
||||
new \moodle_url('/h5p/js/embed.js'),
|
||||
true
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for strip_querystring tests.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue