Differences Between: [Versions 310 and 311] [Versions 39 and 311]
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 * booktool_importhtml tests. 19 * 20 * @package booktool_importhtml 21 * @category phpunit 22 * @copyright 2013 Frédéric Massart 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 namespace booktool_importhtml; 26 27 defined('MOODLE_INTERNAL') || die(); 28 global $CFG; 29 30 require_once($CFG->dirroot.'/mod/book/tool/importhtml/locallib.php'); 31 32 /** 33 * booktool_importhtml tests class. 34 * 35 * @package booktool_importhtml 36 * @category phpunit 37 * @copyright 2013 Frédéric Massart 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class locallib_test extends \advanced_testcase { 41 42 public function setUp(): void { 43 $this->resetAfterTest(); 44 } 45 46 public function test_import_chapters_events() { 47 $course = $this->getDataGenerator()->create_course(); 48 $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id)); 49 $context = \context_module::instance($book->cmid); 50 51 $record = new \stdClass(); 52 $record->contextid = $context->id; 53 $record->component = 'phpunit'; 54 $record->filearea = 'test'; 55 $record->itemid = 0; 56 $record->filepath = '/'; 57 $record->filename = 'chapters.zip'; 58 59 $fs = get_file_storage(); 60 $file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip'); 61 62 // Importing the chapters. 63 $sink = $this->redirectEvents(); 64 toolbook_importhtml_import_chapters($file, 2, $book, $context, false); 65 $events = $sink->get_events(); 66 67 // Checking the results. 68 $this->assertCount(5, $events); 69 foreach ($events as $event) { 70 $this->assertInstanceOf('\mod_book\event\chapter_created', $event); 71 $this->assertEquals($context, $event->get_context()); 72 $chapter = $event->get_record_snapshot('book_chapters', $event->objectid); 73 $this->assertNotEmpty($chapter); 74 $this->assertEventContextNotUsed($event); 75 } 76 } 77 78 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body