Permalink
Browse files

MDL-47065 notes: don't add blank notes

Previously the logic was wrong and was proceeding to add a note
when content was missing.

Also add behat coverage for adding notes to participants (this test is
not perfect, but better than zero coverage we had before).
  • Loading branch information...
danpoltawski authored and dmonllao committed Nov 5, 2015
1 parent 44f23c7 commit 6ccff3ba5d88ec2355d189ef94add7f5e0494cd6
Showing with 43 additions and 1 deletion.
  1. +41 −0 notes/tests/behat/participants_notes.feature
  2. +2 −1 user/addnote.php
@@ -0,0 +1,41 @@
@core @core_note
Feature: Add notes to course participants
In order to share information with other staff
As a teacher
I need to add notes from the course particpants list
Scenario: An teacher can add multiple notes
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Participants"
And I set the field with xpath "//tr[contains(normalize-space(.), 'Student 1')]//input[@type='checkbox']" to "1"
And I set the field with xpath "//tr[contains(normalize-space(.), 'Student 2')]//input[@type='checkbox']" to "1"
And I set the field "With selected users..." to "Add a new note"
And I press "OK"
# Add a note to student 1, but leave student 2 empty.
When I set the field with xpath "//tr[contains(normalize-space(.), 'Student 1')]//textarea" to "Student 1 needs to pick up his game"
And I set the field with xpath "//tr[contains(normalize-space(.), 'Student 2')]//textarea" to ""
And I press "Save changes"
And I follow "Student 1"
And I follow "Notes"
# Student 1 has note from Teacher
Then I should see "Teacher" in the "region-main" "region"
And I should see "Student 1 needs to pick up his game"
And I follow "Participants"
And I follow "Student 2"
And I follow "Notes"
# Terrible way to verify the absence of a note..
And I should not see "Teacher" in the "region-main" "region"
View
@@ -54,7 +54,8 @@
$note->courseid = $id;
$note->format = FORMAT_PLAIN;
foreach ($users as $k => $v) {
if (!$user = $DB->get_record('user', array('id' => $v)) || empty($contents[$k])) {
$user = $DB->get_record('user', array('id' => $v));
if (!$user || empty($contents[$k])) {
continue;
}
$note->id = 0;

0 comments on commit 6ccff3b

Please sign in to comment.