Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 25... Línea 25...
25
 * @category   test
25
 * @category   test
26
 * @copyright  2021 Sara Arjona (sara@moodle.com)
26
 * @copyright  2021 Sara Arjona (sara@moodle.com)
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @coversDefaultClass \tool_admin_presets\local\action\import
28
 * @coversDefaultClass \tool_admin_presets\local\action\import
29
 */
29
 */
30
class import_test extends \advanced_testcase {
30
final class import_test extends \advanced_testcase {
Línea 31... Línea 31...
31
 
31
 
32
    /**
32
    /**
33
     * Test the behaviour of execute() method.
33
     * Test the behaviour of execute() method.
34
     *
34
     *
Línea 42... Línea 42...
42
     * @param bool $expecteddebugging Whether debugging message will be thrown or not.
42
     * @param bool $expecteddebugging Whether debugging message will be thrown or not.
43
     * @param string|null $expectedexception Expected exception class (if that's the case).
43
     * @param string|null $expectedexception Expected exception class (if that's the case).
44
     * @param string|null $expectedpresetname Expected preset name.
44
     * @param string|null $expectedpresetname Expected preset name.
45
     */
45
     */
46
    public function test_import_execute(string $filecontents, bool $expectedpreset, bool $expectedsettings = false,
46
    public function test_import_execute(string $filecontents, bool $expectedpreset, bool $expectedsettings = false,
47
            bool $expectedplugins = false, bool $expecteddebugging = false, string $expectedexception = null,
47
            bool $expectedplugins = false, bool $expecteddebugging = false, ?string $expectedexception = null,
48
            string $expectedpresetname = 'Imported preset'): void {
48
            string $expectedpresetname = 'Imported preset'): void {
49
        global $DB, $USER;
49
        global $DB, $USER;
Línea 50... Línea 50...
50
 
50
 
51
        $this->resetAfterTest();
51
        $this->resetAfterTest();
Línea 79... Línea 79...
79
        $_POST['mode'] = 'execute';
79
        $_POST['mode'] = 'execute';
Línea 80... Línea 80...
80
 
80
 
81
        $action = new import();
81
        $action = new import();
82
        $sink = $this->redirectEvents();
82
        $sink = $this->redirectEvents();
-
 
83
        try {
-
 
84
            // Suppress warnings and load XML.
-
 
85
            $invokable = self::get_invokable();
83
        try {
86
            set_error_handler($invokable, E_WARNING);
84
            $action->execute();
87
            $action->execute();
85
        } catch (\exception $e) {
88
        } catch (\exception $e) {
86
            // If import action was successfull, redirect should be called so we will encounter an
89
            // If import action was successfull, redirect should be called so we will encounter an
87
            // 'unsupported redirect error' moodle_exception.
90
            // 'unsupported redirect error' moodle_exception.
88
            if ($expectedexception) {
91
            if ($expectedexception) {
89
                $this->assertInstanceOf($expectedexception, $e);
92
                $this->assertInstanceOf($expectedexception, $e);
90
            } else {
93
            } else {
91
                $this->assertInstanceOf(\moodle_exception::class, $e);
94
                $this->assertInstanceOf(\moodle_exception::class, $e);
-
 
95
            }
92
            }
96
            restore_error_handler();
93
        } finally {
97
        } finally {
94
            if ($expecteddebugging) {
98
            if ($expecteddebugging) {
95
                $this->assertDebuggingCalled();
99
                $this->assertDebuggingCalled();
Línea 152... Línea 156...
152
                        'block' => [
156
                        'block' => [
153
                            'html' => 0,
157
                            'html' => 0,
154
                            'activity_modules' => 1,
158
                            'activity_modules' => 1,
155
                        ],
159
                        ],
156
                        'mod' => [
160
                        'mod' => [
157
                            'chat' => 0,
161
                            'page' => 0,
158
                            'data' => 0,
162
                            'data' => 0,
159
                            'lesson' => 1,
163
                            'lesson' => 1,
160
                        ],
164
                        ],
161
                    ];
165
                    ];
162
                    foreach ($plugins as $plugin) {
166
                    foreach ($plugins as $plugin) {
Línea 188... Línea 192...
188
    /**
192
    /**
189
     * Data provider for test_import_execute().
193
     * Data provider for test_import_execute().
190
     *
194
     *
191
     * @return array
195
     * @return array
192
     */
196
     */
193
    public function import_execute_provider(): array {
197
    public static function import_execute_provider(): array {
194
        $fixturesfolder = __DIR__ . '/../../../../../presets/tests/fixtures/';
198
        $fixturesfolder = __DIR__ . '/../../../../../presets/tests/fixtures/';
Línea 195... Línea 199...
195
 
199
 
196
        return [
200
        return [
197
            'Import settings from an empty file' => [
201
            'Import settings from an empty file' => [