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
@@ -0,0 +1,95 @@
<?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/>.
/**
* @package block_glossary_random
* @subpackage backup-moodle2
* @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Specialised restore task for the glossary_random block
* (using execute_after_tasks for recoding of glossaryid)
*
* TODO: Finish phpdocs
*/
class restore_glossary_random_block_task extends restore_block_task {
protected function define_my_settings() {
}
protected function define_my_steps() {
}
public function get_fileareas() {
return array(); // No associated fileareas
}
public function get_configdata_encoded_attributes() {
return array(); // No special handling of configdata
}
/**
* This function, executed after all the tasks in the plan
* have been executed, will perform the recode of the
* target glossary for the block. This must be done here
* and not in normal execution steps because the glossary
* may be restored after the block.
*/
public function after_restore() {
global $DB;
// Get the blockid
$blockid = $this->get_blockid();
// Extract block configdata and update it to point to the new glossary
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = $this->decode_configdata($configdata);
if (!empty($config->glossary)) {
if ($glossarymap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $config->glossary)) {
// Get glossary mapping and replace it in config
$config->glossary = $glossarymap->newitemid;
} else if ($this->is_samesite()) {
// We are restoring on the same site, check if glossary can be used in the block in this course.
$glossaryid = $DB->get_field_sql("SELECT id FROM {glossary} " .
"WHERE id = ? AND (course = ? OR globalglossary = 1)",
[$config->glossary, $this->get_courseid()]);
if (!$glossaryid) {
unset($config->glossary);
}
} else {
// The block refers to a glossary not present in the backup file.
unset($config->glossary);
}
// Unset config variables that are no longer used.
unset($config->globalglossary);
unset($config->courseid);
// Save updated config.
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}
}
public static function define_decode_contents() {
return array();
}
public static function define_decode_rules() {
return array();
}
}
@@ -0,0 +1,287 @@
<?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/>.
/**
* Glossary Random block.
*
* @package block_glossary_random
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('BGR_RANDOMLY', '0');
define('BGR_LASTMODIFIED', '1');
define('BGR_NEXTONE', '2');
define('BGR_NEXTALPHA', '3');
class block_glossary_random extends block_base {
/**
* @var cm_info|stdClass has properties 'id' (course module id) and 'uservisible'
* (whether the glossary is visible to the current user)
*/
protected $glossarycm = null;
/** @var stdClass course data. */
public $course;
function init() {
$this->title = get_string('pluginname','block_glossary_random');
}
function specialization() {
global $CFG, $DB;
require_once($CFG->libdir . '/filelib.php');
$this->course = $this->page->course;
// load userdefined title and make sure it's never empty
if (empty($this->config->title)) {
$this->title = get_string('pluginname','block_glossary_random');
} else {
$this->title = format_string($this->config->title, true, ['context' => $this->context]);
}
if (empty($this->config->glossary)) {
return false;
}
if (!isset($this->config->nexttime)) {
$this->config->nexttime = 0;
}
//check if it's time to put a new entry in cache
if (time() > $this->config->nexttime) {
if (!($cm = $this->get_glossary_cm()) || !$cm->uservisible) {
// Skip generating of the cache if we can't display anything to the current user.
return false;
}
// place glossary concept and definition in $pref->cache
if (!$numberofentries = $DB->count_records('glossary_entries',
array('glossaryid'=>$this->config->glossary, 'approved'=>1))) {
$this->config->cache = get_string('noentriesyet','block_glossary_random');
$this->instance_config_commit();
}
$glossaryctx = context_module::instance($cm->id);
$limitfrom = 0;
$limitnum = 1;
$orderby = 'timemodified ASC';
switch ($this->config->type) {
case BGR_RANDOMLY:
$i = ($numberofentries > 1) ? rand(1, $numberofentries) : 1;
$limitfrom = $i-1;
break;
case BGR_NEXTONE:
if (isset($this->config->previous)) {
$i = $this->config->previous + 1;
} else {
$i = 1;
}
if ($i > $numberofentries) { // Loop back to beginning
$i = 1;
}
$limitfrom = $i-1;
break;
case BGR_NEXTALPHA:
$orderby = 'concept ASC';
if (isset($this->config->previous)) {
$i = $this->config->previous + 1;
} else {
$i = 1;
}
if ($i > $numberofentries) { // Loop back to beginning
$i = 1;
}
$limitfrom = $i-1;
break;
default: // BGR_LASTMODIFIED
$i = $numberofentries;
$limitfrom = 0;
$orderby = 'timemodified DESC, id DESC';
break;
}
if ($entry = $DB->get_records_sql("SELECT id, concept, definition, definitionformat, definitiontrust
FROM {glossary_entries}
WHERE glossaryid = ? AND approved = 1
ORDER BY $orderby", array($this->config->glossary), $limitfrom, $limitnum)) {
$entry = reset($entry);
if (empty($this->config->showconcept)) {
$text = '';
} else {
$text = "<h3>".format_string($entry->concept,true)."</h3>";
}
$options = new stdClass();
$options->trusted = $entry->definitiontrust;
$options->overflowdiv = true;
$entry->definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $glossaryctx->id, 'mod_glossary', 'entry', $entry->id);
$text .= format_text($entry->definition, $entry->definitionformat, $options);
$this->config->nexttime = usergetmidnight(time()) + DAYSECS * $this->config->refresh;
$this->config->previous = $i;
} else {
$text = get_string('noentriesyet','block_glossary_random');
}
// store the text
$this->config->cache = $text;
$this->instance_config_commit();
}
}
/**
* Replace the instance's configuration data with those currently in $this->config;
*/
function instance_config_commit($nolongerused = false) {
// Unset config variables that are no longer used.
unset($this->config->globalglossary);
unset($this->config->courseid);
parent::instance_config_commit($nolongerused);
}
/**
* Checks if glossary is available - it should be either located in the same course or be global
*
* @return null|cm_info|stdClass object with properties 'id' (course module id) and 'uservisible'
*/
protected function get_glossary_cm() {
global $DB;
if (empty($this->config->glossary)) {
// No glossary is configured.
return null;
}
if (!empty($this->glossarycm)) {
return $this->glossarycm;
}
if (!empty($this->page->course->id)) {
// First check if glossary belongs to the current course (we don't need to make any DB queries to find it).
$modinfo = get_fast_modinfo($this->page->course);
if (isset($modinfo->instances['glossary'][$this->config->glossary])) {
$this->glossarycm = $modinfo->instances['glossary'][$this->config->glossary];
if ($this->glossarycm->uservisible) {
// The glossary is in the same course and is already visible to the current user,
// no need to check if it is global, save on DB query.
return $this->glossarycm;
}
}
}
// Find course module id for the given glossary, only if it is global.
$cm = $DB->get_record_sql("SELECT cm.id, cm.visible AS uservisible
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {glossary} g ON g.id = cm.instance
WHERE g.id = :instance AND md.name = :modulename AND g.globalglossary = 1",
['instance' => $this->config->glossary, 'modulename' => 'glossary']);
if ($cm) {
// This is a global glossary, create an object with properties 'id' and 'uservisible'. We don't need any
// other information so why bother retrieving it. Full access check is skipped for global glossaries for
// performance reasons.
$this->glossarycm = $cm;
} else if (empty($this->glossarycm)) {
// Glossary does not exist. Remove it in the config so we don't repeat this check again later.
$this->config->glossary = 0;
$this->instance_config_commit();
}
return $this->glossarycm;
}
function instance_allow_multiple() {
// Are you going to allow multiple instances of each block?
// If yes, then it is assumed that the block WILL USE per-instance configuration
return true;
}
function get_content() {
if ($this->content !== null) {
return $this->content;
}
$this->content = (object)['text' => '', 'footer' => ''];
if (!$cm = $this->get_glossary_cm()) {
if ($this->user_can_edit()) {
$this->content->text = get_string('notyetconfigured', 'block_glossary_random');
}
return $this->content;
}
if (empty($this->config->cache)) {
$this->config->cache = '';
}
if ($cm->uservisible) {
// Show glossary if visible and place links in footer.
$this->content->text = $this->config->cache;
if (has_capability('mod/glossary:write', context_module::instance($cm->id))) {
$this->content->footer = html_writer::link(new moodle_url('/mod/glossary/edit.php', ['cmid' => $cm->id]),
format_string($this->config->addentry)) . '<br/>';
}
$this->content->footer .= html_writer::link(new moodle_url('/mod/glossary/view.php', ['id' => $cm->id]),
format_string($this->config->viewglossary));
} else {
// Otherwise just place some text, no link.
$this->content->footer = format_string($this->config->invisible);
}
return $this->content;
}
/**
* Return the plugin config settings for external functions.
*
* @return stdClass the configs for both the block instance and plugin
* @since Moodle 3.8
*/
public function get_config_for_external() {
// Return all settings for all users since it is safe (no private keys, etc..).
$configs = !empty($this->config) ? $this->config : new stdClass();
return (object) [
'instance' => $configs,
'plugin' => new stdClass(),
];
}
/**
* This block shouldn't be added to a page if the glossary module is disabled.
*
* @param moodle_page $page
* @return bool
*/
public function can_block_be_added(moodle_page $page): bool {
$pluginclass = \core_plugin_manager::resolve_plugininfo_class('mod');
return $pluginclass::get_enabled_plugin('glossary');
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_glossary_random.
*
* @package block_glossary_random
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_glossary_random\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_glossary_random implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+51
View File
@@ -0,0 +1,51 @@
<?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/>.
/**
* Glossary random block caps.
*
* @package block_glossary_random
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/glossary_random:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/glossary_random:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
+104
View File
@@ -0,0 +1,104 @@
<?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/>.
/**
* Form for editing HTML block instances.
*
* @package block_glossary_random
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Form for editing Random glossary entry block instances.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_glossary_random_edit_form extends block_edit_form {
protected function specific_definition($mform) {
global $DB;
// Fields for editing HTML block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
$mform->addElement('text', 'config_title', get_string('title', 'block_glossary_random'));
$mform->setDefault('config_title', get_string('pluginname','block_glossary_random'));
$mform->setType('config_title', PARAM_TEXT);
// Select glossaries to put in dropdown box ...
$glossaries = $DB->get_records_select_menu('glossary', 'course = ? OR globalglossary = ?',
[$this->get_course_id(), 1], 'name', 'id,name');
foreach($glossaries as $key => $value) {
$glossaries[$key] = strip_tags(format_string($value, true));
}
$mform->addElement('select', 'config_glossary', get_string('select_glossary', 'block_glossary_random'), $glossaries);
$mform->addElement('text', 'config_refresh', get_string('refresh', 'block_glossary_random'), array('size' => 5));
$mform->setDefault('config_refresh', 0);
$mform->setType('config_refresh', PARAM_INT);
// and select quotetypes to put in dropdown box
$types = array(
0 => get_string('random','block_glossary_random'),
1 => get_string('lastmodified','block_glossary_random'),
2 => get_string('nextone','block_glossary_random'),
3 => get_string('nextalpha','block_glossary_random')
);
$mform->addElement('select', 'config_type', get_string('type', 'block_glossary_random'), $types);
$mform->addElement('selectyesno', 'config_showconcept', get_string('showconcept', 'block_glossary_random'));
$mform->setDefault('config_showconcept', 1);
$mform->addElement('static', 'footerdescription', '', get_string('whichfooter', 'block_glossary_random'));
$mform->addElement('text', 'config_addentry', get_string('askaddentry', 'block_glossary_random'));
$mform->setDefault('config_addentry', get_string('addentry', 'block_glossary_random'));
$mform->setType('config_addentry', PARAM_NOTAGS);
$mform->addElement('text', 'config_viewglossary', get_string('askviewglossary', 'block_glossary_random'));
$mform->setDefault('config_viewglossary', get_string('viewglossary', 'block_glossary_random'));
$mform->setType('config_viewglossary', PARAM_NOTAGS);
$mform->addElement('text', 'config_invisible', get_string('askinvisible', 'block_glossary_random'));
$mform->setDefault('config_invisible', get_string('invisible', 'block_glossary_random'));
$mform->setType('config_invisible', PARAM_NOTAGS);
}
/**
* Returns id of the course where this block is located (or siteid for the dashboard or non-course page)
*
* @return int
*/
protected function get_course_id(): int {
if ($this->block->instance->id) {
return $this->block->course->id;
} else if ($parentcontext = $this->block->context->get_course_context(false)) {
return $parentcontext->instanceid;
} else {
return get_site()->id;
}
}
/**
* Display the configuration form when block is being added to the page
*
* @return bool
*/
public static function display_form_when_adding(): bool {
return true;
}
}
@@ -0,0 +1,48 @@
<?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/>.
/**
* Strings for component 'block_glossary_random', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_glossary_random
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['addentry'] = 'Add a new entry';
$string['askaddentry'] = 'When users can add entries to the glossary, show a link with this text';
$string['askinvisible'] = 'When users cannot edit or view the glossary, show this text (without link)';
$string['askviewglossary'] = 'When users can view the glossary but not add entries, show a link with this text';
$string['glossary_random:addinstance'] = 'Add a new random glossary entry block';
$string['glossary_random:myaddinstance'] = 'Add a new random glossary entry block to Dashboard';
$string['intro'] = 'Make sure you have at least one glossary with at least one entry added to this course. Then you can adjust the following settings';
$string['invisible'] = '(to be continued)';
$string['lastmodified'] = 'Last modified entry';
$string['nextalpha'] = 'Alphabetical order';
$string['nextone'] = 'Next entry';
$string['noentriesyet'] = 'There are no entries yet in the chosen glossary.';
$string['notyetconfigured'] = 'Please configure this block using the edit icon.';
$string['notyetglossary'] = 'You need to have at least one glossary to choose.';
$string['pluginname'] = 'Random glossary entry';
$string['random'] = 'Random entry';
$string['refresh'] = 'Days before a new entry is chosen';
$string['select_glossary'] = 'Take entries from this glossary';
$string['showconcept'] = 'Show concept (heading) for each entry';
$string['title'] = 'Title';
$string['type'] = 'How a new entry is chosen';
$string['viewglossary'] = 'View all entries';
$string['whichfooter'] = 'You can display links to actions of the glossary this block is associated with. The block will only display links to actions which are enabled for that glossary.';
$string['privacy:metadata'] = 'The Random glossary entry block only shows data stored in other locations.';
@@ -0,0 +1,108 @@
@block @block_glossary_random
Feature: Random glossary entry block is used in a course
In order to show the entries from glossary
As a teacher
I can add the random glossary entry to a course page
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Sam1 | Student1 | student1@example.com |
| teacher1 | Terry1 | Teacher1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
Scenario: Student can not see the block if it is not configured
When I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Random glossary entry" block
Then I should see "Please configure this block using the edit icon" in the "block_glossary_random" "block"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And "block_glossary_random" "block" should not exist
And I log out
Scenario: View random (last) entry in the glossary with auto approval
Given the following "activities" exist:
| activity | name | intro | course | idnumber | defaultapproval |
| glossary | GlossaryAuto | Test glossary description | C1 | glossary1 | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Random glossary entry" block
And I configure the "block_glossary_random" block
And I set the following fields to these values:
| Title | AutoGlossaryblock |
| Take entries from this glossary | GlossaryAuto |
| How a new entry is chosen | Last modified entry |
And I press "Save changes"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "There are no entries yet in the chosen glossary" in the "AutoGlossaryblock" "block"
And I click on "Add a new entry" "link" in the "AutoGlossaryblock" "block"
And I set the following fields to these values:
| Concept | Concept1 |
| Definition | Definition1 |
And I press "Save changes"
And I am on "Course 1" course homepage
And I should see "Concept1" in the "AutoGlossaryblock" "block"
And I should see "Definition1" in the "AutoGlossaryblock" "block"
And I should not see "There are no entries yet in the chosen glossary" in the "AutoGlossaryblock" "block"
And I click on "Add a new entry" "link" in the "AutoGlossaryblock" "block"
And I set the following fields to these values:
| Concept | Concept2 |
| Definition | Definition2 |
And I press "Save changes"
And I am on "Course 1" course homepage
# Only the last entry appears in the block
And I should not see "Concept1" in the "AutoGlossaryblock" "block"
And I should not see "Definition1" in the "AutoGlossaryblock" "block"
And I should see "Concept2" in the "AutoGlossaryblock" "block"
And I should see "Definition2" in the "AutoGlossaryblock" "block"
And I click on "View all entries" "link" in the "AutoGlossaryblock" "block"
And I should see "GlossaryAuto" in the "#page-navbar" "css_element"
And I should see "Concept1" in the "#page-content" "css_element"
And I should see "Concept2" in the "#page-content" "css_element"
And I log out
Scenario: View random (last) entry in the glossary with manual approval
Given the following "activities" exist:
| activity | name | intro | course | idnumber | defaultapproval |
| glossary | GlossaryManual | Test glossary description | C1 | glossary2 | 0 |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Random glossary entry" block
And I configure the "block_glossary_random" block
And I set the following fields to these values:
| Title | ManualGlossaryblock |
| Take entries from this glossary | GlossaryManual |
| How a new entry is chosen | Last modified entry |
And I press "Save changes"
And I log out
When I log in as "student1"
And I am on "Course 1" course homepage
Then I should see "There are no entries yet in the chosen glossary" in the "ManualGlossaryblock" "block"
And I click on "Add a new entry" "link" in the "ManualGlossaryblock" "block"
And I set the following fields to these values:
| Concept | Concept1 |
| Definition | Definition1 |
And I press "Save changes"
And I am on "Course 1" course homepage
And I should see "There are no entries yet in the chosen glossary" in the "ManualGlossaryblock" "block"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I should see "There are no entries yet in the chosen glossary" in the "ManualGlossaryblock" "block"
And I follow "GlossaryManual"
And I follow "Pending approval"
And I follow "Approve"
And I click on "Course 1" "link" in the "#page-navbar" "css_element"
And I should see "Concept1" in the "ManualGlossaryblock" "block"
And I should see "Definition1" in the "ManualGlossaryblock" "block"
And I log out
@@ -0,0 +1,23 @@
@block @block_glossary_random @javascript @addablocklink
Feature: Add the glossary random block when main feature is enabled
In order to add the glossary random block to my course
As a teacher
It should be added to courses only if the glossary module is enabled.
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And I am on the "C1" "course" page logged in as "admin"
Scenario: The glossary random block can be added when glossary module is enabled
Given I turn editing mode on
When I click on "Add a block" "link"
Then I should see "Random glossary entry"
Scenario: The glossary random block cannot be added when glossary module is disabled
Given I navigate to "Plugins > Activity modules > Manage activities" in site administration
And I click on "Disable Glossary" "icon" in the "Glossary" "table_row"
And I am on "Course 1" course homepage with editing mode on
When I click on "Add a block" "link"
Then I should not see "Random glossary entry"
@@ -0,0 +1,36 @@
@block @block_glossary_random @javascript
Feature: Add the glossary random block when main feature is disabled
In order to add the glossary random block to my course
As a teacher
It should be added to courses only if the glossary module is enabled.
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| glossary_random | Course | C1 | course-view-* | site-post |
Scenario: The glossary random block is displayed even when glossary module is disabled
When I log in as "admin"
And I navigate to "Plugins > Activity modules > Manage activities" in site administration
And I click on "Disable Glossary" "icon" in the "Glossary" "table_row"
And I am on "Course 1" course homepage with editing mode on
Then "Random glossary entry" "block" should exist
Scenario: The glossary random block can be removed even when glossary module is disabled
When I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I open the "Random glossary entry" blocks action menu
And I click on "Delete Random glossary entry block" "link" in the "Random glossary entry" "block"
And "Delete block?" "dialogue" should exist
And I click on "Cancel" "button" in the "Delete block?" "dialogue"
And "Random glossary entry" "block" should exist
When I navigate to "Plugins > Activity modules > Manage activities" in site administration
And I click on "Disable Glossary" "icon" in the "Glossary" "table_row"
And I am on "Course 1" course homepage with editing mode on
And I open the "Random glossary entry" blocks action menu
And I click on "Delete Random glossary entry block" "link" in the "Random glossary entry" "block"
And I click on "Delete" "button" in the "Delete block?" "dialogue"
Then "Random glossary entry" "block" should not exist
@@ -0,0 +1,27 @@
@block @block_glossary_random
Feature: Random glossary entry block can be added to the frontpage
In order to show the entries from glossary on the frontpage
As a teacher
I can add the random glossary entry to the frontpage
Scenario: Admin can add random glossary block to the frontpage
Given the following "activities" exist:
| activity | name | intro | course | idnumber |
| glossary | Tips and Tricks | Frontpage glossary description | Acceptance test site | glossary0 |
And I log in as "admin"
And I am on site homepage
And I turn editing mode on
And I add the "Random glossary entry" block
And I configure the "block_glossary_random" block
And I set the following fields to these values:
| Title | Tip of the day |
| Take entries from this glossary | Tips and Tricks |
And I press "Save changes"
And I click on "Add a new entry" "link" in the "Tip of the day" "block"
And I set the following fields to these values:
| Concept | Never come late |
| Definition | Come in time for your classes |
And I press "Save changes"
When I log out
Then I should see "Never come late" in the "Tip of the day" "block"
And I should see "Come in time for your classes" in the "Tip of the day" "block"
@@ -0,0 +1,84 @@
@block @block_glossary_random
Feature: Random glossary entry block linking to global glossary
In order to show the entries from glossary
As a teacher
I can add the random glossary entry to a course page
Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
| Course 2 | C2 |
And the following "activity" exists:
| activity | glossary |
| name | Tips and Tricks |
| intro | Frontpage glossary description |
| course | C2 |
| idnumber | glossary0 |
| globalglossary | 1 |
| defaultapproval | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Sam1 | Student1 | student1@example.com |
| teacher1 | Terry1 | Teacher1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
Scenario: View random (last) entry in the global glossary
When I log in as "admin"
And I am on "Course 2" course homepage
And I follow "Tips and Tricks"
And I press "Add entry"
And I set the following fields to these values:
| Concept | Never come late |
| Definition | Come in time for your classes |
And I press "Save changes"
And I log out
# As a teacher add a block to the course page linking to the global glossary.
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Random glossary entry" block
And I configure the "block_glossary_random" block
And I set the following fields to these values:
| Title | Tip of the day |
| Take entries from this glossary | Tips and Tricks |
| How a new entry is chosen | Last modified entry |
And I press "Save changes"
Then I should see "Never come late" in the "Tip of the day" "block"
And I should not see "Add a new entry" in the "Tip of the day" "block"
And I should see "View all entries" in the "Tip of the day" "block"
And I log out
# Student who can't see the module is still able to view entries in this block (because the glossary was marked as global)
And I log in as "student1"
And I am on "Course 1" course homepage
And I should see "Never come late" in the "Tip of the day" "block"
And I should not see "Add a new entry" in the "Tip of the day" "block"
And I should see "View all entries" in the "Tip of the day" "block"
And I log out
Scenario: Removing the global glossary that is used in random glossary block
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add the "Random glossary entry" block
And I configure the "block_glossary_random" block
And I set the following fields to these values:
| Title | Tip of the day |
| Take entries from this glossary | Tips and Tricks |
| How a new entry is chosen | Last modified entry |
And I press "Save changes"
And I log out
And I log in as "admin"
And I am on "Course 2" course homepage
And I follow "Tips and Tricks"
And I follow "Settings"
And I set the field "globalglossary" to "0"
And I press "Save and return to course"
And I am on "Course 1" course homepage
Then I should see "Please configure this block using the edit icon." in the "Tip of the day" "block"
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage
And "Tip of the day" "block" should not exist
And I log out
@@ -0,0 +1,64 @@
<?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/>.
namespace block_glossary_random;
use advanced_testcase;
use block_glossary_random;
use context_course;
/**
* PHPUnit block_glossary_random tests
*
* @package block_glossary_random
* @category test
* @copyright 2021 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \block_glossary_random
*/
class glossary_random_test extends advanced_testcase {
public static function setUpBeforeClass(): void {
require_once(__DIR__ . '/../../moodleblock.class.php');
require_once(__DIR__ . '/../block_glossary_random.php');
}
/**
* Test the behaviour of can_block_be_added() method.
*
* @covers ::can_block_be_added
*/
public function test_can_block_be_added(): void {
$this->resetAfterTest();
$this->setAdminUser();
// Create a course and prepare the page where the block will be added.
$course = $this->getDataGenerator()->create_course();
$page = new \moodle_page();
$page->set_context(context_course::instance($course->id));
$page->set_pagelayout('course');
$block = new block_glossary_random();
$pluginclass = \core_plugin_manager::resolve_plugininfo_class('mod');
// If glossary module is enabled, the method should return true.
$pluginclass::enable_plugin('glossary', 1);
$this->assertTrue($block->can_block_be_added($page));
// However, if the glossary module is disabled, the method should return false.
$pluginclass::enable_plugin('glossary', 0);
$this->assertFalse($block->can_block_be_added($page));
}
}
+31
View File
@@ -0,0 +1,31 @@
<?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/>.
/**
* Version details
*
* @package block_glossary_random
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_glossary_random'; // Full name of the plugin (used for diagnostics)
$plugin->dependencies = ['mod_glossary' => 2024041600];