__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Testing the H5PEditorAjaxInterface interface implementation.
 *
 * @package    core_h5p
 * @category   test
 * @copyright  2020 Victor Deniz <victor@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace core_h5p;

use core_h5p\local\library\autoloader;
use Moodle\H5PCore;

/**
 *
 * Test class covering the H5PEditorAjaxInterface interface implementation.
 *
 * @package    core_h5p
 * @copyright  2020 Victor Deniz <victor@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 *
 * @runTestsInSeparateProcesses
 */
final class editor_ajax_test extends \advanced_testcase {

    /** @var editor_ajax H5P editor ajax instance */
    protected $editorajax;

    /**
     * Set up function for tests.
     */
    protected function setUp(): void {
        parent::setUp();

        autoloader::register();

        $this->editorajax = new editor_ajax();
    }

    /**
     * Test that getLatestLibraryVersions method retrieves the latest installed library versions.
     */
    public function test_getLatestLibraryVersions(): void {
        $this->resetAfterTest();

        $generator = \testing_util::get_data_generator();
        $h5pgenerator = $generator->get_plugin_generator('core_h5p');

        // Create several libraries records.
        $h5pgenerator->create_library_record('Library1', 'Lib1', 2, 0);
        $lib2 = $h5pgenerator->create_library_record('Library2', 'Lib2', 2, 1);
        $expectedlibraries[] = $lib2->id;
        $lib3 = $h5pgenerator->create_library_record('Library3', 'Lib3', 1, 3);
        $expectedlibraries[] = $lib3->id;
        $h5pgenerator->create_library_record('Library1', 'Lib1', 2, 1);
        $lib12 = $h5pgenerator->create_library_record('Library1', 'Lib1', 3, 0);
        $expectedlibraries[] = $lib12->id;

        $actuallibraries = $this->editorajax->getLatestLibraryVersions();
        ksort($actuallibraries);

        $this->assertEquals($expectedlibraries, array_keys($actuallibraries));
    }

    /**
     * Test that getContentTypeCache method retrieves the latest library versions that exists locally.
     */
    public function test_getContentTypeCache(): void {
        $this->resetAfterTest();

        $h5pgenerator = \testing_util::get_data_generator()->get_plugin_generator('core_h5p');

        // Create several libraries records.
        $lib1 = $h5pgenerator->create_library_record('Library1', 'Lib1', 1, 0, 1, '', null, 'http://tutorial.org',
            'http://example.org');
        $lib2 = $h5pgenerator->create_library_record('Library2', 'Lib2', 2, 0, 1, '', null, 'http://tutorial.org');
        $lib3 = $h5pgenerator->create_library_record('Library3', 'Lib3', 3, 0);
        $libs = [$lib1, $lib2, $lib3];

        $libraries = $this->editorajax->getContentTypeCache();
        $this->assertCount(3, $libraries);
        foreach ($libs as $lib) {
            $library = $libraries[$lib->id];
            $this->assertEquals($library->id, $lib->id);
            $this->assertEquals($library->machine_name, $lib->machinename);
            $this->assertEquals($library->major_version, $lib->majorversion);
            $this->assertEquals($library->tutorial, $lib->tutorial);
            $this->assertEquals($library->example, $lib->example);
            $this->assertEquals($library->is_recommended, 0);
            $this->assertEquals($library->summary, '');
        }
    }

    /**
     * Test that the method getTranslations retrieves the translations of several libraries.
     *
     * @dataProvider  get_translations_provider
     *
     * @param  array  $datalibs      Libraries to create
     * @param  string $lang          Language to get the translations
     * @param  bool   $emptyexpected True if empty translations are expected; false otherwise
     * @param  array  $altstringlibs When defined, libraries are no created and the content here is used to call the method
     */
    public function test_get_translations(array $datalibs, string $lang, bool $emptyexpected, ?array $altstringlibs = []): void {
        $this->resetAfterTest();

        // Fetch generator.
        $generator = \testing_util::get_data_generator();
        $h5pgenerator = $generator->get_plugin_generator('core_h5p');

        $h5pfilestorage = new file_storage();
        $h5ptempath = $h5pfilestorage->getTmpPath();

        if (!empty($altstringlibs)) {
            // Libraries won't be created and the getTranslation method will be called with this $altstringlibs.
            $stringlibs = $altstringlibs;
        } else {
            $stringlibs = [];
            foreach ($datalibs as $datalib) {
                // Create DB entry for this library.
                $tmplib = $h5pgenerator->create_library_record($datalib['machinename'], $datalib['title'], $datalib['majorversion'],
                    $datalib['minorversion']);
                // Create the files for this libray.
                [$library, $files] = $h5pgenerator->create_library($h5ptempath, $tmplib->id, $datalib['machinename'],
                    $datalib['majorversion'], $datalib['minorversion'], $datalib['translation']);
                $h5pfilestorage->saveLibrary($library);
                $stringlibs[] = H5PCore::libraryToString($library);
            }
        }

        $translations = $this->editorajax->getTranslations($stringlibs, $lang);

        if ($emptyexpected) {
            $this->assertEmpty($translations);
        } else {
            foreach ($translations as $stringlib => $translation) {
                $this->assertEquals($datalibs[$stringlib]['translation'][$lang], $translation);
            }
        }
    }

    /**
     * Data provider for test_get_translations().
     *
     * @return array
     */
    public static function get_translations_provider(): array {
        return [
            'No library' => [
                [],
                'es',
                true,
                ['Library1 1.2']
            ],
            'One library with existing translation (es)' => [
                [
                    'Library1 1.2' => [
                        'machinename' => 'Library1',
                        'title' => 'Lib1',
                        'majorversion' => 1,
                        'minorversion' => 2,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ]
                ],
                'es',
                false
            ],
            'One library with existing translation (fr)' => [
                [
                    'Library1 1.2' => [
                        'machinename' => 'Library1',
                        'title' => 'Lib1',
                        'majorversion' => 1,
                        'minorversion' => 2,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ]
                ],
                'fr',
                false
            ],
            'One library with unexisting translation (de)' => [
                [
                    'Library1 1.2' => [
                        'machinename' => 'Library1',
                        'title' => 'Lib1',
                        'majorversion' => 1,
                        'minorversion' => 2,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ]
                ],
                'de',
                true
            ],
            'Two libraries with existing translation (es)' => [
                [
                    'Library1 1.2' => [
                        'machinename' => 'Library1',
                        'title' => 'Lib1',
                        'majorversion' => 1,
                        'minorversion' => 2,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ],
                    'Library2 3.4' => [
                        'machinename' => 'Library2',
                        'title' => 'Lib1',
                        'majorversion' => 3,
                        'minorversion' => 4,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ]
                ],
                'es',
                false
            ],
            'Two libraries with unexisting translation (de)' => [
                [
                    'Library1 1.2' => [
                        'machinename' => 'Library1',
                        'title' => 'Lib1',
                        'majorversion' => 1,
                        'minorversion' => 2,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ],
                    'Library2 3.4' => [
                        'machinename' => 'Library2',
                        'title' => 'Lib1',
                        'majorversion' => 3,
                        'minorversion' => 4,
                        'translation' => [
                            'es' => '{"libraryStrings": {"key": "valor"}}',
                            'fr' => '{"libraryStrings": {"key": "valeur"}}',
                        ],
                    ]
                ],
                'de',
                true
            ],
        ];
    }
}

Filemanager

Name Type Size Permission Actions
behat Folder 0777
event Folder 0777
external Folder 0777
fixtures Folder 0777
generator Folder 0777
local Folder 0777
api_test.php File 46.5 KB 0777
editor_ajax_test.php File 10.54 KB 0777
editor_framework_test.php File 14.79 KB 0777
editor_test.php File 8.73 KB 0777
file_storage_test.php File 36.06 KB 0777
framework_test.php File 92.3 KB 0777
generator_test.php File 23.43 KB 0777
h5p_core_test.php File 7.87 KB 0777
helper_test.php File 18.36 KB 0777
Filemanager