MDL-45478 Conditional availability: Custom user restriction missing
authorsam marshall <s.marshall@open.ac.uk>
Thu, 8 May 2014 10:57:57 +0000 (11:57 +0100)
committersam marshall <s.marshall@open.ac.uk>
Thu, 8 May 2014 10:57:57 +0000 (11:57 +0100)
There was an error in the JavaScript and custom user field
restrictions did not show correctly when editing the form.

Behat tests didn't cover custom user fields, so I added a
scenario.

availability/condition/profile/tests/behat/availability_profile.feature
availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-debug.js
availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-min.js
availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form.js
availability/condition/profile/yui/src/form/js/form.js

index e4335ed..79c41a1 100644 (file)
@@ -64,3 +64,52 @@ Feature: availability_profile
     # I see P1 but not P2.
     Then I should see "P1" in the "region-main" "region"
     And I should not see "P2" in the "region-main" "region"
+
+  @javascript
+  Scenario: Test with custom user profile field
+    # Add custom field.
+    Given I log in as "admin"
+    And I navigate to "User profile fields" node in "Site administration > Users > Accounts"
+    And I set the field "datatype" to "Text input"
+    And I set the following fields to these values:
+      | Short name | superfield  |
+      | Name       | Super field |
+    And I click on "Save changes" "button"
+
+    # Set field value for user.
+    And I navigate to "Browse list of users" node in "Site administration > Users > Accounts"
+    And I click on "a[title=Edit]" "css_element" in the "s@example.org" "table_row"
+    And I expand all fieldsets
+    And I set the field "Super field" to "Bananaman"
+    And I click on "Update profile" "button"
+
+    # Set Page activity which has requirement on this field.
+    And I am on homepage
+    And I follow "Course 1"
+    And I turn editing mode on
+    And I add a "Page" to section "1"
+    And I set the following fields to these values:
+      | Name         | P1 |
+      | Description  | x  |
+      | Page content | x  |
+    And I expand all fieldsets
+    And I click on "Add restriction..." "button"
+    And I click on "User profile" "button"
+    And I set the following fields to these values:
+      | User profile field       | Super field |
+      | Value to compare against | Bananaman   |
+    And I click on ".availability-item .availability-eye img" "css_element"
+    And I click on "Save and return to course" "button"
+
+    # Edit it again and check the setting still works.
+    When I follow "P1"
+    And I navigate to "Edit settings" node in "Page module administration"
+    And I expand all fieldsets
+    Then the field "User profile field" matches value "Super field"
+    And the field "Value to compare against" matches value "Bananaman"
+
+    # Log out and back in as student. Should be able to see activity.
+    And I log out
+    And I log in as "student1"
+    And I follow "Course 1"
+    Then I should see "P1" in the "region-main" "region"
index 47e4667..0973f47 100644 (file)
Binary files a/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-debug.js and b/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-debug.js differ
index a5addca..f0ab241 100644 (file)
Binary files a/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-min.js and b/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form-min.js differ
index 47e4667..0973f47 100644 (file)
Binary files a/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form.js and b/availability/condition/profile/yui/build/moodle-availability_profile-form/moodle-availability_profile-form.js differ
index ca3f3be..afc486e 100644 (file)
@@ -66,7 +66,7 @@ M.availability_profile.form.getNode = function(json) {
             node.one('select[name=field] > option[value=sf_' + json.sf + ']')) {
         node.one('select[name=field]').set('value', 'sf_' + json.sf);
     } else if (json.cf !== undefined &&
-            node.one('select[name=field] > option[value=cf_' + json.sf + ']')) {
+            node.one('select[name=field] > option[value=cf_' + json.cf + ']')) {
         node.one('select[name=field]').set('value', 'cf_' + json.cf);
     }
     if (json.op !== undefined &&