MDL-54672 behat: Fix i_enrol_user_as() step in non-js sessions
authorDavid Mudrák <david@moodle.com>
Fri, 20 May 2016 18:29:29 +0000 (20:29 +0200)
committerDavid Mudrák <david@moodle.com>
Fri, 20 May 2016 18:37:28 +0000 (20:37 +0200)
During the recent reimplementation of the step (eb9ca848), we did not
notice that javascript variant uses the string `assignroles` while the
non-js variant uses string `assignrole`. This caused any "Given I enrol"
steps to fail in non-javascript sessions.

enrol/tests/behat/behat_enrol.php
enrol/tests/behat/enrol_user.feature [new file with mode: 0644]

index 11c0e22..4b541cd 100644 (file)
@@ -86,9 +86,8 @@ class behat_enrol extends behat_base {
 
         $this->execute("behat_forms::press_button", get_string('enrolusers', 'enrol'));
 
-        $this->execute('behat_forms::i_set_the_field_to', array(get_string('assignroles', 'role'), $rolename));
-
         if ($this->running_javascript()) {
+            $this->execute('behat_forms::i_set_the_field_to', array(get_string('assignroles', 'role'), $rolename));
 
             // We have a div here, not a tr.
             $userliteral = behat_context_helper::escape($userfullname);
@@ -100,6 +99,7 @@ class behat_enrol extends behat_base {
             $this->execute("behat_forms::press_button", get_string('finishenrollingusers', 'enrol'));
 
         } else {
+            $this->execute('behat_forms::i_set_the_field_to', array(get_string('assignrole', 'role'), $rolename));
             $this->execute('behat_forms::i_set_the_field_to', array("addselect", $userfullname));
             $this->execute("behat_forms::press_button", "add");
         }
diff --git a/enrol/tests/behat/enrol_user.feature b/enrol/tests/behat/enrol_user.feature
new file mode 100644 (file)
index 0000000..9166d58
--- /dev/null
@@ -0,0 +1,27 @@
+@enrol
+Feature: User can be enrolled into a course
+  In order to let them participate in course activities
+  As an admin
+  I must be able to enrol users
+
+  Background:
+    Given the following "users" exist:
+      | username | firstname | lastname | email                |
+      | student1 | Studie    | One      | student1@example.com |
+    And the following "courses" exist:
+      | fullname   | shortname |
+      | Course 001 | C001      |
+    And I log in as "admin"
+    And I follow "Courses"
+    And I follow "Course 001"
+
+  Scenario: User can be enrolled without javascript
+    When I enrol "Studie One" user as "Student"
+    And I navigate to "Enrolled users" node in "Course administration > Users"
+    Then I should see "Studie One"
+
+  @javascript
+  Scenario: User can be enrolled with javascript enrol element
+    When I enrol "Studie One" user as "Student"
+    And I navigate to "Enrolled users" node in "Course administration > Users"
+    Then I should see "Studie One"