+
\ No newline at end of file
diff --git a/tests/behat/behat_mod_moodleoverflow.php b/tests/behat/behat_mod_moodleoverflow.php
index 69305a4903..bfdffc7c0e 100644
--- a/tests/behat/behat_mod_moodleoverflow.php
+++ b/tests/behat/behat_mod_moodleoverflow.php
@@ -131,7 +131,7 @@ public function i_add_a_moodleoverflow_discussion_with_posts_from_different_user
}
/**
- * The admins adds a moodleoverflow discussions with a tracking type. Used in the track_read_posts_feature.
+ * The admin adds a moodleoverflow discussions with a tracking type. Used in the track_read_posts_feature.
*
* @Given /^The admin posts "(?P
[^"]*)" in "(?P[^"]*)" with tracking type "(?P[^"]*)"$/
*
@@ -153,6 +153,24 @@ public function admin_adds_moodleoverflow_with_tracking_type(string $subject, st
]));
}
+ /**
+ * The admin adds a moodleoverflow discussion.
+ *
+ * @Given /^The admin posts "(?P[^"]*)" in "(?P[^"]*)"$/
+ *
+ * @param string $subject
+ * @param string $name
+ * @return void
+ */
+ public function admin_adds_discussion(string $subject, string $name): void {
+ $this->execute('behat_auth::i_log_in_as', 'admin');
+ $this->execute('behat_navigation::i_am_on_course_homepage', 'Course 1');
+ $this->i_add_a_moodleoverflow_discussion_to_moodleoverflow_with($name, new TableNode([
+ ['Subject', $subject],
+ ['Message', 'Test post message'],
+ ]));
+ }
+
/**
* Logs in as a user and navigates in a course to dedicated moodleoverflow discussion.
*
@@ -225,30 +243,10 @@ public function i_comment_moodleoverflow_post_with_message(string $postmessage,
* @param TableNode $data
*/
public function i_add_moodleoverflow_to_course_and_fill_form(string $courseshortname, string $sectionnumber, TableNode $data) {
- global $CFG;
-
- if ($CFG->branch >= 404) {
- $this->execute(
- "behat_course::i_add_to_course_section_and_i_fill_the_form_with",
- [$this->escape('moodleoverflow'), $this->escape($courseshortname), $this->escape($sectionnumber), $data]
- );
- } else {
- // This is the code from the deprecated behat function "i_add_to_section_and_i_fill_the_form_with".
- // Add activity to section.
- $this->execute(
- "behat_course::i_add_to_section",
- [$this->escape('moodleoverflow'), $this->escape($sectionnumber)]
- );
-
- // Wait to be redirected.
- $this->execute('behat_general::wait_until_the_page_is_ready');
-
- // Set form fields.
- $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
-
- // Save course settings.
- $this->execute("behat_forms::press_button", get_string('savechangesandreturntocourse'));
- }
+ $this->execute(
+ "behat_course::i_add_to_course_section_and_i_fill_the_form_with",
+ [$this->escape('moodleoverflow'), $this->escape($courseshortname), $this->escape($sectionnumber), $data]
+ );
}
/**
diff --git a/tests/behat/track_read_posts.feature b/tests/behat/track_read_posts.feature
index c9a4261147..8b495d7169 100644
--- a/tests/behat/track_read_posts.feature
+++ b/tests/behat/track_read_posts.feature
@@ -1,4 +1,4 @@
-@mod @mod_moodleoverflow
+@mod @mod_moodleoverflow @javascript
Feature: A teacher can set one of 3 possible options for tracking read moodleoverflow posts
In order to ease the moodleoverflow posts follow up
As a user
@@ -67,3 +67,17 @@ Feature: A teacher can set one of 3 possible options for tracking read moodleove
And I click on "1" "link" in the "Test post subject" moodleoverflow discussion card
And I am on "Course 1" course homepage
And I should not see "1 unread post"
+
+ Scenario: Marking all unread posts as read.
+ Given the following config values are set as admin:
+ | allowforcedreadtracking | 1 | moodleoverflow |
+ And The admin posts "Test post subject" in "Test moodleoverflow name" with tracking type "2"
+ And The admin posts "Test post subject 2" in "Test moodleoverflow name"
+ And I log in as "student1"
+ And I am on "Course 1" course homepage
+ And I should see "2 unread post"
+ And I follow "Test moodleoverflow name"
+ When I click on "Mark all posts as read" "link"
+ And I am on "Course 1" course homepage
+ Then I should not see "2 unread post"
+
diff --git a/tests/discussion_test.php b/tests/discussion_test.php
index b4a2efac8e..2b9dabeec0 100644
--- a/tests/discussion_test.php
+++ b/tests/discussion_test.php
@@ -87,7 +87,7 @@ public function test_create_discussion(): void {
$prepost->message = 'a message';
$prepost->messageformat = 1;
$prepost->reviewed = 0;
- $prepost->formattachments = '';
+ $prepost->formattachments = null;
$prepost->modulecontext = $this->modulecontext;
// Log in as the teacher.
diff --git a/tests/generator/lib.php b/tests/generator/lib.php
index 0e9e499140..57ea194432 100644
--- a/tests/generator/lib.php
+++ b/tests/generator/lib.php
@@ -64,28 +64,15 @@ public function reset() {
* @return stdClass
*/
public function create_instance($record = null, ?array $options = null) {
-
- // Transform the record.
- $record = (object) (array) $record;
-
- if (!isset($record->name)) {
- $record->name = 'Test MO Instance';
- }
- if (!isset($record->intro)) {
- $record->intro = 'Test Intro';
- }
- if (!isset($record->introformat)) {
- $record->introformat = 1;
- }
- if (!isset($record->timecreated)) {
- $record->timecreated = time();
- }
- if (!isset($record->timemodified)) {
- $record->timemodified = time();
- }
- if (!isset($record->forcesubscribe)) {
- $record->forcesubscribe = MOODLEOVERFLOW_CHOOSESUBSCRIBE;
- }
+ // Transform the record and set default values if not provided.
+ $record = (object) array_merge([
+ 'name' => 'Test MO Instance',
+ 'intro' => 'Test Intro',
+ 'introformat' => 1,
+ 'timecreated' => time(),
+ 'timemodified' => time(),
+ 'forcesubscribe' => MOODLEOVERFLOW_CHOOSESUBSCRIBE,
+ ], (array) $record);
return parent::create_instance($record, (array) $options);
}
@@ -104,50 +91,32 @@ public function create_discussion($record = null, $forum = null) {
// Increment the discussion count.
$this->discussioncount++;
-
- // Create the record.
$record = (array) $record;
-
- // Check needed submitted values.
- if (!isset($record['course'])) {
- throw new coding_exception('course must be present in phpunit_util:create_discussion() $record');
- }
- if (!isset($record['moodleoverflow'])) {
- throw new coding_exception('moodleoverflow must be present in phpunit_util:create_discussion() $record');
- }
- if (!isset($record['userid'])) {
- throw new coding_exception('userid must be present in phpunit_util:create_discussion() $record');
+ // Ensure required fields are set.
+ foreach (['course', 'moodleoverflow', 'userid'] as $field) {
+ if (empty($record[$field])) {
+ throw new coding_exception("$field must be present in phpunit_util:create_discussion() $record");
+ }
}
// Set default values.
- if (!isset($record['name'])) {
- $record['name'] = 'Discussion ' . $this->discussioncount;
- }
- if (!isset($record['message'])) {
- $record['message'] = html_writer::tag('p', 'Message for discussion ' . $this->discussioncount);
- }
- if (!isset($record['messageformat'])) {
- $record['messageformat'] = editors_get_preferred_format();
- }
- if (!isset($record['timestart'])) {
- $record['timestart'] = "0";
- }
- if (!isset($record['timeend'])) {
- $record['timeend'] = "0";
- }
- if (isset($record['mailed'])) {
- $mailed = $record['mailed'];
- }
- if (isset($record['timemodified'])) {
- $timemodified = $record['timemodified'];
- }
- $record['attachments'] = null;
-
- // Transform the array into an object.
+ $record = array_merge([
+ 'name' => 'Discussion ' . $this->discussioncount,
+ 'message' => html_writer::tag('p', 'Message for discussion ' . $this->discussioncount),
+ 'messageformat' => editors_get_preferred_format(),
+ 'timestart' => "0",
+ 'timeend' => "0",
+ 'attachments' => null,
+ 'draftideditor' => -1,
+ ], (array) $record);
+
+ // Extract optional fields.
+ $mailed = $record['mailed'] ?? null;
+ $timemodified = $record['timemodified'] ?? null;
+
+ // Convert the record to an object.
$record = (object) $record;
- $record->draftideditor = -1;
-
// Get the module context.
$cm = get_coursemodule_from_instance('moodleoverflow', $forum->id);
@@ -188,40 +157,29 @@ public function create_discussion($record = null, $forum = null) {
*/
public function create_post($record = null, $straighttodb = true) {
global $DB;
- // Increment the forum post count.
+
+ // Increment the forum post count and set the current time.
$this->postcount++;
- // Variable to store time.
$time = time() + $this->postcount;
- $record = (array) $record;
- if (!isset($record['discussion'])) {
+
+ // Ensure required fields are set and provide default values.
+ $record = (object) array_merge([
+ 'parent' => 0,
+ 'message' => html_writer::tag('p', 'Forum message post ' . $this->postcount),
+ 'created' => $time,
+ 'modified' => $time,
+ 'mailed' => 0,
+ 'messageformat' => 0,
+ 'attachment' => "",
+ ], (array) $record);
+
+ if (empty($record->discussion)) {
throw new coding_exception('discussion must be present in phpunit_util::create_post() $record');
}
- if (!isset($record['userid'])) {
+ if (empty($record->userid)) {
throw new coding_exception('userid must be present in phpunit_util::create_post() $record');
}
- if (!isset($record['parent'])) {
- $record['parent'] = 0;
- }
- if (!isset($record['message'])) {
- $record['message'] = html_writer::tag('p', 'Forum message post ' . $this->postcount);
- }
- if (!isset($record['created'])) {
- $record['created'] = $time;
- }
- if (!isset($record['modified'])) {
- $record['modified'] = $time;
- }
- if (!isset($record['mailed'])) {
- $record['mailed'] = 0;
- }
- if (!isset($record['messageformat'])) {
- $record['messageformat'] = 0;
- }
- if (!isset($record['attachment'])) {
- $record['attachment'] = "";
- }
- $record = (object) $record;
// Add the post.
if ($straighttodb) {
$record->id = $DB->insert_record('moodleoverflow_posts', $record);
@@ -229,6 +187,7 @@ public function create_post($record = null, $straighttodb = true) {
$record->draftideditor = -1;
$record->id = moodleoverflow_add_new_post($record);
}
+
// Update the last post.
moodleoverflow_discussion_update_last_post($record->discussion);
@@ -246,31 +205,21 @@ public function create_rating($record = null) {
global $DB;
$time = time();
- $record = (array) $record;
- if (!isset($record['moodleoverflowid'])) {
- throw new coding_exception('moodleoverflowid must be present in phpunit_util::create_rating() $record');
- }
- if (!isset($record['discussionid'])) {
- throw new coding_exception('discussionid must be present in phpunit_util::create_rating() $record');
- }
- if (!isset($record['userid'])) {
- throw new coding_exception('userid must be present in phpunit_util::create_rating() $record');
- }
- if (!isset($record['postid'])) {
- throw new coding_exception('postid must be present in phpunit_util::create_rating() $record');
- }
- if (!isset($record['rating'])) {
- $record['rating'] = 1;
- }
- if (!isset($record['firstrated'])) {
- $record['firstrated'] = $time;
- }
- if (!isset($record['lastchanged'])) {
- $record['lastchanged'] = $time;
+ $record = array_merge([
+ 'rating' => 1,
+ 'firstrated' => $time,
+ 'lastchanged' => $time,
+ ], (array) $record);
+
+ // Ensure required fields are set.
+ foreach (['moodleoverflowid', 'discussionid', 'userid', 'postid'] as $field) {
+ if (empty($record[$field])) {
+ throw new coding_exception("$field must be present in phpunit_util::create_rating() \$record");
+ }
}
$record = (object) $record;
- // Add the post.
+ // Add the rating.
$record->id = $DB->insert_record('moodleoverflow_ratings', $record);
return $record;
diff --git a/tests/notification_mail_test.php b/tests/notification_mail_test.php
index d422819b19..0f82986e13 100644
--- a/tests/notification_mail_test.php
+++ b/tests/notification_mail_test.php
@@ -81,8 +81,7 @@ public function tearDown(): void {
* @covers \mod_moodleoverflow\task\send_mails
*/
public function test_sortorder(): void {
- global $DB;
- $result = $this->helper_run_task();
+ $this->helper_run_task();
$this->assertTrue(true);
/* LEARNWEB-TODO: Add tests. A simple test coverage of the notification mails are in review_test.php for now.
They need to be removed from there and added here (+extending test cases). */
@@ -99,7 +98,6 @@ public function test_sortorder(): void {
* - a student in each course.
*/
private function helper_course_set_up(): void {
- global $DB;
$datagenerator = $this->getDataGenerator();
$plugingenerator = $datagenerator->get_plugin_generator('mod_moodleoverflow');
$this->testdata->mailsink = $this->redirectEmails();
diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php
index 28f91775e5..d4f8174c43 100644
--- a/tests/privacy_provider_test.php
+++ b/tests/privacy_provider_test.php
@@ -23,10 +23,6 @@
*/
namespace mod_moodleoverflow;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\userlist;
diff --git a/tests/ratings_test.php b/tests/ratings_test.php
index dc93fad9fa..9040f9e067 100644
--- a/tests/ratings_test.php
+++ b/tests/ratings_test.php
@@ -22,7 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_moodleoverflow;
-use mod_moodleoverflow\ratings;
use stdClass;
defined('MOODLE_INTERNAL') || die();
@@ -39,27 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
final class ratings_test extends \advanced_testcase {
- /** @var stdClass test course */
- private $course;
-
- /** @var stdClass coursemodule */
- private $coursemodule;
-
- /** @var stdClass test moodleoverflow */
- private $moodleoverflow;
-
- /** @var stdClass test teacher */
- private $teacher;
-
- /** @var stdClass test user */
- private $user1;
-
- /** @var stdClass another test user */
- private $user2;
-
- /** @var stdClass a discussion */
- private $discussion;
-
/** @var stdClass a post from the teacher*/
private $post;
@@ -81,9 +59,6 @@ final class ratings_test extends \advanced_testcase {
/** @var stdClass answer from user 2 */
private $answer6;
- /** @var \mod_moodleoverflow_generator $generator */
- private $generator;
-
/**
* Test setUp.
*/
diff --git a/tests/review_test.php b/tests/review_test.php
index be2e381162..c04cb7294d 100644
--- a/tests/review_test.php
+++ b/tests/review_test.php
@@ -24,7 +24,6 @@
namespace mod_moodleoverflow;
-use mod_moodleoverflow\manager\mail_manager;
use mod_moodleoverflow\task\send_mails;
use mod_moodleoverflow\task\send_review_mails;
@@ -258,15 +257,10 @@ private function run_send_notification_mails() {
* @param object|array $actual
*/
private function assert_matches_properties($expected, $actual) {
- global $CFG;
$expected = (array)$expected;
$actual = (object)$actual;
foreach ($expected as $key => $value) {
- if ($CFG->branch >= 404) {
- $this->assertObjectHasProperty($key, $actual, "Failed asserting that attribute '$key' exists.");
- } else {
- $this->assertObjectHasAttribute($key, $actual, "Failed asserting that attribute '$key' exists.");
- }
+ $this->assertObjectHasProperty($key, $actual, "Failed asserting that attribute '$key' exists.");
$this->assertEquals($value, $actual->$key, "Failed asserting that \$obj->$key '" . $actual->$key . "' equals '$value'");
}
}
diff --git a/tests/userstats_test.php b/tests/userstats_test.php
index 4107194693..890beca0cc 100644
--- a/tests/userstats_test.php
+++ b/tests/userstats_test.php
@@ -232,7 +232,6 @@ public function test_total_anonymous(): void {
// Get the current userstats to compare later.
$olduserstats = $this->create_statstable();
- $oldupvotesuser1 = $this->get_specific_userstats($olduserstats, $this->user1, 'receivedupvotes');
$oldactivityuser1 = $this->get_specific_userstats($olduserstats, $this->user1, 'forumactivity');
$oldupvotesuser2 = $this->get_specific_userstats($olduserstats, $this->user2, 'receivedupvotes');
diff --git a/version.php b/version.php
index 4121f57dca..32e56d7e3c 100644
--- a/version.php
+++ b/version.php
@@ -26,9 +26,9 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2025111200;
-$plugin->requires = 2022112819; // Require Moodle 4.1.
+$plugin->version = 2025112700;
+$plugin->requires = 2024100700.00; // Require Moodle 4.5.
$plugin->supported = [405, 501];
$plugin->component = 'mod_moodleoverflow';
-$plugin->maturity = MATURITY_ALPHA;
+$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'v5.1-r1';