From e06ddff2cd66c0c56deca2b39ecabf690b7ffc18 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 25 Jul 2025 12:03:35 +0200 Subject: [PATCH] MDL-31071 blog: replace deprecated file_encode_url Signed-off-by: Daniel Ziegenberg --- public/blog/locallib.php | 12 ++++++++++-- public/blog/tests/behat/blog_entry.feature | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/public/blog/locallib.php b/public/blog/locallib.php index d6ad0880f48..b1b6f2c0979 100644 --- a/public/blog/locallib.php +++ b/public/blog/locallib.php @@ -27,6 +27,8 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->libdir . '/filelib.php'); +use core\url; + /** * Blog_entry class. Represents an entry in a user's blog. Contains all methods for managing this entry. * This class does not contain any HTML-generating code. See blog_listing sub-classes for such code. @@ -1175,8 +1177,14 @@ class blog_entry_attachment implements renderable { $this->file = $file; $this->filename = $file->get_filename(); - $this->url = file_encode_url($CFG->wwwroot . '/pluginfile.php', - '/' . SYSCONTEXTID . '/blog/attachment/' . $entryid . '/' . $this->filename); + $this->url = url::make_pluginfile_url( + contextid: SYSCONTEXTID, + component: 'blog', + area: 'attachment', + itemid: $entryid, + pathname: '/', + filename: $this->filename + )->out(); } } diff --git a/public/blog/tests/behat/blog_entry.feature b/public/blog/tests/behat/blog_entry.feature index 254254706bc..f3fa1938c79 100644 --- a/public/blog/tests/behat/blog_entry.feature +++ b/public/blog/tests/behat/blog_entry.feature @@ -13,9 +13,9 @@ Feature: Blog entries can be added, modified and deleted And I follow "Add a new entry" And I should see "Blogs: Add a new entry" And I set the following fields to these values: - | Entry title | Entry 1 | - | Blog entry body | Entry 1 content | - | Attachment | lib/tests/fixtures/gd-logo.png | + | Entry title | Entry 1 | + | Blog entry body | Entry 1 content | + | Attachment | lib/tests/fixtures/empty.txt | And I press "Save changes" Scenario: Modify a blog entry @@ -24,6 +24,10 @@ Feature: Blog entries can be added, modified and deleted | Entry title | Blog entry 1 | And I press "Save changes" Then I should see "Blog entry 1" + And I should see "Entry 1 content" + And I should see "empty.txt" + And following "empty.txt" should download a file that: + | contains text | empty file for testing purposes | Scenario: Delete a blog entry When I click on "Delete" "link"