Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 35... Línea 35...
35
 * @package    booktool_importhtml
35
 * @package    booktool_importhtml
36
 * @category   phpunit
36
 * @category   phpunit
37
 * @copyright  2013 Frédéric Massart
37
 * @copyright  2013 Frédéric Massart
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
39
 */
40
class locallib_test extends \advanced_testcase {
40
final class locallib_test extends \advanced_testcase {
-
 
41
 
-
 
42
    /** @var object */
-
 
43
    private object $book;
-
 
44
    /** @var object */
-
 
45
    private object $context;
-
 
46
    /** @var object */
-
 
47
    private object $record;
Línea 41... Línea 48...
41
 
48
 
-
 
49
    public function setUp(): void {
42
    public function setUp(): void {
50
        parent::setUp();
43
        $this->resetAfterTest();
-
 
Línea 44... Línea -...
44
    }
-
 
45
 
51
        $this->resetAfterTest();
46
    public function test_import_chapters_events(): void {
52
 
47
        $course = $this->getDataGenerator()->create_course();
53
        $course = $this->getDataGenerator()->create_course();
-
 
54
        $this->book = $this->getDataGenerator()->create_module('book', ['course' => $course->id]);
-
 
55
        $this->context = \context_module::instance($this->book->cmid);
-
 
56
        $this->record = (object) [
-
 
57
            'contextid' => $this->context->id,
-
 
58
            'component' => 'phpunit',
-
 
59
            'filearea'  => 'test',
-
 
60
            'itemid'    => 0,
-
 
61
            'filepath'  => '/',
Línea 48... Línea 62...
48
        $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
62
        ];
49
        $context = \context_module::instance($book->cmid);
63
    }
50
 
64
 
51
        $record = new \stdClass();
-
 
52
        $record->contextid = $context->id;
65
    /**
53
        $record->component = 'phpunit';
-
 
54
        $record->filearea = 'test';
66
     * Tests the events within toolbook_importhtml_import_chapters
Línea -... Línea 67...
-
 
67
     * @covers ::toolbook_importhtml_import_chapters
-
 
68
     */
55
        $record->itemid = 0;
69
    public function test_import_chapters_events(): void {
56
        $record->filepath = '/';
70
 
-
 
71
        $this->record->filename = 'chapters.zip';
Línea 57... Línea 72...
57
        $record->filename = 'chapters.zip';
72
        $file = get_file_storage()->create_file_from_pathname(
58
 
73
            $this->record,
59
        $fs = get_file_storage();
74
            self::get_fixture_path(__NAMESPACE__, 'chapters.zip')
60
        $file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip');
75
        );
Línea 61... Línea 76...
61
 
76
 
62
        // Importing the chapters.
77
        // Importing the chapters.
63
        $sink = $this->redirectEvents();
78
        $sink = $this->redirectEvents();
64
        toolbook_importhtml_import_chapters($file, 2, $book, $context, false);
79
        toolbook_importhtml_import_chapters($file, 2, $this->book, $this->context, false);
65
        $events = $sink->get_events();
80
        $events = $sink->get_events();
66
 
81
 
67
        // Checking the results.
82
        // Checking the results up to the triggered event.
68
        $this->assertCount(5, $events);
83
        $this->assertCount(5, $events);
69
        foreach ($events as $event) {
84
        foreach ($events as $event) {
70
            $this->assertInstanceOf('\mod_book\event\chapter_created', $event);
85
            $this->assertInstanceOf('\mod_book\event\chapter_created', $event);
Línea -... Línea 86...
-
 
86
            $this->assertEquals($this->context, $event->get_context());
-
 
87
            $chapter = $event->get_record_snapshot('book_chapters', $event->objectid);
-
 
88
            $this->assertNotEmpty($chapter);
-
 
89
            $this->assertEventContextNotUsed($event);
-
 
90
        }
-
 
91
    }
-
 
92
 
-
 
93
    /**
-
 
94
     * Tests the conversion of (anchored) links within toolbook_importhtml_import_chapters
-
 
95
     * @covers ::toolbook_importhtml_import_chapters
-
 
96
     */
-
 
97
    public function test_import_chapters_links(): void {
-
 
98
        global $DB;
-
 
99
 
-
 
100
        $this->record->filename = 'chapters_links.zip';
-
 
101
        $file = get_file_storage()->create_file_from_pathname(
-
 
102
            $this->record,
-
 
103
            self::get_fixture_path(__NAMESPACE__, 'chapters_links.zip')
-
 
104
        );
-
 
105
 
-
 
106
        toolbook_importhtml_import_chapters($file, 2, $this->book, $this->context, false);
-
 
107
 
-
 
108
        $chapters = $DB->get_records('book_chapters', ['bookid' => $this->book->id]);
-
 
109
        foreach ($chapters as $chapter) {
71
            $this->assertEquals($context, $event->get_context());
110
            $this->assertStringNotContainsString('.html', $chapter->content);