Skip to content

Commit 7fd52a7

Browse files
committed
new try
1 parent f21d767 commit 7fd52a7

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
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 & 2 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"
@@ -26,14 +27,12 @@ Feature: Testing overview integration in moodleoverflow activity
2627
Given I am on the "C1" "course > activities > moodleoverflow" page logged in as "student1"
2728
And I should not be subscribed to "Test Moodleoverflow"
2829
When I click on ".moodleoverflow-subscription-toggle .form-check-input" "css_element"
29-
And I wait "2" seconds
3030
And I reload the page
3131
Then I should " " be subscribed to "Test Moodleoverflow"
3232

3333
Scenario: The readtracking toggle item should work
3434
Given I am on the "C1" "course > activities > moodleoverflow" page logged in as "student1"
3535
And I should " " have readtracking on in "Test Moodleoverflow"
3636
When I click on ".moodleoverflow-readtracking-toggle .form-check-input" "css_element"
37-
And I wait "2" seconds
3837
And I reload the page
3938
Then I should not have readtracking on in "Test Moodleoverflow"

0 commit comments

Comments
 (0)