MDL-62640 mod_wiki: Adjust code for slashargument removal

This commit is contained in:
meirzamoodle
2024-09-25 08:30:18 +07:00
parent 652f6b9994
commit 83f6d355f7
2 changed files with 22 additions and 3 deletions
-3
View File
@@ -736,9 +736,6 @@ function wiki_parser_real_path($url, $context, $component, $filearea, $swid) {
} else {
$file = 'pluginfile.php';
if (!$CFG->slasharguments) {
$file = $file . '?file=';
}
$baseurl = "$CFG->wwwroot/$file/{$context->id}/$component/$filearea/$swid/";
// it is a file in current file area
return $baseurl . $url;
+22
View File
@@ -922,4 +922,26 @@ class lib_test extends \advanced_testcase {
return \calendar_event::create($event);
}
/**
* Tests the wiki_parser_real_path function to ensure it correctly resolves URLs.
*
* @covers ::wiki_parser_real_path()
*/
public function test_wiki_parser_real_path(): void {
global $CFG;
$this->resetAfterTest();
// Create the activity.
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
$wiki = $this->getDataGenerator()->create_module('wiki', ['course' => $course->id]);
$context = \context_module::instance($wiki->cmid);
$moodleurl = new \moodle_url('/mod/wiki/view.php', ['id' => 2]);
$url = wiki_parser_real_path($moodleurl->out(), $context, 'mod_wiki', 'attachments', 3);
$this->assertSame("{$CFG->wwwroot}/mod/wiki/view.php?id=2", $url);
$url = wiki_parser_real_path('mod/wiki/view.php?id=2', $context, 'mod_wiki', 'attachments', 3);
$this->assertSame("{$CFG->wwwroot}/pluginfile.php/{$context->id}/mod_wiki/attachments/3/mod/wiki/view.php?id=2", $url);
}
}