Merge branch 'MDL-53140-master' of git://github.com/rezaies/moodle
[moodle.git] / completion / tests / capabilities_test.php
CommitLineData
3f560e80
NM
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Tests that completion works without requiring unnecessary capabilities.
19 *
20 * @package core_completion
21 * @copyright 2018 University of Nottingham
22 * @author Neill Magill <neill.magill@nottingham.ac.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28/**
29 * Tests that completion works without requiring unnecessary capabilities.
30 *
31 * @package core_completion
32 * @copyright 2018 University of Nottingham
33 * @author Neill Magill <neill.magill@nottingham.ac.uk>
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class core_completion_capabilities_testcase extends advanced_testcase {
37 /**
38 * A user who does not have capabilities to add events to the calendar should be able to create activities.
39 */
40 public function test_creation_with_no_calendar_capabilities() {
41 $this->resetAfterTest();
42 $course = self::getDataGenerator()->create_course(['enablecompletion' => 1]);
43 $context = context_course::instance($course->id);
44 $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
45 $roleid = self::getDataGenerator()->create_role();
46 self::getDataGenerator()->role_assign($roleid, $user->id, $context->id);
47 assign_capability('moodle/calendar:manageentries', CAP_PROHIBIT, $roleid, $context, true);
48 $generator = self::getDataGenerator()->get_plugin_generator('mod_forum');
49 // Create an instance as a user without the calendar capabilities.
50 $this->setUser($user);
51 $params = array(
52 'course' => $course->id,
53 'completionexpected' => time() + 2000,
54 );
55 $generator->create_instance($params);
56 }
57}