Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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   */
  35  class 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';
  54          $dummy = [
  55              'contextid' => \context_system::instance()->id,
  56              'component' => 'contentbank',
  57              'filearea' => 'public',
  58              'itemid' => $content->get_id(),
  59              'filepath' => '/',
  60              'filename' => $filename
  61          ];
  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  }