From 9a58434601f68a11ba93638dc10eafc55dd1403c Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 23 Oct 2015 17:50:16 +0800 Subject: [PATCH] MDL-40863 mod_resource: do not cache user-specific info --- mod/resource/lib.php | 8 ++- .../tests/behat/display_resource.feature | 66 +++++++++++++++++++ mod/resource/tests/fixtures/samplefile.txt | 1 + 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 mod/resource/tests/behat/display_resource.feature create mode 100644 mod/resource/tests/fixtures/samplefile.txt diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 71e8f491a1c..e786687611f 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -238,7 +238,7 @@ function resource_get_coursemodule_info($coursemodule) { } // If any optional extra details are turned on, store in custom data - $info->customdata = resource_get_optional_details($resource, $coursemodule); + $info->customdata = $resource->displayoptions; return $info; } @@ -250,7 +250,11 @@ function resource_get_coursemodule_info($coursemodule) { * @param cm_info $cm Course module information */ function resource_cm_info_view(cm_info $cm) { - $details = $cm->customdata; + global $CFG; + require_once($CFG->dirroot . '/mod/resource/locallib.php'); + + $resource = (object)array('displayoptions' => $cm->customdata); + $details = resource_get_optional_details($resource, $cm); if ($details) { $cm->set_after_link(' ' . html_writer::tag('span', $details, array('class' => 'resourcelinkdetails'))); diff --git a/mod/resource/tests/behat/display_resource.feature b/mod/resource/tests/behat/display_resource.feature new file mode 100644 index 00000000000..1126241133a --- /dev/null +++ b/mod/resource/tests/behat/display_resource.feature @@ -0,0 +1,66 @@ +@mod @mod_resource +Feature: Teacher can specify different display options for the resource + In order to provide more information about a file + As a teacher + I need to be able to show size, type and modified date + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + + @javascript + Scenario: Specifying no additional display options for a file resource + When I add a "File" to section "1" + And I set the following fields to these values: + | Name | Myfile | + | Show size | 0 | + | Show type | 0 | + | Show upload/modified date | 0 | + And I upload "mod/resource/tests/fixtures/samplefile.txt" file to "Select files" filemanager + And I press "Save and display" + Then ".resourcedetails" "css_element" should not exist + And I follow "Course 1" + And ".activity.resource .resourcelinkdetails" "css_element" should not exist + And I log out + + @javascript + Scenario Outline: Specifying different display options for a file resource + When I add a "File" to section "1" + And I set the following fields to these values: + | Name | Myfile | + | Display | Open | + | Show size | | + | Show type | | + | Show upload/modified date | | + And I upload "mod/resource/tests/fixtures/samplefile.txt" file to "Select files" filemanager + And I press "Save and display" + Then I see "6 bytes" in the ".resourcedetails" "css_element" + And I see "Text file" in the ".resourcedetails" "css_element" + And I see "2015" in the ".resourcedetails" "css_element" + And I follow "Course 1" + And I see "6 bytes" in the ".activity.resource .resourcelinkdetails" "css_element" + And I see "Text file" in the ".activity.resource .resourcelinkdetails" "css_element" + And I see "2015" in the ".activity.resource .resourcelinkdetails" "css_element" + And I log out + + Examples: + | showsize | showtype | showdate | seesize | seetype | seedate | + | 1 | 0 | 0 | should | should not | should not | + | 0 | 1 | 0 | should not | should | should not | + | 0 | 0 | 1 | should not | should not | should | + | 1 | 1 | 0 | should | should | should not | + | 1 | 0 | 1 | should | should not | should | + | 0 | 1 | 1 | should not | should | should | + | 1 | 1 | 1 | should | should | should | diff --git a/mod/resource/tests/fixtures/samplefile.txt b/mod/resource/tests/fixtures/samplefile.txt new file mode 100644 index 00000000000..05a682bd4e7 --- /dev/null +++ b/mod/resource/tests/fixtures/samplefile.txt @@ -0,0 +1 @@ +Hello! \ No newline at end of file -- 2.43.0