Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 37... Línea 37...
37
 * @package    core_h5p
37
 * @package    core_h5p
38
 * @copyright  2020 Sara Arjona <sara@moodle.com>
38
 * @copyright  2020 Sara Arjona <sara@moodle.com>
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 * @coversDefaultClass \core_h5p\api
40
 * @coversDefaultClass \core_h5p\api
41
 */
41
 */
42
class api_test extends \advanced_testcase {
42
final class api_test extends \advanced_testcase {
Línea 43... Línea 43...
43
 
43
 
44
    /**
44
    /**
45
     * Test the behaviour of delete_library().
45
     * Test the behaviour of delete_library().
46
     *
46
     *
Línea 96... Línea 96...
96
    /**
96
    /**
97
     * Data provider for test_delete_library().
97
     * Data provider for test_delete_library().
98
     *
98
     *
99
     * @return array
99
     * @return array
100
     */
100
     */
101
    public function delete_library_provider(): array {
101
    public static function delete_library_provider(): array {
102
        return [
102
        return [
103
            'Delete MainLibrary' => [
103
            'Delete MainLibrary' => [
104
                'MainLibrary',
104
                'MainLibrary',
105
                0,
105
                0,
106
                6,
106
                6,
Línea 190... Línea 190...
190
    /**
190
    /**
191
     * Data provider for test_get_dependent_libraries().
191
     * Data provider for test_get_dependent_libraries().
192
     *
192
     *
193
     * @return array
193
     * @return array
194
     */
194
     */
195
    public function get_dependent_libraries_provider(): array {
195
    public static function get_dependent_libraries_provider(): array {
196
        return [
196
        return [
197
            'Main library of a content' => [
197
            'Main library of a content' => [
198
                'MainLibrary',
198
                'MainLibrary',
199
                0,
199
                0,
200
            ],
200
            ],
Línea 254... Línea 254...
254
    /**
254
    /**
255
     * Data provider for test_get_library().
255
     * Data provider for test_get_library().
256
     *
256
     *
257
     * @return array
257
     * @return array
258
     */
258
     */
259
    public function get_library_provider(): array {
259
    public static function get_library_provider(): array {
260
        return [
260
        return [
261
            'Main library of a content' => [
261
            'Main library of a content' => [
262
                'MainLibrary',
262
                'MainLibrary',
263
                false,
263
                false,
264
            ],
264
            ],
Línea 285... Línea 285...
285
        $this->resetAfterTest();
285
        $this->resetAfterTest();
286
        $factory = new factory();
286
        $factory = new factory();
Línea 287... Línea 287...
287
 
287
 
288
        // Create the H5P data.
288
        // Create the H5P data.
289
        $filename = 'find-the-words.h5p';
289
        $filename = 'find-the-words.h5p';
290
        $path = __DIR__ . '/fixtures/' . $filename;
290
        $path = self::get_fixture_path(__NAMESPACE__, $filename);
291
        $fakefile = helper::create_fake_stored_file_from_path($path);
291
        $fakefile = helper::create_fake_stored_file_from_path($path);
292
        $config = (object)[
292
        $config = (object)[
293
            'frame' => 1,
293
            'frame' => 1,
294
            'export' => 1,
294
            'export' => 1,
Línea 348... Línea 348...
348
        $factory = new factory();
348
        $factory = new factory();
349
        $syscontext = \context_system::instance();
349
        $syscontext = \context_system::instance();
Línea 350... Línea 350...
350
 
350
 
351
        // Create the original file.
351
        // Create the original file.
352
        $filename = 'greeting-card.h5p';
352
        $filename = 'greeting-card.h5p';
353
        $path = __DIR__ . '/fixtures/' . $filename;
353
        $path = self::get_fixture_path(__NAMESPACE__, $filename);
354
        $originalfile = helper::create_fake_stored_file_from_path($path);
354
        $originalfile = helper::create_fake_stored_file_from_path($path);
355
        $originalfilerecord = [
355
        $originalfilerecord = [
356
            'contextid' => $originalfile->get_contextid(),
356
            'contextid' => $originalfile->get_contextid(),
357
            'component' => $originalfile->get_component(),
357
            'component' => $originalfile->get_component(),
Línea 490... Línea 490...
490
            $itemid = $post->id;
490
            $itemid = $post->id;
491
        }
491
        }
Línea 492... Línea 492...
492
 
492
 
493
        // Create the file.
493
        // Create the file.
494
        $filename = 'greeting-card.h5p';
494
        $filename = 'greeting-card.h5p';
495
        $path = __DIR__ . '/fixtures/' . $filename;
495
        $path = self::get_fixture_path(__NAMESPACE__, $filename);
496
        if ($filecomponent === 'contentbank') {
496
        if ($filecomponent === 'contentbank') {
497
            $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
497
            $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
498
            $contents = $generator->generate_contentbank_data(
498
            $contents = $generator->generate_contentbank_data(
499
                'contenttype_h5p',
499
                'contenttype_h5p',
Línea 527... Línea 527...
527
    /**
527
    /**
528
     * Data provider for test_can_edit_content().
528
     * Data provider for test_can_edit_content().
529
     *
529
     *
530
     * @return array
530
     * @return array
531
     */
531
     */
532
    public function can_edit_content_provider(): array {
532
    public static function can_edit_content_provider(): array {
533
        return [
533
        return [
534
            // Component = user.
534
            // Component = user.
535
            'user: Admin user is author' => [
535
            'user: Admin user is author' => [
536
                'currentuser' => 'admin',
536
                'currentuser' => 'admin',
537
                'fileauthor' => 'admin',
537
                'fileauthor' => 'admin',
Línea 752... Línea 752...
752
        $this->resetAfterTest();
752
        $this->resetAfterTest();
753
        $factory = new factory();
753
        $factory = new factory();
Línea 754... Línea 754...
754
 
754
 
755
        // Create the H5P data.
755
        // Create the H5P data.
756
        $filename = 'find-the-words.h5p';
756
        $filename = 'find-the-words.h5p';
757
        $path = __DIR__ . '/fixtures/' . $filename;
757
        $path = self::get_fixture_path(__NAMESPACE__, $filename);
758
        $fakefile = helper::create_fake_stored_file_from_path($path);
758
        $fakefile = helper::create_fake_stored_file_from_path($path);
759
        $config = (object)[
759
        $config = (object)[
760
            'frame' => 1,
760
            'frame' => 1,
761
            'export' => 1,
761
            'export' => 1,
Línea 810... Línea 810...
810
        $this->resetAfterTest();
810
        $this->resetAfterTest();
811
        $factory = new factory();
811
        $factory = new factory();
Línea 812... Línea 812...
812
 
812
 
813
        // Create the H5P data.
813
        // Create the H5P data.
814
        $filename = 'find-the-words.h5p';
814
        $filename = 'find-the-words.h5p';
815
        $path = __DIR__ . '/fixtures/' . $filename;
815
        $path = self::get_fixture_path(__NAMESPACE__, $filename);
816
        $fakefile = helper::create_fake_stored_file_from_path($path);
816
        $fakefile = helper::create_fake_stored_file_from_path($path);
817
        $config = (object)[
817
        $config = (object)[
818
            'frame' => 1,
818
            'frame' => 1,
819
            'export' => 1,
819
            'export' => 1,
Línea 961... Línea 961...
961
    /**
961
    /**
962
     * Data provider for test_set_library_enabled().
962
     * Data provider for test_set_library_enabled().
963
     *
963
     *
964
     * @return array
964
     * @return array
965
     */
965
     */
966
    public function set_library_enabled_provider(): array {
966
    public static function set_library_enabled_provider(): array {
967
        return [
967
        return [
968
            'Disable existing library' => [
968
            'Disable existing library' => [
969
                'libraryname' => 'MainLibrary',
969
                'libraryname' => 'MainLibrary',
970
                'action' => 'disable',
970
                'action' => 'disable',
971
                'expected' => 0,
971
                'expected' => 0,
Línea 1066... Línea 1066...
1066
    /**
1066
    /**
1067
     * Data provider for test_is_library_enabled().
1067
     * Data provider for test_is_library_enabled().
1068
     *
1068
     *
1069
     * @return array
1069
     * @return array
1070
     */
1070
     */
1071
    public function is_library_enabled_provider(): array {
1071
    public static function is_library_enabled_provider(): array {
1072
        return [
1072
        return [
1073
            'Library with 2 versions, one of them disabled' => [
1073
            'Library with 2 versions, one of them disabled' => [
1074
                'libraryname' => 'H5P.Lib1',
1074
                'libraryname' => 'H5P.Lib1',
1075
                'expected' => false,
1075
                'expected' => false,
1076
            ],
1076
            ],
Línea 1192... Línea 1192...
1192
    /**
1192
    /**
1193
     * Data provider for test_is_valid_package().
1193
     * Data provider for test_is_valid_package().
1194
     *
1194
     *
1195
     * @return array
1195
     * @return array
1196
     */
1196
     */
1197
    public function is_valid_package_provider(): array {
1197
    public static function is_valid_package_provider(): array {
1198
        return [
1198
        return [
1199
            'Valid H5P file (as admin)' => [
1199
            'Valid H5P file (as admin)' => [
1200
                'filename' => '/fixtures/greeting-card.h5p',
1200
                'filename' => '/fixtures/greeting-card.h5p',
1201
                'expected' => true,
1201
                'expected' => true,
1202
                'isadmin' => true,
1202
                'isadmin' => true,