From 279d86943bdf921677f4f925a46091b579cbabdf Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 12 Mar 2013 15:47:30 +0800 Subject: [PATCH 1/2] MDL-38437 behat: Step definition to add a discussion --- mod/forum/tests/behat/behat_mod_forum.php | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 mod/forum/tests/behat/behat_mod_forum.php diff --git a/mod/forum/tests/behat/behat_mod_forum.php b/mod/forum/tests/behat/behat_mod_forum.php new file mode 100644 index 00000000000..9183a19229d --- /dev/null +++ b/mod/forum/tests/behat/behat_mod_forum.php @@ -0,0 +1,61 @@ +. + +/** + * Steps definitions related with the forum activity. + * + * @package mod_forum + * @category test + * @copyright 2013 David Monllaó + * @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\Behat\Context\Step\Given as Given, + Behat\Gherkin\Node\TableNode as TableNode; +/** + * Forum-related steps definitions. + * + * @package mod_forum + * @category test + * @copyright 2013 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_mod_forum extends behat_base { + + /** + * Adds a discussion to the forum specified by it's name with the provided table data (usually Subject and Message). The step begins from the forum's course page. + * + * @Given /^I add a new discussion to "(?P(?:[^"]|\\")*)" forum with:$/ + * @param string $forumname + * @param TableNode $table + */ + public function i_add_a_forum_discussion_to_forum_with($forumname, TableNode $table) { + + // Escaping $forumname as it has been stripped automatically by the transformer. + return array( + new Given('I follow "' . $this->escape($forumname) . '"'), + new Given('I press "Add a new discussion topic"'), + new Given('I fill the moodle form with:', $table), + new Given('I press "Post to forum"'), + new Given('I wait "5" seconds') + ); + } + +} From e6cb6aed64e30149d0225d6f9200519936c6763e Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 12 Mar 2013 15:48:27 +0800 Subject: [PATCH 2/2] MDL-38437 behat: Behat feature for mod_forum Basic add an activity, MDLQA-2 (students can edit or delete their forum posts within a set time limit). --- mod/forum/tests/behat/add_forum.feature | 29 +++++++++ .../tests/behat/edit_post_student.feature | 62 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 mod/forum/tests/behat/add_forum.feature create mode 100644 mod/forum/tests/behat/edit_post_student.feature diff --git a/mod/forum/tests/behat/add_forum.feature b/mod/forum/tests/behat/add_forum.feature new file mode 100644 index 00000000000..80466ea6097 --- /dev/null +++ b/mod/forum/tests/behat/add_forum.feature @@ -0,0 +1,29 @@ +@mod_forum +Feature: Add forum activities and discussions + In order to discuss topics with other users + As a moodle teacher + I need to add forum activities to moodle courses + + @javascript + Scenario: Add a forum and a discussion + Given the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + And the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "forum" to section "1" and I fill the form with: + | Forum name | Test forum name | + | Forum type | Standard forum for general use | + | Description | Test forum description | + When I add a new discussion to "Test forum name" forum with: + | Subject | Forum post 1 | + | Message | This is the body | + And I wait "6" seconds + Then I should see "Test forum name" diff --git a/mod/forum/tests/behat/edit_post_student.feature b/mod/forum/tests/behat/edit_post_student.feature new file mode 100644 index 00000000000..e693af64230 --- /dev/null +++ b/mod/forum/tests/behat/edit_post_student.feature @@ -0,0 +1,62 @@ +@mod_forum +Feature: Students can edit or delete their forum posts within a set time limit + In order to refine forum posts + As a moodle user + I need to edit or delete my forum posts within a certain period of time after posting + + Background: + Given the following "users" exists: + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@asd.com | + And the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exists: + | user | course | role | + | student1 | C1 | student | + And I log in as "admin" + And I expand "Site administration" node + And I expand "Security" node + And I follow "Site policies" + And I select "1 minutes" from "Maximum time to edit posts" + And I press "Save changes" + And I am on homepage + And I follow "Course 1" + And I turn editing mode on + And I add a "forum" to 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 + And I follow "Course 1" + And I log in as "student1" + And I add a new discussion to "Test forum name" forum with: + | Subject | Forum post subject | + | Message | This is the body | + And I wait "6" seconds + + @javascript + Scenario: Edit forum post + When I follow "Forum post subject" + And I follow "Edit" + And I fill the moodle form with: + | Subject | Edited post subject | + | Message | Edited post body | + And I press "Save changes" + And I wait "6" seconds + Then I should see "Edited post subject" + And I should see "Edited post body" + + @javascript + Scenario: Delete forum post + When I follow "Forum post subject" + And I follow "Delete" + And I press "Continue" + Then I should not see "Forum post subject" + + @javascript + Scenario: Time limit expires + When I wait "70" seconds + And I follow "Forum post subject" + Then I should not see "Edit" + And I should not see "Delete"