Skip to content

Commit 1fba3f9

Browse files
committed
Set subscription and readtracking at beginning of test
1 parent 03214d5 commit 1fba3f9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/behat/behat_mod_moodleoverflow.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,36 @@ public function should_be_tracking(string $type, string $modflowname) {
536536
}
537537
}
538538

539+
/**
540+
* Set subscription and readtracking for a user in a moodleoverflow.
541+
* @Given User :username has in :modflowname subscription :substype and readtracking :readtype
542+
* @param string $username
543+
* @param string $modflowname
544+
* @param string $substype "on" or "off"
545+
* @param string $readtype "on" or "off"
546+
* @return void
547+
*/
548+
public function set_subscription_readtracking(string $username, string $modflowname, string $substype, string $readtype): void {
549+
global $DB;
550+
$substype = $substype == "on" ? true : false;
551+
$readtype = $readtype == "on" ? true : false;
552+
$modflow = $DB->get_record('moodleoverflow', ['name' => $modflowname]);
553+
$user = $DB->get_record('user', ['username' => $username]);
554+
$cm = get_coursemodule_from_instance('moodleoverflow', $modflow->id);
555+
$modcontext = context_module::instance($cm->id);
556+
if ($substype) {
557+
subscriptions::subscribe_user($user->id, $modflow, $modcontext, true);
558+
} else {
559+
subscriptions::unsubscribe_user($user->id, $modflow, $modcontext, true);
560+
}
561+
562+
if ($readtype) {
563+
readtracking::moodleoverflow_start_tracking($modflow->id, $user->id);
564+
} else {
565+
readtracking::moodleoverflow_start_tracking($modflow->id, $user->id);
566+
}
567+
}
568+
539569
// Internal helper functions.
540570

541571
/**

tests/behat/overview_report.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Feature: Testing overview integration in moodleoverflow activity
1515
| moodleoverflow | Test Moodleoverflow | Test moodleoverflow description | C1 | 1 |
1616
And User "teacher1" adds to "Test Moodleoverflow" a discussion with topic "Topic1" and message "message1" automatically
1717
And User "student1" replies "message1" with "message2" automatically
18+
And User "student1" has in "Test Moodleoverflow" subscription "off" and readtracking "on"
1819

1920
Scenario: The bin to mark all unread posts as read should work
2021
When I am on the "C1" "course > activities > moodleoverflow" page logged in as "teacher1"

0 commit comments

Comments
 (0)