-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbehat_mod_moodleoverflow.php
145 lines (127 loc) · 5.7 KB
/
behat_mod_moodleoverflow.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Steps definitions related with the moodleoverflow activity.
*
* @package mod_moodleoverflow
* @category test
* @copyright 2017 KennetWinter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
use Behat\Gherkin\Node\TableNode as TableNode;
/**
* moodleoverflow-related steps definitions.
*
* @package mod_moodleoverflow
* @category test
* @copyright 2017 KennetWinter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_moodleoverflow extends behat_base {
/**
* Adds a topic to the moodleoverflow specified by it's name. Useful for the Announcements and blog-style moodleoverflow.
*
* @Given /^I add a new topic to "(?P<moodleoverflow_name_string>(?:[^"]|\\")*)" moodleoverflow with:$/
* @param string $moodleoverflowname
* @param TableNode $table
*/
public function i_add_a_new_topic_to_moodleoverflow_with($moodleoverflowname, TableNode $table) {
$this->add_new_discussion($moodleoverflowname, $table, get_string('addanewtopic', 'moodleoverflow'));
}
/**
* Adds a discussion to the moodleoverflow specified by it's name with the provided table data
* (usually Subject and Message). The step begins from the moodleoverflow's course page.
*
* @Given /^I add a new discussion to "(?P<moodleoverflow_name_string>(?:[^"]|\\")*)" moodleoverflow with:$/
* @param string $moodleoverflowname
* @param TableNode $table
*/
public function i_add_a_moodleoverflow_discussion_to_moodleoverflow_with($moodleoverflowname, TableNode $table) {
$this->add_new_discussion($moodleoverflowname, $table, get_string('addanewdiscussion', 'moodleoverflow'));
}
/**
* Adds a reply to the specified post of the specified moodleoverflow.
* The step begins from the moodleoverflow's page or from the moodleoverflow's course page.
*
* @Given /^I reply "(?P<post_subject_string>(?:[^"]|\\")*)" post
* from "(?P<moodleoverflow_name_string>(?:[^"]|\\")*)" moodleoverflow with:$/
*
* @param string $postsubject The subject of the post
* @param string $moodleoverflowname The moodleoverflow name
* @param TableNode $table
*/
public function i_reply_post_from_moodleoverflow_with($postsubject, $moodleoverflowname, TableNode $table) {
// Navigate to moodleoverflow.
$this->execute('behat_general::click_link', $this->escape($moodleoverflowname));
$this->execute('behat_general::click_link', $this->escape($postsubject));
$this->execute('behat_general::click_link', get_string('reply', 'moodleoverflow'));
// Fill form and post.
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
$this->execute('behat_forms::press_button', get_string('posttomoodleoverflow', 'moodleoverflow'));
$this->execute('behat_general::i_wait_to_be_redirected');
}
/**
* Returns the steps list to add a new discussion to a moodleoverflow.
*
* Abstracts add a new topic and add a new discussion, as depending
* on the moodleoverflow type the button string changes.
*
* @param string $moodleoverflowname
* @param TableNode $table
* @param string $buttonstr
*/
protected function add_new_discussion($moodleoverflowname, TableNode $table, $buttonstr) {
// Navigate to moodleoverflow.
$this->execute('behat_general::click_link', $this->escape($moodleoverflowname));
$this->execute('behat_forms::press_button', $buttonstr);
// Fill form and post.
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', $table);
$this->execute('behat_forms::press_button', get_string('posttomoodleoverflow', 'moodleoverflow'));
$this->execute('behat_general::i_wait_to_be_redirected');
}
/**
* @Given I go to :link
*/
public function i_go_to($link) {
$this->visitPath($link);
}
/**
* Fills in form field with specified id|name|label|value
* Example: When I fill in "username" with: "bwayne"
* Example: And I fill in "bwayne" for "username"
*
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
* @When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
* @When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
*/
public function fill_field($field, $value) {
$field = $this->fix_step_argument($field);
$value = $this->fix_step_argument($value);
$this->getSession()->getPage()->fillField($field, $value);
}
/**
* Returns fixed step argument (with \\" replaced back to ")
*
* @param string $argument
*
* @return string
*/
protected function fix_step_argument($argument) {
return str_replace('\\"', '"', $argument);
}
}