diff --git a/blocks/news_items/tests/behat/display_news.feature b/blocks/news_items/tests/behat/display_news.feature new file mode 100644 index 00000000000..1768980bd35 --- /dev/null +++ b/blocks/news_items/tests/behat/display_news.feature @@ -0,0 +1,45 @@ +@block @block_news_items +Feature: Latest news block displays the course latest news + In order to be aware of the course news + As a user + I need to see the latest news in the main course page + + @javascript + Scenario: Latest course news are displayed and can be configured + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + And I log in as "admin" + And I create a course with: + | Course full name | Course 1 | + | Course short name | C1 | + | News items to show | 5 | + And I enrol "Teacher 1" user as "Teacher" + And I log out + And I log in as "teacher1" + And I follow "Course 1" + When I add a new topic to "News forum" forum with: + | Subject | Discussion One | + | Message | Not important | + And I add a new topic to "News forum" forum with: + | Subject | Discussion Two | + | Message | Not important | + And I add a new topic to "News forum" forum with: + | Subject | Discussion Three | + | Message | Not important | + And I follow "Course 1" + Then I should see "Discussion One" in the "Latest news" "block" + And I should see "Discussion Two" in the "Latest news" "block" + And I should see "Discussion Three" in the "Latest news" "block" + And I follow "Edit settings" + And I set the following fields to these values: + | News items to show | 2 | + And I press "Save changes" + And I should not see "Discussion One" in the "Latest news" "block" + And I should see "Discussion Two" in the "Latest news" "block" + And I should see "Discussion Three" in the "Latest news" "block" + And I follow "Edit settings" + And I set the following fields to these values: + | News items to show | 0 | + And I press "Save changes" + And "Latest news" "block" should not exist diff --git a/course/tests/behat/course_creation.feature b/course/tests/behat/course_creation.feature new file mode 100644 index 00000000000..668a50dd528 --- /dev/null +++ b/course/tests/behat/course_creation.feature @@ -0,0 +1,31 @@ +@core @core_course +Feature: Managers can create courses + In order to group users and contents + As a manager + I need to create courses and set default values on them + + @javascript + Scenario: Courses are created with the default forum and blocks + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + And I log in as "admin" + And I create a course with: + | Course full name | Course 1 | + | Course short name | C1 | + And I enrol "Teacher 1" user as "Teacher" + And I enrol "Student 1" user as "Student" + And I log out + When I log in as "teacher1" + And I follow "Course 1" + Then "Latest news" "block" should exist + And I follow "News forum" + And "Add a new topic" "button" should exist + And "Forced subscription" "link" should not exist + And I log out + And I log in as "student1" + And I follow "Course 1" + And I follow "News forum" + And "Add a new topic" "button" should not exist + And I should see "Forced subscription" in the "Administration" "block" diff --git a/enrol/tests/behat/behat_enrol.php b/enrol/tests/behat/behat_enrol.php index f3a99ec3e2b..b96c517f786 100644 --- a/enrol/tests/behat/behat_enrol.php +++ b/enrol/tests/behat/behat_enrol.php @@ -58,4 +58,42 @@ class behat_enrol extends behat_base { ); } + /** + * Enrols the specified user in the current course without options. + * + * This is a simple step, to set enrolment options would be better to + * create a separate step as a TableNode will be required. + * + * @Given /^I enrol "(?P(?:[^"]|\\")*)" user as "(?P(?:[^"]|\\")*)"$/ + * @param string $userfullname + * @param string $rolename + * @return Given[] + */ + public function i_enrol_user_as($userfullname, $rolename) { + + $steps = array( + new Given('I follow "' . get_string('enrolledusers', 'enrol') . '"'), + new Given('I press "' . get_string('enrolusers', 'enrol') . '"') + ); + + if ($this->running_javascript()) { + + // We have a div here, not a tr. + $userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname); + $userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]"; + + $steps[] = new Given('I set the field "' . get_string('assignroles', 'role') . '" to "' . $rolename . '"'); + $steps[] = new Given('I click on "' . get_string('enrol', 'enrol') . '" "button" in the "' . $userrowxpath . '" "xpath_element"'); + $steps[] = new Given('I press "' . get_string('finishenrollingusers', 'enrol') . '"'); + + } else { + + $steps[] = new Given('I set the field "' . get_string('assignrole', 'role') . '" to "' . $rolename . '"'); + $steps[] = new Given('I set the field "addselect" to "' . $userfullname . '"'); + $steps[] = new Given('I press "add"'); + } + + return $steps; + } + } diff --git a/mod/forum/tests/behat/behat_mod_forum.php b/mod/forum/tests/behat/behat_mod_forum.php index 95ddeca526d..e95c8b0aa48 100644 --- a/mod/forum/tests/behat/behat_mod_forum.php +++ b/mod/forum/tests/behat/behat_mod_forum.php @@ -39,6 +39,17 @@ use Behat\Behat\Context\Step\Given as Given, */ class behat_mod_forum extends behat_base { + /** + * Adds a topic to the forum specified by it's name. Useful for the News forum and blog-style forums. + * + * @Given /^I add a new topic to "(?P(?:[^"]|\\")*)" forum with:$/ + * @param string $forumname + * @param TableNode $table + */ + public function i_add_a_new_topic_to_forum_with($forumname, TableNode $table) { + return $this->add_new_discussion($forumname, $table, get_string('addanewtopic', 'forum')); + } + /** * 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. * @@ -47,15 +58,7 @@ class behat_mod_forum extends behat_base { * @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 "' . get_string('addanewdiscussion', 'forum') . '"'), - new Given('I set the following fields to these values:', $table), - new Given('I press "' . get_string('posttoforum', 'forum') . '"'), - new Given('I wait to be redirected') - ); + return $this->add_new_discussion($forumname, $table, get_string('addanewdiscussion', 'forum')); } /** @@ -78,4 +81,29 @@ class behat_mod_forum extends behat_base { ); } + + /** + * Returns the steps list to add a new discussion to a forum. + * + * Abstracts add a new topic and add a new discussion, as depending + * on the forum type the button string changes. + * + * @param string $forumname + * @param TableNode $table + * @param string $buttonstr + * @return Given[] + */ + protected function add_new_discussion($forumname, TableNode $table, $buttonstr) { + + // Escaping $forumname as it has been stripped automatically by the transformer. + return array( + new Given('I follow "' . $this->escape($forumname) . '"'), + new Given('I press "' . $buttonstr . '"'), + new Given('I set the following fields to these values:', $table), + new Given('I press "' . get_string('posttoforum', 'forum') . '"'), + new Given('I wait to be redirected') + ); + + } + }