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