From 95b82c9dcf1c7443a17182a54650a1dafb1d2c21 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Mon, 9 May 2016 18:58:05 -0400 Subject: [PATCH 1/2] MDL-54116 block_comments: behat test --- .../behat/block_comment_dashboard.feature | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 blocks/comments/tests/behat/block_comment_dashboard.feature diff --git a/blocks/comments/tests/behat/block_comment_dashboard.feature b/blocks/comments/tests/behat/block_comment_dashboard.feature new file mode 100644 index 00000000000..e37faabd5aa --- /dev/null +++ b/blocks/comments/tests/behat/block_comment_dashboard.feature @@ -0,0 +1,19 @@ +@block @block_comments +Feature: Enable Block comments on the dashboard and view comments + In order to enable the comments block on a the dashboard + As a teacher + I can add the comments block to my dashboard + + Scenario: Add the comments block on the dashboard and add comments + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | Frist | teacher1@example.com | + And I log in as "teacher1" + And I press "Customise this page" + And I add the "Comment" block + And I follow "Show comments" + When I add "I'm a comment from the teacher" comment to comments block + Then I should see "I'm a comment from the teacher" From 89fba73a45420b1497e3590d23d2bccfbc5da128 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 16 May 2016 10:22:40 +0800 Subject: [PATCH 2/2] MDL-54116 block_comments: warnings when commenting outside of a course --- .../behat/block_comment_dashboard.feature | 18 ++++++++++++++---- comment/comment_post.php | 9 ++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/blocks/comments/tests/behat/block_comment_dashboard.feature b/blocks/comments/tests/behat/block_comment_dashboard.feature index e37faabd5aa..66e49c6e9db 100644 --- a/blocks/comments/tests/behat/block_comment_dashboard.feature +++ b/blocks/comments/tests/behat/block_comment_dashboard.feature @@ -4,16 +4,26 @@ Feature: Enable Block comments on the dashboard and view comments As a teacher I can add the comments block to my dashboard - Scenario: Add the comments block on the dashboard and add comments + Background: Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | Frist | teacher1@example.com | - And I log in as "teacher1" + + Scenario: Add the comments block on the dashboard and add comments with Javascript disabled + When I log in as "teacher1" And I press "Customise this page" - And I add the "Comment" block + And I add the "Comments" block And I follow "Show comments" - When I add "I'm a comment from the teacher" comment to comments block + And I add "I'm a comment from the teacher" comment to comments block + Then I should see "I'm a comment from the teacher" + + @javascript + Scenario: Add the comments block on the dashboard and add comments with Javascript enabled + When I log in as "teacher1" + And I press "Customise this page" + And I add the "Comments" block + And I add "I'm a comment from the teacher" comment to comments block Then I should see "I'm a comment from the teacher" diff --git a/comment/comment_post.php b/comment/comment_post.php index a9602936934..bfe717b0302 100644 --- a/comment/comment_post.php +++ b/comment/comment_post.php @@ -34,6 +34,11 @@ list($context, $course, $cm) = get_context_info_array($contextid); require_login($course, true, $cm); require_sesskey(); +if (!$course) { + // Require_login() does not set context if called without a $course, do it manually. + $PAGE->set_context($context); +} + $action = optional_param('action', '', PARAM_ALPHA); $area = optional_param('area', '', PARAM_AREA); $content = optional_param('content', '', PARAM_RAW); @@ -48,7 +53,9 @@ if ($action !== 'add') { $cmt = new stdClass; $cmt->contextid = $contextid; -$cmt->courseid = $course->id; +if ($course) { + $cmt->courseid = $course->id; +} $cmt->cm = $cm; $cmt->area = $area; $cmt->itemid = $itemid;