|
32 | 32 | use Behat\Mink\Exception\ExpectationException; |
33 | 33 | use mod_moodleoverflow\post\post_control; |
34 | 34 | use mod_moodleoverflow\readtracking; |
| 35 | +use mod_moodleoverflow\review; |
35 | 36 | use mod_moodleoverflow\subscriptions; |
36 | 37 |
|
37 | 38 | /** |
@@ -136,6 +137,88 @@ public function i_add_a_moodleoverflow_discussion_with_posts_from_different_user |
136 | 137 | ]); |
137 | 138 | } |
138 | 139 |
|
| 140 | + /** |
| 141 | + * Build a background to test the reviewing (approve/reject) feature. |
| 142 | + * Builds: |
| 143 | + * - A course with one teacher and one student, both enrolled. |
| 144 | + * - A moodleoverflow that requires every new post to be reviewed. |
| 145 | + * - A discussion started by the teacher whose first post is already reviewed. |
| 146 | + * - A reply by the student that is still pending review. |
| 147 | + * |
| 148 | + * The student post is created in the past so that it is already past the review waiting |
| 149 | + * period (reviewpossibleaftertime), which makes the approve/reject buttons show immediately. |
| 150 | + * |
| 151 | + * @Given /^I set up a moodleoverflow with a student post pending review$/ |
| 152 | + * @return void |
| 153 | + */ |
| 154 | + public function i_set_up_a_moodleoverflow_with_a_student_post_pending_review(): void { |
| 155 | + global $DB; |
| 156 | + |
| 157 | + $this->i_prepare_a_moodleoverflow_background(new TableNode([ |
| 158 | + ['username', 'firstname', 'lastname', 'email', 'idnumber', 'role'], |
| 159 | + ['teacher1', 'Tamaro', 'Walter', 'tamaro@mail.com', '10', 'teacher'], |
| 160 | + ['student1', 'John', 'Smith', 'john@mail.com', '11', 'student'], |
| 161 | + ])); |
| 162 | + |
| 163 | + $course = $DB->get_record('course', ['shortname' => 'C1']); |
| 164 | + $teacher = $DB->get_record('user', ['username' => 'teacher1']); |
| 165 | + $student = $DB->get_record('user', ['username' => 'student1']); |
| 166 | + $time = time(); |
| 167 | + // Age the pending post so it is past the review waiting period and the review buttons are shown. |
| 168 | + $pasttime = $time - DAYSECS; |
| 169 | + |
| 170 | + // Create a moodleoverflow that requires every post to be reviewed. |
| 171 | + $this->execute('behat_data_generators::the_following_entities_exist', ['activities', new TableNode([ |
| 172 | + ['activity', 'course', 'name', 'needsreview'], |
| 173 | + ['moodleoverflow', 'C1', 'Moodleoverflow 1', review::EVERYTHING], |
| 174 | + ])]); |
| 175 | + $moodleoverflow = $DB->get_record('moodleoverflow', ['name' => 'Moodleoverflow 1']); |
| 176 | + |
| 177 | + // Create the discussion with the teacher's already reviewed first post. |
| 178 | + $discussionid = $DB->insert_record('moodleoverflow_discussions', ['course' => $course->id, |
| 179 | + 'moodleoverflow' => $moodleoverflow->id, 'name' => 'Discussion 1', 'firstpost' => 1, 'userid' => $teacher->id, |
| 180 | + 'timemodified' => $time, 'timestart' => $time, 'usermodified' => $teacher->id, |
| 181 | + ]); |
| 182 | + $teacherpostid = $DB->insert_record('moodleoverflow_posts', ['discussion' => $discussionid, |
| 183 | + 'moodleoverflow' => $moodleoverflow->id, 'parent' => 0, 'userid' => $teacher->id, 'created' => $time, |
| 184 | + 'modified' => $time, 'message' => 'Message from teacher', 'messageformat' => 1, 'attachment' => '', 'mailed' => 1, |
| 185 | + 'reviewed' => 1, 'timereviewed' => $time, |
| 186 | + ]); |
| 187 | + |
| 188 | + // Update firstpost field in discussion. |
| 189 | + $record = $DB->get_record('moodleoverflow_discussions', ['id' => $discussionid]); |
| 190 | + $record->firstpost = $teacherpostid; |
| 191 | + $DB->update_record('moodleoverflow_discussions', $record); |
| 192 | + |
| 193 | + // Create the student reply that is still pending review. |
| 194 | + $DB->insert_record('moodleoverflow_posts', ['discussion' => $discussionid, 'moodleoverflow' => $moodleoverflow->id, |
| 195 | + 'parent' => $teacherpostid, 'userid' => $student->id, 'created' => $pasttime, 'modified' => $pasttime, |
| 196 | + 'message' => 'Answer from student', 'messageformat' => 1, 'attachment' => '', 'mailed' => 1, 'reviewed' => 0, |
| 197 | + 'timereviewed' => null, |
| 198 | + ]); |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Clicks a moodleoverflow review action button (e.g. "approve", "reject", "reject-submit"). |
| 203 | + * |
| 204 | + * The button is scrolled into the centre of the viewport first so that it is not covered by |
| 205 | + * sticky page elements such as the course activity navigation footer, which would otherwise |
| 206 | + * intercept the click. |
| 207 | + * |
| 208 | + * @When /^I click on the "(?P<action_string>[^"]*)" moodleoverflow review button$/ |
| 209 | + * @param string $action The value of the data-moodleoverflow-action attribute. |
| 210 | + * @return void |
| 211 | + */ |
| 212 | + public function i_click_on_the_moodleoverflow_review_button(string $action): void { |
| 213 | + $selector = "[data-moodleoverflow-action='" . $action . "']"; |
| 214 | + $node = $this->find('css', $selector); |
| 215 | + $this->getSession()->executeScript( |
| 216 | + "document.querySelector(\"" . $selector . "\").scrollIntoView({block: 'center'});" |
| 217 | + ); |
| 218 | + $this->ensure_node_is_visible($node); |
| 219 | + $node->click(); |
| 220 | + } |
| 221 | + |
139 | 222 | /** |
140 | 223 | * The admin adds a moodleoverflow discussions with a tracking type. Used in the track_read_posts_feature. |
141 | 224 | * |
|
0 commit comments