Skip to content

Commit

Permalink
MDL-62640 mod_wiki: Adjust code for slashargument removal
Browse files Browse the repository at this point in the history
  • Loading branch information
meirzamoodle committed Sep 25, 2024
1 parent 652f6b9 commit 83f6d35
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 0 additions & 3 deletions mod/wiki/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions mod/wiki/tests/lib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,26 @@ private function create_action_event($courseid, $instanceid, $eventtype) {

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);
}
}

0 comments on commit 83f6d35

Please sign in to comment.