MDL-67790 core_contentbank: Unit and behat tests for renaming content
[moodle.git] / contentbank / contenttype / h5p / tests / content_h5p_test.php
CommitLineData
bd4e0a76
AA
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 * Test for H5P content bank plugin.
19 *
20 * @package contenttype_h5p
21 * @category test
22 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
27 * Test for H5P content bank plugin.
28 *
29 * @package contenttype_h5p
30 * @category test
31 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 * @coversDefaultClass \contenttype_h5p\content
34 */
35class contenttype_h5p_content_plugin_testcase extends advanced_testcase {
36
37 /**
38 * Tests for uploaded file.
39 *
40 * @covers ::get_file
41 */
42 public function test_upload_file() {
43 $this->resetAfterTest();
44
45 // Create content.
46 $record = new stdClass();
47 $record->name = 'Test content';
48 $record->configdata = '';
49 $contenttype = new \contenttype_h5p\contenttype(context_system::instance());
50 $content = $contenttype->create_content($record);
51
52 // Create a dummy file.
53 $filename = 'content.h5p';
3a6ca392 54 $dummy = [
bd4e0a76
AA
55 'contextid' => \context_system::instance()->id,
56 'component' => 'contentbank',
57 'filearea' => 'public',
58 'itemid' => $content->get_id(),
59 'filepath' => '/',
60 'filename' => $filename
3a6ca392 61 ];
bd4e0a76
AA
62 $fs = get_file_storage();
63 $fs->create_file_from_string($dummy, 'dummy content');
64
65 $file = $content->get_file();
66 $this->assertInstanceOf(\stored_file::class, $file);
67 $this->assertEquals($filename, $file->get_filename());
68 }
69}