first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+99
View File
@@ -0,0 +1,99 @@
<?php
/**
* Aids in capability assignment and alteration of the assigned capability.
*
* @package core_course
* @copyright 2013 Sam Hemelryk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_capability_assignment {
/**
* @var array The capability that has been assigned.
*/
protected $capability;
/**
* @var int The role ID that the assignment was made for.
*/
protected $roleid;
/**
* @var int The context ID against which the assignment was made.
*/
protected $contextid;
/**
* Assigns a capability to a role at the given context giving it permission.
*
* @param string|array $capability The capability to assign.
* @param int $roleid The roleID to assign to.
* @param int $contextid The contextID for where to make the assignment.
* @return course_capability_assignment
*/
public static function allow($capability, $roleid, $contextid) {
return new course_capability_assignment($capability, $roleid, $contextid, CAP_ALLOW);
}
/**
* Assigns a capability to a role at the given context prohibiting it.
*
* @param string|array $capability The capability to assign.
* @param int $roleid The roleID to assign to.
* @param int $contextid The contextID for where to make the assignment.
* @return course_capability_assignment
*/
public static function prohibit($capability, $roleid, $contextid) {
return new course_capability_assignment($capability, $roleid, $contextid, CAP_PROHIBIT);
}
/**
* Assigns a capability to a role at the given context preventing it.
*
* @param string|array $capability The capability to assign.
* @param int $roleid The roleID to assign to.
* @param int $contextid The contextID for where to make the assignment.
* @return course_capability_assignment
*/
public static function prevent($capability, $roleid, $contextid) {
return new course_capability_assignment($capability, $roleid, $contextid, CAP_PREVENT);
}
/**
* Creates a new course_capability_assignment object
*
* @param string|array $capability The capability to assign.
* @param int $roleid The roleID to assign to.
* @param int $contextid The contextID for where to make the assignment.
* @param int $permission The permission to apply. One of CAP_ALLOW, CAP_PROHIBIT, CAP_PREVENT.
* @return course_capability_assignment
*/
protected function __construct($capability, $roleid, $contextid, $permission) {
if (is_string($capability)) {
$capability = array($capability);
}
$this->capability = $capability;
$this->roleid = $roleid;
$this->contextid = $contextid;
$this->assign($permission);
}
/**
* Assign a new permission.
* @param int $permission One of CAP_ALLOW, CAP_PROHIBIT, CAP_PREVENT
*/
public function assign($permission) {
foreach ($this->capability as $capability) {
assign_capability($capability, $permission, $this->roleid, $this->contextid, true);
}
accesslib_clear_all_caches_for_unit_testing();
}
/**
* Revokes the capability assignment.
*/
public function revoke() {
foreach ($this->capability as $capability) {
unassign_capability($capability, $this->roleid, $this->contextid);
}
accesslib_clear_all_caches_for_unit_testing();
}
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

+186
View File
@@ -0,0 +1,186 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Fixture for mocking callbacks used in \core_course_category
*
* @package core_course
* @category test
* @copyright 2020 Ruslan Kabalin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_course\test {
/**
* Class mock_hooks
*
* @package core_course
* @category test
* @copyright 2020 Ruslan Kabalin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mock_hooks {
/** @var bool $cancoursecategorydelete */
private static $cancoursecategorydelete = true;
/** @var bool $cancoursecategorydeletemove */
private static $cancoursecategorydeletemove = true;
/** @var string $getcoursecategorycontents */
private static $getcoursecategorycontents = '';
/** @var array $callingarguments */
private static $callingarguments = [];
/**
* Set calling arguments.
*
* This is supposed to be used in the callbacks to store arguments passed to callback.
*
* @param array $callingarguments
*/
public static function set_calling_arguments($callingarguments) {
self::$callingarguments = $callingarguments;
}
/**
* Get calling arguments.
*
* This is supposed to be used in the test to verify arguments passed to callback.
* This method also reset stored calling arguments.
*
* @return array $callingarguments
*/
public static function get_calling_arguments() {
$callingarguments = self::$callingarguments;
self::$callingarguments = [];
return $callingarguments;
}
/**
* Get can_course_category_delete callback return.
*
* @return bool
*/
public static function get_can_course_category_delete_return(): bool {
return self::$cancoursecategorydelete;
}
/**
* Sets can_course_category_delete callback return.
*
* @param bool $return
*/
public static function set_can_course_category_delete_return(bool $return) {
self::$cancoursecategorydelete = $return;
}
/**
* Get can_course_category_delete_move callback return.
*
* @return bool
*/
public static function get_can_course_category_delete_move_return(): bool {
return self::$cancoursecategorydeletemove;
}
/**
* Sets can_course_category_delete_move callback return.
*
* @param bool $return
*/
public static function set_can_course_category_delete_move_return(bool $return) {
self::$cancoursecategorydeletemove = $return;
}
/**
* Get get_course_category_contents callback return.
*
* @return string
*/
public static function get_get_course_category_contents_return(): string {
return self::$getcoursecategorycontents;
}
/**
* Sets get_course_category_contents callback return.
*
* @param string $return
*/
public static function set_get_course_category_contents_return(string $return) {
self::$getcoursecategorycontents = $return;
}
}
}
namespace {
use core_course\test\mock_hooks;
/**
* Test pre_course_category_delete callback.
*
* @param object $category
*/
function tool_unittest_pre_course_category_delete(object $category) {
mock_hooks::set_calling_arguments(func_get_args());
}
/**
* Test pre_course_category_delete_move callback.
*
* @param core_course_category $category
* @param core_course_category $newcategory
*/
function tool_unittest_pre_course_category_delete_move(core_course_category $category, core_course_category $newcategory) {
mock_hooks::set_calling_arguments(func_get_args());
}
/**
* Test can_course_category_delete callback.
*
* @param core_course_category $category
* @return bool
*/
function tool_unittest_can_course_category_delete(core_course_category $category) {
mock_hooks::set_calling_arguments(func_get_args());
return mock_hooks::get_can_course_category_delete_return();
}
/**
* Test can_course_category_delete_move callback.
*
* @param core_course_category $category
* @param core_course_category $newcategory
* @return bool
*/
function tool_unittest_can_course_category_delete_move(core_course_category $category, core_course_category $newcategory) {
mock_hooks::set_calling_arguments(func_get_args());
return mock_hooks::get_can_course_category_delete_move_return();
}
/**
* Test get_course_category_contents callback.
*
* @param core_course_category $category
* @return string
*/
function tool_unittest_get_course_category_contents(core_course_category $category) {
mock_hooks::set_calling_arguments(func_get_args());
return mock_hooks::get_get_course_category_contents_return();
}
}
+49
View File
@@ -0,0 +1,49 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Testable course edit form.
*
* @package core_course
* @category test
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/course/edit_form.php');
/**
* Testable course edit form.
*
* @package core_course
* @category test
* @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_course_edit_form extends course_edit_form {
/**
* Expose the internal moodleform's MoodleQuickForm
*
* @return MoodleQuickForm
*/
public function get_quick_form() {
return $this->_form;
}
}