MDL-38659 environment: verify feedback matches levels
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 24 Mar 2013 01:13:52 +0000 (02:13 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 26 Mar 2013 14:34:06 +0000 (15:34 +0100)
lib/environmentlib.php

index be7aabf..3d8a0df 100644 (file)
@@ -70,6 +70,10 @@ defined('MOODLE_INTERNAL') || die();
     define('CUSTOM_CHECK_FUNCTION_MISSING',     14);
     /** XML Processing Error */
     define('NO_PHP_SETTINGS_NAME_FOUND',        15);
+    /** XML Processing Error */
+    define('INCORRECT_FEEDBACK_FOR_REQUIRED',   16);
+    /** XML Processing Error */
+    define('INCORRECT_FEEDBACK_FOR_OPTIONAL',   17);
 
 /// Define algorithm used to select the xml file
     /** To select the newer file available to perform checks */
@@ -1066,6 +1070,8 @@ function process_environment_restrict($xml, &$result) {
  * This function will detect if there is some message available to be added to the
  * result in order to clarify enviromental details.
  *
+ * @uses INCORRECT_FEEDBACK_FOR_REQUIRED
+ * @uses INCORRECT_FEEDBACK_FOR_OPTIONAL
  * @param string xmldata containing the feedback data
  * @param object reult object to be updated
  */
@@ -1075,6 +1081,15 @@ function process_environment_messages($xml, &$result) {
     if (is_array($xml['#']) && isset($xml['#']['FEEDBACK'][0]['#'])) {
         $feedbackxml = $xml['#']['FEEDBACK'][0]['#'];
 
+        // Detect some incorrect feedback combinations.
+        if ($result->getLevel() == 'required' and isset($feedbackxml['ON_CHECK'])) {
+            $result->setStatus(false);
+            $result->setErrorCode(INCORRECT_FEEDBACK_FOR_REQUIRED);
+        } else if ($result->getLevel() == 'optional' and isset($feedbackxml['ON_ERROR'])) {
+            $result->setStatus(false);
+            $result->setErrorCode(INCORRECT_FEEDBACK_FOR_OPTIONAL);
+        }
+
         if (!$result->status and $result->getLevel() == 'required') {
             if (isset($feedbackxml['ON_ERROR'][0]['@']['message'])) {
                 $result->setFeedbackStr($feedbackxml['ON_ERROR'][0]['@']['message']);