Merge branch 'MDL-66876-master' of git://github.com/jleyva/moodle
authorAdrian Greeve <abgreeve@gmail.com>
Thu, 24 Oct 2019 07:14:45 +0000 (15:14 +0800)
committerAdrian Greeve <abgreeve@gmail.com>
Thu, 24 Oct 2019 07:14:45 +0000 (15:14 +0800)
filter/classes/external.php
filter/tests/external_test.php

index ed6218f..07911a9 100644 (file)
@@ -85,7 +85,7 @@ class external extends external_api {
             } catch (Exception $e) {
                 $warnings[] = array(
                     'item' => 'context',
-                    'itemid' => $context['instanceid'],
+                    'itemid' => $contextinfo['instanceid'],
                     'warningcode' => $e->getCode(),
                     'message' => $e->getMessage(),
                 );
index 71bdef4..17796a3 100644 (file)
@@ -187,5 +187,14 @@ class core_filter_external_testcase extends externallib_advanced_testcase {
         $this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled globally.
         $this->assertEquals(TEXTFILTER_OFF, $result['filters'][0]['localstate']); // It is not available in this context.
         $this->assertEquals(TEXTFILTER_ON, $result['filters'][0]['inheritedstate']); // In the parent context is available.
+
+        // Try user without permission, warning expected.
+        $user = $this->getDataGenerator()->create_user();
+        $this->setUser($user);
+        $result = external::get_available_in_context(array(array('contextlevel' => 'module', 'instanceid' => $forum->cmid)));
+        $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+        $this->assertNotEmpty($result['warnings']);
+        $this->assertEquals('context', $result['warnings'][0]['item']);
+        $this->assertEquals($forum->cmid, $result['warnings'][0]['itemid']);
     }
 }