Merge branch 'MDL-63136-master' of git://github.com/rezaies/moodle
[moodle.git] / mod / data / tests / lib_test.php
index 7405187..84e8a7b 100644 (file)
@@ -1984,4 +1984,29 @@ class mod_data_lib_testcase extends advanced_testcase {
         $this->assertNull($min);
         $this->assertNull($max);
     }
         $this->assertNull($min);
         $this->assertNull($max);
     }
+
+    /**
+     * A user who does not have capabilities to add events to the calendar should be able to create an database.
+     */
+    public function test_creation_with_no_calendar_capabilities() {
+        $this->resetAfterTest();
+        $course = self::getDataGenerator()->create_course();
+        $context = context_course::instance($course->id);
+        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
+        $roleid = self::getDataGenerator()->create_role();
+        self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
+        assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
+        $generator = self::getDataGenerator()->get_plugin_generator('mod_data');
+        // Create an instance as a user without the calendar capabilities.
+        $this->setUser($user);
+        $time = time();
+        $params = array(
+            'course' => $course->id,
+            'timeavailablefrom' => $time + 200,
+            'timeavailableto' => $time + 2000,
+            'timeviewfrom' => $time + 400,
+            'timeviewto' => $time + 2000,
+        );
+        $generator->create_instance($params);
+    }
 }
 }