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; + } + }