From 6897b44d438e8d711e8eba78dfddd1349a17e837 Mon Sep 17 00:00:00 2001 From: waleedhassan Date: Mon, 24 Jun 2024 14:07:33 +0100 Subject: [PATCH] Moodle 4.4 compatibilty fixes for hsuforum Removed some of the depricated functions and depricated strings that were causing test cases to fail when running on moodle 4.4 Fixed some the test cases as well which were using deprecated functions --- classes/output/big_search_form.php | 2 ++ mod_form.php | 20 ++++++++++++------- post.php | 4 ++-- search.php | 3 +-- tests/behat/accessibility_pin_button.feature | 2 +- tests/behat/add_forum.feature | 4 ++-- ...anced_editor_pass_data_to_new_page.feature | 11 ++++++---- tests/behat/edit_post_student.feature | 2 +- tests/behat/edit_post_teacher.feature | 2 +- .../forum_subscriptions_availability.feature | 8 ++++---- tests/behat/grading_settings.feature | 4 ++-- tests/behat/hsuforum_tags.feature | 4 ++-- tests/behat/inline_edit.feature | 2 +- tests/behat/maintain_start_end_date.feature | 2 +- tests/behat/posts_ordering_blog.feature | 4 ++-- tests/behat/posts_ordering_general.feature | 2 +- tests/behat/rate_posts.feature | 2 +- ...ate_group_single_group_discussions.feature | 4 ++-- tests/behat/split_forum_discussion.feature | 2 +- 19 files changed, 47 insertions(+), 37 deletions(-) diff --git a/classes/output/big_search_form.php b/classes/output/big_search_form.php index 33f559f9..1e441c27 100644 --- a/classes/output/big_search_form.php +++ b/classes/output/big_search_form.php @@ -53,6 +53,8 @@ class big_search_form implements renderable, templatable { public $user; public $words; public $tags; + + public $forumid; /** @var string The URL of the search form. */ public $actionurl; diff --git a/mod_form.php b/mod_form.php index af63bffc..365b1a69 100644 --- a/mod_form.php +++ b/mod_form.php @@ -276,7 +276,7 @@ function standard_grading_coursemodule_elements() { * Adds all the standard elements to a form to edit the settings for an activity module for Hsuforum. */ protected function standard_hsuforum_coursemodule_elements() { - global $COURSE, $CFG, $DB; + global $COURSE, $CFG, $DB, $OUTPUT; $mform =& $this->_form; if (!empty($CFG->core_outcome_enable)) { @@ -370,6 +370,13 @@ protected function standard_hsuforum_coursemodule_elements() { // So it uses a long name that will not conflict. $mform->addElement('textarea', 'availabilityconditionsjson', get_string('accessrestrictions', 'availability')); + // Availability loading indicator. + $loadingcontainer = $OUTPUT->container( + $OUTPUT->render_from_template('core/loading', []), + 'd-flex justify-content-center py-5 icon-size-5', + 'availabilityconditions-loading' + ); + $mform->addElement('html', $loadingcontainer); // The _cm variable may not be a proper cm_info, so get one from modinfo. if ($this->_cm) { $modinfo = get_fast_modinfo($COURSE); @@ -395,7 +402,7 @@ protected function standard_hsuforum_coursemodule_elements() { $trackingdefault = COMPLETION_TRACKING_NONE; // If system and activity default is on, set it. - if ($CFG->completiondefault && $this->_features->defaultcompletion) { + if (!empty($CFG->completiondefault) && $this->_features->defaultcompletion) { $hasrules = plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_HAS_RULES, true); $tracksviews = plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, true); if ($hasrules || $tracksviews) { @@ -414,7 +421,7 @@ protected function standard_hsuforum_coursemodule_elements() { // Automatic completion once you view it $gotcompletionoptions = false; if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) { - $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'), + $mform->addElement('checkbox', 'completionview', '', get_string('completionview_desc', 'completion')); $mform->hideIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); // Check by default if automatic completion tracking is set. @@ -437,11 +444,10 @@ protected function standard_hsuforum_coursemodule_elements() { $mform->addElement( 'checkbox', 'completionusegrade', - get_string('completionusegrade', 'completion'), + '', get_string('completionusegrade_desc', 'completion') ); $mform->hideIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC); - $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion'); // The disabledIf logic differs between ratings and other grade items due to different field types. if ($this->_features->rating) { @@ -675,11 +681,11 @@ protected function add_hsuforum_rating_settings() { $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating')); $mform->hideIf('ratingtime', $assessedfieldname, 'eq', 0); - $mform->addElement('date_time_selector', 'assesstimestart', get_string('from')); + $mform->addElement('date_time_selector', 'assesstimestart', get_string('fromdate')); $mform->hideIf('assesstimestart', $assessedfieldname, 'eq', 0); $mform->hideIf('assesstimestart', 'ratingtime'); - $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to')); + $mform->addElement('date_time_selector', 'assesstimefinish', get_string('todate')); $mform->hideIf('assesstimefinish', $assessedfieldname, 'eq', 0); $mform->hideIf('assesstimefinish', 'ratingtime'); } diff --git a/post.php b/post.php index ed18b3c5..9306eddb 100644 --- a/post.php +++ b/post.php @@ -570,6 +570,7 @@ } $formheading = ''; +$hidehtml = ''; if (!empty($parent)) { $formheading = get_string("yourreply", "hsuforum"); } else { @@ -578,7 +579,6 @@ } else { $formheading = get_string('yournewtopic', 'hsuforum'); // Hide duplicated hsuforum description when creating a new discussion topic, see INT-18928. - $hidehtml = ''; $hidehtml .= html_writer::start_tag('style', array('type' => 'text/css')) . "\n"; $hidehtml .= ' #page-mod-hsuforum-post .activity-description, @@ -586,7 +586,6 @@ display: none; };'; $hidehtml .= html_writer::end_tag('style') . "\n"; - echo $hidehtml; } } @@ -998,6 +997,7 @@ $renderer = $PAGE->get_renderer('mod_hsuforum'); $PAGE->requires->js_init_call('M.mod_hsuforum.init', null, false, $renderer->get_js_module()); echo $OUTPUT->header(); +echo $hidehtml; echo $OUTPUT->heading(format_string($forum->name), 2); // Checkup. diff --git a/search.php b/search.php index d91dbf1d..14e5e3ad 100644 --- a/search.php +++ b/search.php @@ -312,8 +312,7 @@ $post->id ), $post->messageformat, - $options, - $course->id), + $options), 0, '', ''); foreach ($searchterms as $searchterm) { diff --git a/tests/behat/accessibility_pin_button.feature b/tests/behat/accessibility_pin_button.feature index 0aba5f07..2090a8b3 100644 --- a/tests/behat/accessibility_pin_button.feature +++ b/tests/behat/accessibility_pin_button.feature @@ -36,7 +36,7 @@ Feature: When creating a new discussion the unpin option should exist as a butto | teacher1 | C1 | editingteacher | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | diff --git a/tests/behat/add_forum.feature b/tests/behat/add_forum.feature index cb4c75f4..8ce620d0 100644 --- a/tests/behat/add_forum.feature +++ b/tests/behat/add_forum.feature @@ -19,7 +19,7 @@ Feature: Add Open Forum activities and discussions | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | @@ -59,7 +59,7 @@ Feature: Add Open Forum activities and discussions | teacher1 | C1 | editingteacher | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | diff --git a/tests/behat/advanced_editor_pass_data_to_new_page.feature b/tests/behat/advanced_editor_pass_data_to_new_page.feature index 53818e39..05f3be04 100644 --- a/tests/behat/advanced_editor_pass_data_to_new_page.feature +++ b/tests/behat/advanced_editor_pass_data_to_new_page.feature @@ -17,13 +17,14 @@ Feature: Users see their typed information in the advanced editor view when clic | enabletimedposts | 1 | hsuforum | And I log in as "admin" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | And I log out @javascript + @editor_tiny Scenario: User can continue writing after clicking "Use advanced editor" When I log in as "teacher1" And I am on "Course 1" course homepage @@ -39,7 +40,7 @@ Feature: Users see their typed information in the advanced editor view when clic And I should not see "Add your discussion" And I should see "Your new discussion topic" And I set the field with xpath "//*[@id='id_subject']" to "Test discussion 1 to be cancelled" - And I set the field with xpath "//*[@id='id_messageeditable']" to "Test discussion 1 to be cancelled description" + And I set the field with xpath "//*[@id='id_message']" to "Test discussion 1 to be cancelled description" And I press "Post to forum" Then I log out And I log in as "student1" @@ -54,7 +55,7 @@ Feature: Users see their typed information in the advanced editor view when clic And I wait until the page is ready And I should see "Your reply" And I set the field with xpath "//*[@id='id_subject']" to "Test reply subject" - And I set the field with xpath "//*[@id='id_messageeditable']" to "Test reply message" + And I set the field with xpath "//*[@id='id_message']" to "Test reply message" And I press "Post to forum" And I log out And I log in as "teacher1" @@ -68,6 +69,8 @@ Feature: Users see their typed information in the advanced editor view when clic And I set editable div with break line ".hsuforum-post.depth0 .hsuforum-textarea" "css_element" to "This is a reply \n This is a new line" And I click on ".hsuforum-post.depth0 .hsuforum-use-advanced" "css_element" And I wait until the page is ready + And I switch to the "Message" TinyMCE editor iframe And ".text_to_html br" "css_element" should exist + And I switch to the main frame And I should see "Your reply" - And I set the field with xpath "//*[@id='id_messageeditable']" to "This is a reply" + And I set the field with xpath "//*[@id='id_message']" to "This is a reply" diff --git a/tests/behat/edit_post_student.feature b/tests/behat/edit_post_student.feature index a7ed2125..ea031667 100644 --- a/tests/behat/edit_post_student.feature +++ b/tests/behat/edit_post_student.feature @@ -51,7 +51,7 @@ Feature: Students can edit or delete their Open Forum posts within a set time li And I log out And I log in as "admin" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | diff --git a/tests/behat/edit_post_teacher.feature b/tests/behat/edit_post_teacher.feature index dedc60ad..37c85b41 100644 --- a/tests/behat/edit_post_teacher.feature +++ b/tests/behat/edit_post_teacher.feature @@ -18,7 +18,7 @@ Feature: Teachers can edit or delete any Open Forum post | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | And I add a new discussion to "Test forum name" Open Forum with: diff --git a/tests/behat/forum_subscriptions_availability.feature b/tests/behat/forum_subscriptions_availability.feature index b8ad6382..eb092a3c 100644 --- a/tests/behat/forum_subscriptions_availability.feature +++ b/tests/behat/forum_subscriptions_availability.feature @@ -25,7 +25,7 @@ Feature: In Open Forums as a teacher I need to see an accurate list of subscribe @javascript Scenario: A forced forum lists all subscribers - When I add a "Open Forum" to section "1" and I fill the form with: + When I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Forced Forum 1 | | Forum type | Standard forum for general use | | Description | Test forum description | @@ -39,7 +39,7 @@ Feature: In Open Forums as a teacher I need to see an accurate list of subscribe @javascript Scenario: A forced forum does not allow to edit the subscribers - When I add a "Open Forum" to section "1" and I fill the form with: + When I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Forced Forum 2 | | Forum type | Standard forum for general use | | Description | Test forum description | @@ -55,7 +55,7 @@ Feature: In Open Forums as a teacher I need to see an accurate list of subscribe @javascript Scenario: A forced and hidden forum lists only teachers - When I add a "Open Forum" to section "1" and I fill the form with: + When I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Forced Forum 2 | | Forum type | Standard forum for general use | | Description | Test forum description | @@ -70,7 +70,7 @@ Feature: In Open Forums as a teacher I need to see an accurate list of subscribe @javascript Scenario: An automatic forum lists all subscribers - When I add a "Open Forum" to section "1" and I fill the form with: + When I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Forced Forum 1 | | Forum type | Standard forum for general use | | Description | Test forum description | diff --git a/tests/behat/grading_settings.feature b/tests/behat/grading_settings.feature index 1e9bd6d1..3e65b11e 100644 --- a/tests/behat/grading_settings.feature +++ b/tests/behat/grading_settings.feature @@ -39,7 +39,7 @@ Feature: While creating a new activity, the grade settings should remain in the | Grade category 1 | C1 | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | @@ -68,5 +68,5 @@ Feature: While creating a new activity, the grade settings should remain in the # Test forum name Open forum, should exist as a Grade category 1 which is the Grade category chosen before. And I should see "Grade category 1" And I should see "Test forum name" - And "//h4[contains(text(), 'Grade category 1')]" "xpath_element" should exist + And "//div[contains(text(), 'Grade category 1')]" "xpath_element" should exist And "//a[contains(text(), 'Test forum name')]" "xpath_element" should exist diff --git a/tests/behat/hsuforum_tags.feature b/tests/behat/hsuforum_tags.feature index 5744f2fc..df890ee4 100644 --- a/tests/behat/hsuforum_tags.feature +++ b/tests/behat/hsuforum_tags.feature @@ -37,7 +37,7 @@ Feature: Open forum posts and new discussions handle tags correctly, in order to | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | And I add a new discussion to "Test forum name" Open Forum with: @@ -47,7 +47,7 @@ Feature: Open forum posts and new discussions handle tags correctly, in order to Given I log in as "admin" And I navigate to "Appearance > Manage tags" in site administration And I follow "Default collection" - And I follow "Add standard tags" + And I press "Add standard tags" And I set the field "Enter comma-separated list of new tags" to "OT1, OT2, OT3" And I press "Continue" And I log out diff --git a/tests/behat/inline_edit.feature b/tests/behat/inline_edit.feature index e8de4003..7247034f 100644 --- a/tests/behat/inline_edit.feature +++ b/tests/behat/inline_edit.feature @@ -17,7 +17,7 @@ Feature: Teachers and students can add discussions inline | enabletimedposts | 1 | hsuforum | And I log in as "admin" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Forum type | Standard forum for general use | | Description | Test forum description | diff --git a/tests/behat/maintain_start_end_date.feature b/tests/behat/maintain_start_end_date.feature index e9631fdd..75d30dbf 100644 --- a/tests/behat/maintain_start_end_date.feature +++ b/tests/behat/maintain_start_end_date.feature @@ -17,7 +17,7 @@ Feature: In Open Forums users can change start and end date and the changes rema And the following config values are set as admin: | enabletimedposts | 1 | hsuforum | And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | And I add a new discussion to "Test forum name" Open Forum with: diff --git a/tests/behat/posts_ordering_blog.feature b/tests/behat/posts_ordering_blog.feature index 723d427c..30bcc33a 100644 --- a/tests/behat/posts_ordering_blog.feature +++ b/tests/behat/posts_ordering_blog.feature @@ -18,7 +18,7 @@ Feature: In Open Forums, blog posts are always displayed in reverse chronologica | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Course blog forum | | Description | Single discussion forum description | | Forum type | Standard forum displayed in a blog-like format | @@ -65,7 +65,7 @@ Feature: In Open Forums, blog posts are always displayed in reverse chronologica And I follow "Blog post 1" And I follow "Reply" And I follow "Use advanced editor and additional options" - And I set the field with xpath "//*[@id='id_messageeditable']" to "Reply to the first post" + And I set the field with xpath "//*[@id='id_message']" to "Reply to the first post" And I press "Post to forum" And I wait to be redirected to open forum And I am on "Course 1" course homepage diff --git a/tests/behat/posts_ordering_general.feature b/tests/behat/posts_ordering_general.feature index 48f56882..2013f81f 100644 --- a/tests/behat/posts_ordering_general.feature +++ b/tests/behat/posts_ordering_general.feature @@ -18,7 +18,7 @@ Feature: New Open discussions and discussions with recently added replies are di | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Course general forum | | Description | Single discussion forum description | | Forum type | Standard forum for general use | diff --git a/tests/behat/rate_posts.feature b/tests/behat/rate_posts.feature index 07af4cbd..22d151a7 100644 --- a/tests/behat/rate_posts.feature +++ b/tests/behat/rate_posts.feature @@ -18,7 +18,7 @@ Feature: Users can rate other users forum posts | student1 | C1 | student | And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Test forum name | | Description | Test forum description | | Aggregate type | Average of ratings | diff --git a/tests/behat/separate_group_single_group_discussions.feature b/tests/behat/separate_group_single_group_discussions.feature index e3b1d8ec..c7515480 100644 --- a/tests/behat/separate_group_single_group_discussions.feature +++ b/tests/behat/separate_group_single_group_discussions.feature @@ -40,13 +40,13 @@ Feature: In Open Forums, posting to groups in a separate group discussion when r | G2 | G2G1 | And I log in as "admin" And I am on "Course 1" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Multiple groups forum | | Forum type | Standard forum for general use | | Description | Standard forum description | | Group mode | Separate groups | | Grouping | G1 | - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Course 1" section "1" and I fill the form with: | Forum name | Single groups forum | | Forum type | Standard forum for general use | | Description | Standard forum description | diff --git a/tests/behat/split_forum_discussion.feature b/tests/behat/split_forum_discussion.feature index 33ddcc6e..905e4ca4 100644 --- a/tests/behat/split_forum_discussion.feature +++ b/tests/behat/split_forum_discussion.feature @@ -18,7 +18,7 @@ Feature: Open Forum discussions can be split | student1 | C1 | student | And I log in as "teacher1" And I am on "Science 101" course homepage with editing mode on - And I add a "Open Forum" to section "1" and I fill the form with: + And I add a "hsuforum" activity to course "Science 101" section "1" and I fill the form with: | Forum name | Study discussions | | Forum type | Standard forum for general use | | Description | Forum to discuss your coursework. |