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/mod/forum/tests/behat/behat_mod_forum.php b/mod/forum/tests/behat/behat_mod_forum.php index 55b3f61bb89..720878d9aa4 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 fill the moodle form with:', $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 fill the moodle form with:', $table), + new Given('I press "' . get_string('posttoforum', 'forum') . '"'), + new Given('I wait to be redirected') + ); + + } + }