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,98 @@
<?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/>.
/**
* booktool_exportimscp book exported event.
*
* @package booktool_exportimscp
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_exportimscp\event;
defined('MOODLE_INTERNAL') || die();
/**
* booktool_exportimscp book exported event class.
*
* @package booktool_exportimscp
* @since Moodle 2.6
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class book_exported extends \core\event\base {
/**
* Create instance of event.
*
* @since Moodle 2.7
*
* @param \stdClass $book
* @param \context_module $context
* @return book_exported
*/
public static function create_from_book(\stdClass $book, \context_module $context) {
$data = array(
'context' => $context,
'objectid' => $book->id
);
/** @var book_exported $event */
$event = self::create($data);
$event->add_record_snapshot('book', $book);
return $event;
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' has exported the book with course module id '$this->contextinstanceid'.";
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventbookexported', 'booktool_exportimscp');
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/book/tool/exportimscp/index.php', array('id' => $this->contextinstanceid));
}
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'book';
}
public static function get_objectid_mapping() {
return array('db' => 'book', 'restore' => 'book');
}
}
@@ -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 provider implementation for booktool_exportimscp.
*
* @package booktool_exportimscp
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_exportimscp\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy provider implementation for booktool_exportimscp.
*
* @copyright 2018 Mihail Geshoski <mihail@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';
}
}
+32
View File
@@ -0,0 +1,32 @@
<?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/>.
/**
* Book module capability definition
*
* @package booktool_exportimscp
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$capabilities = array(
'booktool/exportimscp:export' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE
),
);
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Export to IMSCP booktool log events definition
*
* @package booktool_exportimscp
* @copyright 2012 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$logs = array(
array('module'=>'book', 'action'=>'exportimscp', 'mtable'=>'book', 'field'=>'name')
);
+40
View File
@@ -0,0 +1,40 @@
body,
table,
td,
th,
li,
p {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 1em;
line-height: 150%;
letter-spacing: 0.02em;
}
th {
font-weight: bold;
}
a:link,
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1.main,
h2.main,
h3.main,
h4.main,
h5.main,
h6.main {
font-weight: bold;
}
h1#header {
color: #666;
text-align: right;
padding-bottom: 0.2em;
border-bottom: solid 1px #666;
}
+50
View File
@@ -0,0 +1,50 @@
<?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/>.
/**
* Book IMSCP export plugin
*
* @package booktool_exportimscp
* @copyright 2001-3001 Antonio Vicent {@link http://ludens.es}
* @copyright 2001-3001 Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../../../config.php');
require_once(__DIR__.'/locallib.php');
require_once($CFG->dirroot.'/mod/book/locallib.php');
require_once($CFG->libdir.'/filelib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
$book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
$PAGE->set_url('/mod/book/tool/exportimscp/index.php', array('id'=>$id));
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/book:read', $context);
require_capability('booktool/exportimscp:export', $context);
\booktool_exportimscp\event\book_exported::create_from_book($book, $context)->trigger();
$file = booktool_exportimscp_build_package($book, $context);
send_stored_file($file, 10, 0, true, array('filename' => clean_filename($book->name).'.zip'));
@@ -0,0 +1,32 @@
<?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/>.
/**
* exportimscp booktool language strings
*
* @package booktool_exportimscp
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$string['eventbookexported'] = 'Book exported';
$string['exportimscp:export'] = 'Export book as IMS content package';
$string['generateimscp'] = 'Download IMS CP';
$string['nochapters'] = 'No book chapters found, so unable to export to IMS CP.';
$string['pluginname'] = 'Book IMS CP export';
$string['privacy:metadata'] = 'The Book IMS CP export plugin does not store any personal data.';
+41
View File
@@ -0,0 +1,41 @@
<?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/>.
/**
* IMSCP export lib
*
* @package booktool_exportimscp
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Adds module specific settings to the settings block
*
* @param settings_navigation $settings The settings navigation object
* @param navigation_node $node The node to add module settings to
*/
function booktool_exportimscp_extend_settings_navigation(settings_navigation $settings, navigation_node $node) {
if (has_capability('booktool/exportimscp:export', $settings->get_page()->cm->context)) {
$url = new moodle_url('/mod/book/tool/exportimscp/index.php', array('id' => $settings->get_page()->cm->id));
$icon = new pix_icon('generate', '', 'booktool_exportimscp', array('class'=>'icon'));
$umscpnode = $node->add(get_string('generateimscp', 'booktool_exportimscp'), $url,
navigation_node::TYPE_SETTING, null, null, $icon);
$umscpnode->set_force_into_more_menu(true);
}
}
+262
View File
@@ -0,0 +1,262 @@
<?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/>.
/**
* Book imscp export lib
*
* @package booktool_exportimscp
* @copyright 2001-3001 Antonio Vicent {@link http://ludens.es}
* @copyright 2001-3001 Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once(__DIR__.'/lib.php');
require_once($CFG->dirroot.'/mod/book/locallib.php');
/**
* Export one book as IMSCP package
*
* @param stdClass $book book instance
* @param context_module $context
* @return bool|stored_file
*/
function booktool_exportimscp_build_package($book, $context) {
global $DB;
$fs = get_file_storage();
if ($packagefile = $fs->get_file($context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip')) {
return $packagefile;
}
// fix structure and test if chapters present
if (!book_preload_chapters($book)) {
throw new \moodle_exception('nochapters', 'booktool_exportimscp');
}
// prepare temp area with package contents
booktool_exportimscp_prepare_files($book, $context);
$packer = get_file_packer('application/zip');
$areafiles = $fs->get_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision, "sortorder, itemid, filepath, filename", false);
$files = array();
foreach ($areafiles as $file) {
$path = $file->get_filepath().$file->get_filename();
$path = ltrim($path, '/');
$files[$path] = $file;
}
unset($areafiles);
$packagefile = $packer->archive_to_storage($files, $context->id, 'booktool_exportimscp', 'package', $book->revision, '/', 'imscp.zip');
// drop temp area
$fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $book->revision);
// delete older versions
$sql = "SELECT DISTINCT itemid
FROM {files}
WHERE contextid = :contextid AND component = 'booktool_exportimscp' AND itemid < :revision";
$params = array('contextid'=>$context->id, 'revision'=>$book->revision);
$revisions = $DB->get_records_sql($sql, $params);
foreach ($revisions as $rev => $unused) {
$fs->delete_area_files($context->id, 'booktool_exportimscp', 'temp', $rev);
$fs->delete_area_files($context->id, 'booktool_exportimscp', 'package', $rev);
}
return $packagefile;
}
/**
* Prepare temp area with the files used by book html contents
*
* @param stdClass $book book instance
* @param context_module $context
*/
function booktool_exportimscp_prepare_files($book, $context) {
global $CFG, $DB;
$fs = get_file_storage();
$temp_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp', 'itemid'=>$book->revision);
$chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
$chapterresources = array();
foreach ($chapters as $chapter) {
$chapterresources[$chapter->id] = array();
$files = $fs->get_area_files($context->id, 'mod_book', 'chapter', $chapter->id, "sortorder, itemid, filepath, filename", false);
foreach ($files as $file) {
$temp_file_record['filepath'] = '/'.$chapter->pagenum.$file->get_filepath();
$fs->create_file_from_storedfile($temp_file_record, $file);
$chapterresources[$chapter->id][] = $chapter->pagenum.$file->get_filepath().$file->get_filename();
}
if ($file = $fs->get_file($context->id, 'booktool_exportimscp', 'temp', $book->revision, "/$chapter->pagenum/", 'index.html')) {
// this should not exist
$file->delete();
}
$content = booktool_exportimscp_chapter_content($chapter, $context);
$index_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
'itemid'=>$book->revision, 'filepath'=>"/$chapter->pagenum/", 'filename'=>'index.html');
$fs->create_file_from_string($index_file_record, $content);
}
$css_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
'itemid'=>$book->revision, 'filepath'=>"/css/", 'filename'=>'styles.css');
$fs->create_file_from_pathname($css_file_record, __DIR__.'/imscp.css');
// Init imsmanifest and others
$imsmanifest = '';
$imsitems = '';
$imsresources = '';
// Moodle and Book version
$moodle_release = $CFG->release;
$moodle_version = $CFG->version;
$book_version = get_config('mod_book', 'version');
$bookname = format_string($book->name, true, array('context'=>$context));
// Load manifest header
$imsmanifest .= '<?xml version="1.0" encoding="UTF-8"?>
<!-- This package has been created with Moodle ' . $moodle_release . ' (' . $moodle_version . ') http://moodle.org/, Book module version ' . $book_version . ' - https://github.com/skodak/moodle-mod_book -->
<!-- One idea and implementation by Eloy Lafuente (stronk7) and Antonio Vicent (C) 2001-3001 -->
<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" identifier="MANIFEST-' . md5($CFG->wwwroot . '-' . $book->course . '-' . $book->id) . '" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
<organizations default="MOODLE-' . $book->course . '-' . $book->id . '">
<organization identifier="MOODLE-' . $book->course . '-' . $book->id . '" structure="hierarchical">
<title>' . htmlspecialchars($bookname, ENT_COMPAT) . '</title>';
// To store the prev level (book only have 0 and 1)
$prevlevel = null;
$currlevel = 0;
foreach ($chapters as $chapter) {
// Calculate current level ((book only have 0 and 1)
$currlevel = empty($chapter->subchapter) ? 0 : 1;
// Based upon prevlevel and current one, decide what to close
if ($prevlevel !== null) {
// Calculate the number of spaces (for visual xml-text formating)
$prevspaces = substr(' ', 0, $currlevel * 2);
// Same level, simply close the item
if ($prevlevel == $currlevel) {
$imsitems .= $prevspaces . ' </item>' . "\n";
}
// Bigger currlevel, nothing to close
// Smaller currlevel, close both the current item and the parent one
if ($prevlevel > $currlevel) {
$imsitems .= ' </item>' . "\n";
$imsitems .= ' </item>' . "\n";
}
}
// Update prevlevel
$prevlevel = $currlevel;
// Calculate the number of spaces (for visual xml-text formatting)
$currspaces = substr(' ', 0, $currlevel * 2);
$chaptertitle = format_string($chapter->title, true, array('context'=>$context));
// Add the imsitems
$imsitems .= $currspaces .' <item identifier="ITEM-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum .'" isvisible="true" identifierref="RES-' .
$book->course . '-' . $book->id . '-' . $chapter->pagenum . "\">\n" .
$currspaces . ' <title>' . htmlspecialchars($chaptertitle, ENT_COMPAT) . '</title>' . "\n";
// Add the imsresources
// First, check if we have localfiles
$localfiles = array();
foreach ($chapterresources[$chapter->id] as $localfile) {
$localfiles[] = "\n" . ' <file href="' . $localfile . '" />';
}
// Now add the dependency to css
$cssdependency = "\n" . ' <dependency identifierref="RES-' . $book->course . '-' . $book->id . '-css" />';
// Now build the resources section
$imsresources .= ' <resource identifier="RES-' . $book->course . '-' . $book->id . '-' . $chapter->pagenum . '" type="webcontent" xml:base="' .
$chapter->pagenum . '/" href="index.html">' . "\n" .
' <file href="' . $chapter->pagenum . '/index.html" />' . implode($localfiles) . $cssdependency . "\n".
' </resource>' . "\n";
}
// Close items (the latest chapter)
// Level 1, close 1
if ($currlevel == 0) {
$imsitems .= ' </item>' . "\n";
}
// Level 2, close 2
if ($currlevel == 1) {
$imsitems .= ' </item>' . "\n";
$imsitems .= ' </item>' . "\n";
}
// Define the css common resource
$cssresource = ' <resource identifier="RES-' . $book->course . '-' . $book->id . '-css" type="webcontent" xml:base="css/" href="styles.css">
<file href="css/styles.css" />
</resource>' . "\n";
// Add imsitems to manifest
$imsmanifest .= "\n" . $imsitems;
// Close the organization
$imsmanifest .= " </organization>
</organizations>";
// Add resources to manifest
$imsmanifest .= "\n <resources>\n" . $imsresources . $cssresource . " </resources>";
// Close manifest
$imsmanifest .= "\n</manifest>\n";
$manifest_file_record = array('contextid'=>$context->id, 'component'=>'booktool_exportimscp', 'filearea'=>'temp',
'itemid'=>$book->revision, 'filepath'=>"/", 'filename'=>'imsmanifest.xml');
$fs->create_file_from_string($manifest_file_record, $imsmanifest);
}
/**
* Returns the html contents of one book's chapter to be exported as IMSCP
*
* @param stdClass $chapter the chapter to be exported
* @param context_module $context context the chapter belongs to
* @return string the contents of the chapter
*/
function booktool_exportimscp_chapter_content($chapter, $context) {
$options = new stdClass();
$options->noclean = true;
$options->context = $context;
// We need to rewrite the pluginfile URLs so the media filters can work.
$chaptercontent = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id);
$chaptercontent = format_text($chaptercontent, $chapter->contentformat, $options);
// Now remove again the full pluginfile URLs.
$options = array('reverse' => true);
$chaptercontent = file_rewrite_pluginfile_urls($chaptercontent, 'pluginfile.php', $context->id, 'mod_book', 'chapter',
$chapter->id, $options);
$chaptercontent = str_replace('@@PLUGINFILE@@/', '', $chaptercontent);
$chaptertitle = format_string($chapter->title, true, array('context'=>$context));
$content = '';
$content .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n";
$content .= '<html>' . "\n";
$content .= '<head>' . "\n";
$content .= '<meta http-equiv="content-type" content="text/html; charset=utf-8" />' . "\n";
$content .= '<link rel="stylesheet" type="text/css" href="../css/styles.css" />' . "\n";
$content .= '<title>' . $chaptertitle . '</title>' . "\n";
$content .= '</head>' . "\n";
$content .= '<body>' . "\n";
$content .= '<h1 id="header">' . $chaptertitle . '</h1>' ."\n";
$content .= $chaptercontent . "\n";
$content .= '</body>' . "\n";
$content .= '</html>' . "\n";
return $content;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 816 B

@@ -0,0 +1,65 @@
<?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/>.
/**
* Events tests.
*
* @package booktool_exportimscp
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace booktool_exportimscp\event;
/**
* Events tests class.
*
* @package booktool_exportimscp
* @category phpunit
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class events_test extends \advanced_testcase {
public function setUp(): void {
$this->resetAfterTest();
}
public function test_book_exported(): void {
// There is no proper API to call to test the event, so what we are
// doing here is simply making sure that the events returns the right information.
$course = $this->getDataGenerator()->create_course();
$book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
$context = \context_module::instance($book->cmid);
$event = \booktool_exportimscp\event\book_exported::create_from_book($book, $context);
// Triggering and capturing the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
// Checking that the event contains the expected values.
$this->assertInstanceOf('\booktool_exportimscp\event\book_exported', $event);
$this->assertEquals(\context_module::instance($book->cmid), $event->get_context());
$this->assertEquals($book->id, $event->objectid);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Book IMSCP export plugin version info
*
* @package booktool_exportimscp
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$plugin->component = 'booktool_exportimscp'; // Full name of the plugin (used for diagnostics)
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.