Skip to content

Commit

Permalink
MDL-54116 block_comments: warnings when commenting outside of a course
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy authored and cameorn1730 committed May 26, 2016
1 parent f2778cc commit c0e3e9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 14 additions & 4 deletions blocks/comments/tests/behat/block_comment_dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
9 changes: 8 additions & 1 deletion comment/comment_post.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
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);
Expand All @@ -48,7 +53,9 @@

$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;
Expand Down

0 comments on commit c0e3e9d

Please sign in to comment.