MDL-67192 core_h5p: get site UUID from H5P using the API
[moodle.git] / lib / tests / h5p_get_content_types_task_test.php
CommitLineData
5315acb4
VDF
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 * Unit tests for the task that fetch the latest version of H5P content types.
19 *
20 * @package core
21 * @copyright 2019 Victor Deniz <victor@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
e942844d
VDF
25use core_h5p\autoloader;
26use core_h5p\h5p_test_factory;
27
5315acb4
VDF
28defined('MOODLE_INTERNAL') || die();
29
30/**
31 * Class containing unit tests for the task that fetch the latest version of H5P content types.
32 *
33 * @package core
34 * @copyright 2019 Victor Deniz <victor@moodle.com>
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 *
37 * @runTestsInSeparateProcesses
38 */
a23969a5 39class h5p_get_content_types_task_testcase extends advanced_testcase {
5315acb4 40
e942844d
VDF
41 protected function setup() {
42 global $CFG;
43 parent::setUp();
44
45 autoloader::register();
46
47 require_once($CFG->libdir . '/tests/fixtures/testable_core_h5p.php');
48 }
49
5315acb4
VDF
50 /**
51 * Test task execution
52 *
5315acb4
VDF
53 * return void
54 */
55 public function test_task_execution(): void {
e942844d 56
fc0ded84 57 if (!PHPUNIT_LONGTEST) {
5315acb4
VDF
58 $this->markTestSkipped('PHPUNIT_LONGTEST is not defined');
59 }
60
61 $this->resetAfterTest();
62
63 // Fetch generator.
64 $generator = \testing_util::get_data_generator();
65 $h5pgenerator = $generator->get_plugin_generator('core_h5p');
66
e942844d
VDF
67 $factory = new h5p_test_factory();
68 $core = $factory->get_core();
69 $core->set_endpoint($this->getExternalTestFileUrl(''));
70 $contenttypespending = ['H5P.Accordion'];
71
72 $h5pgenerator->create_content_types( $contenttypespending, $core);
73
74 // Mock implementation of \core\task\h5p_get_content_types_task::get_core to avoid external systems.
75 $mocktask = $this->getMockBuilder(\core\task\h5p_get_content_types_task::class)
76 ->setMethods(['get_core'])
77 ->getMock();
78
79 $mocktask->expects($this->any())
80 ->method('get_core')
81 ->willReturn($core);
5315acb4 82
e942844d
VDF
83 $mocktask->execute();
84 $this->expectOutputRegex('/1 new content types/');
5315acb4
VDF
85 }
86}