Skip to content

Commit 00cb2c1

Browse files
INT-19116: Fix hsuforum deprecations for Behat tests
1 parent 7ae62a7 commit 00cb2c1

12 files changed

+99
-33
lines changed

lib/discussion/sort.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function disable($key) {
228228
* @return string the string representation of the object or &null;
229229
*/
230230
public function serialize() {
231-
return serialize(array('key' => $this->get_key(), 'direction' => $this->get_direction()));
231+
return serialize($this->__serialize());
232232
}
233233

234234
/**
@@ -242,11 +242,24 @@ public function serialize() {
242242
* @return void
243243
*/
244244
public function unserialize($serialized) {
245-
$sortinfo = unserialize($serialized);
245+
$serialized = unserialize($serialized);
246+
$this->__unserialize($serialized);
247+
}
246248

249+
/**
250+
* @return array
251+
*/
252+
public function __serialize() {
253+
return array('key' => $this->get_key(), 'direction' => $this->get_direction());
254+
}
255+
256+
/**
257+
* @return void
258+
*/
259+
public function __unserialize($serialized) {
247260
try {
248-
$this->set_key($sortinfo['key'])
249-
->set_direction($sortinfo['direction']);
261+
$this->set_key($serialized['key'])
262+
->set_direction($serialized['direction']);
250263
} catch (Exception $e) {
251264
// Ignore...
252265
}

tests/behat/anon_posting.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Feature: Students can post anonymously or not if they choose
3535
| Subject | Anon post subject |
3636
| Message | Anon post body |
3737
And I press "Post to forum"
38-
And I wait to be redirected
38+
And I wait to be redirected to open forum
3939
Then I should see "Anon post subject"
4040
And I should see "Anon post body"
4141
And I should not see "Anonymous User"
@@ -58,7 +58,7 @@ Feature: Students can post anonymously or not if they choose
5858
| Message | Non-anon post body |
5959
| Reveal yourself in this post | 1 |
6060
And I press "Post to forum"
61-
And I wait to be redirected
61+
And I wait to be redirected to open forum
6262
Then I should see "Non-anon post subject"
6363
And I should see "Non-anon post body"
6464
And I should see "Non anonymously"
@@ -82,7 +82,7 @@ Feature: Students can post anonymously or not if they choose
8282
| Message | Edited post body |
8383
| Reveal yourself in this post | 1 |
8484
And I press "Save changes"
85-
And I wait to be redirected
85+
And I wait to be redirected to open forum
8686
Then I should see "Edited post subject"
8787
And I should see "Edited post body"
8888
And I should see "Non anonymously"

tests/behat/behat_mod_hsuforum.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function add_new_discussion($forumname, TableNode $table, $buttonstr)
110110
// Fill form and post.
111111
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
112112
$this->execute('behat_forms::press_button', get_string('posttoforum', 'hsuforum'));
113-
$this->execute('behat_general::i_wait_to_be_redirected');
113+
$this->execute('behat_mod_hsuforum::i_wait_to_be_redirected_to_open_forum');
114114
}
115115

116116
/**
@@ -343,4 +343,57 @@ function($context, $iframename) {
343343
behat_base::get_extended_timeout()
344344
);
345345
}
346+
347+
/**
348+
* Follows the page redirection. Use this step after any action that shows a message and waits for a redirection.
349+
* Based on i_wait_to_be_redirected from behat_general.
350+
*
351+
* @Given /^I wait to be redirected to open forum$/
352+
*/
353+
public function i_wait_to_be_redirected_to_open_forum () {
354+
355+
// Xpath and processes based on core_renderer::redirect_message(), core_renderer::$metarefreshtag and
356+
// moodle_page::$periodicrefreshdelay possible values.
357+
if (!$metarefresh = $this->getSession()->getPage()->find('xpath', "//head/descendant::meta[@http-equiv='refresh']")) {
358+
// We don't fail the scenario if no redirection with message is found to avoid race condition false failures.
359+
return true;
360+
}
361+
362+
// Wrapped in try & catch in case the redirection has already been executed.
363+
try {
364+
$content = $metarefresh->getAttribute('content');
365+
} catch (NoSuchElementException $e) {
366+
return true;
367+
} catch (StaleElementReferenceException $e) {
368+
return true;
369+
}
370+
371+
// Getting the refresh time and the url if present.
372+
if (strstr($content, 'url') != false) {
373+
374+
list($waittime, $url) = explode(';', $content);
375+
376+
// Cleaning the URL value.
377+
$url = trim(substr($url, strpos($url, 'http')));
378+
379+
} else {
380+
// Just wait then.
381+
$waittime = $content;
382+
}
383+
384+
385+
// Wait until the URL change is executed.
386+
if ($this->running_javascript()) {
387+
$this->getSession()->wait($waittime * 1000);
388+
389+
} else if (!empty($url)) {
390+
// We redirect directly as we can not wait for an automatic redirection.
391+
$this->getSession()->getDriver()->getClient()->request('GET', $url);
392+
393+
} else {
394+
// Reload the page if no URL was provided.
395+
$this->getSession()->getDriver()->reload();
396+
}
397+
}
398+
346399
}

tests/behat/discussion_navigation.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Background:
6262
And I set the following fields to these values:
6363
| Message | Answer to discussion |
6464
And I press "Post to forum"
65-
And I wait to be redirected
65+
And I wait to be redirected to open forum
6666
And I should not see "Discussion 2"
6767
And I should see "Discussion 3"
6868
And I follow "Discussion 3"

tests/behat/edit_post_student.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Feature: Students can edit or delete their Open Forum posts within a set time li
3232
| Subject | Edited post subject |
3333
| Message | Edited post body |
3434
And I press "Save changes"
35-
And I wait to be redirected
35+
And I wait to be redirected to open forum
3636
Then I should see "Edited post subject"
3737
And I should see "Edited post body"
3838

tests/behat/edit_post_teacher.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Feature: Teachers can edit or delete any Open Forum post
5656
And I set the following fields to these values:
5757
| Subject | Edited student subject |
5858
And I press "Save changes"
59-
And I wait to be redirected
59+
And I wait to be redirected to open forum
6060
Then I should see "Edited student subject"
6161
And I should see "Edited by Teacher 1 - original submission"
6262

tests/behat/groups_in_course_no_groups_in_forum.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Feature: Open Forums in 'No groups' mode allow posting to All participants for a
4242
| Subject | Teacher 1 -> Forum |
4343
| Message | Teacher 1 -> Forum |
4444
And I press "Post to forum"
45-
And I wait to be redirected
45+
And I wait to be redirected to open forum
4646
And I should see "Teacher 1 -> Forum"
4747

4848
@javascript
@@ -73,7 +73,7 @@ Feature: Open Forums in 'No groups' mode allow posting to All participants for a
7373
| Subject | Student 1 -> Forum |
7474
| Message | Student 1 -> Forum |
7575
And I press "Post to forum"
76-
And I wait to be redirected
76+
And I wait to be redirected to open forum
7777
And I should see "Student 1 -> Forum"
7878

7979
@javascript

tests/behat/no_groups_in_course.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Feature: Posting to Open Forums in a course with no groups behaves correctly
2929
| Subject | Teacher -> All participants |
3030
| Message | Teacher -> All participants |
3131
And I press "Post to forum"
32-
And I wait to be redirected
32+
And I wait to be redirected to open forum
3333
And I should see "Teacher -> All participants"
3434

3535
Scenario: Teachers can post in forum with separate groups
@@ -42,7 +42,7 @@ Feature: Posting to Open Forums in a course with no groups behaves correctly
4242
| Subject | Teacher -> All participants |
4343
| Message | Teacher -> All participants |
4444
And I press "Post to forum"
45-
And I wait to be redirected
45+
And I wait to be redirected to open forum
4646
And I should see "Teacher -> All participants"
4747

4848
Scenario: Teachers can post in forum with visible groups
@@ -55,7 +55,7 @@ Feature: Posting to Open Forums in a course with no groups behaves correctly
5555
| Subject | Teacher -> All participants |
5656
| Message | Teacher -> All participants |
5757
And I press "Post to forum"
58-
And I wait to be redirected
58+
And I wait to be redirected to open forum
5959
And I should see "Teacher -> All participants"
6060

6161
Scenario: Students can post in standard forum
@@ -68,7 +68,7 @@ Feature: Posting to Open Forums in a course with no groups behaves correctly
6868
| Subject | Student -> All participants |
6969
| Message | Student -> All participants |
7070
And I press "Post to forum"
71-
And I wait to be redirected
71+
And I wait to be redirected to open forum
7272
And I should see "Student -> All participants"
7373

7474
@javascript

tests/behat/posts_ordering_blog.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Feature: In Open Forums, blog posts are always displayed in reverse chronologica
5454
And I set the following fields to these values:
5555
| Subject | Edited blog post 2 |
5656
And I press "Submit"
57-
And I wait to be redirected
57+
And I wait to be redirected to open forum
5858
And I log out
5959
#
6060
# Reply to another blog post.
@@ -67,7 +67,7 @@ Feature: In Open Forums, blog posts are always displayed in reverse chronologica
6767
And I follow "Use advanced editor and additional options"
6868
And I set the field with xpath "//*[@id='id_messageeditable']" to "Reply to the first post"
6969
And I press "Post to forum"
70-
And I wait to be redirected
70+
And I wait to be redirected to open forum
7171
And I am on "Course 1" course homepage
7272
And I am on the "Course blog forum" "hsuforum activity" page
7373
#

tests/behat/posts_ordering_general.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Feature: New Open discussions and discussions with recently added replies are di
5454
And I set the following fields to these values:
5555
| Subject | Edited forum post 2 |
5656
And I press "Submit"
57-
And I wait to be redirected
57+
And I wait to be redirected to open forum
5858
And I log out
5959
#
6060
# Reply to another forum post.
@@ -67,7 +67,7 @@ Feature: New Open discussions and discussions with recently added replies are di
6767
And I set the following fields to these values:
6868
| Message | Reply to the first post |
6969
And I press "Post to forum"
70-
And I wait to be redirected
70+
And I wait to be redirected to open forum
7171
And I am on "Course 1" course homepage
7272
And I am on the "Course general forum" "hsuforum activity" page
7373
#

0 commit comments

Comments
 (0)