Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 31... Línea 31...
31
 * @package     core
31
 * @package     core
32
 * @covers      \core_admin\external\set_plugin_state
32
 * @covers      \core_admin\external\set_plugin_state
33
 * @copyright   2023 Andrew Lyons <andrew@nicols.co.uk>
33
 * @copyright   2023 Andrew Lyons <andrew@nicols.co.uk>
34
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
35
 */
36
class set_plugin_order_test extends \externallib_advanced_testcase {
36
final class set_plugin_order_test extends \externallib_advanced_testcase {
37
    /**
37
    /**
38
     * Text execute method for editor plugins, which support ordering.
38
     * Text execute method for editor plugins, which support ordering.
39
     *
39
     *
40
     * @dataProvider execute_editor_provider
40
     * @dataProvider execute_editor_provider
41
     * @param string $initialstate The initial state of the plugintype
41
     * @param string $initialstate The initial state of the plugintype
Línea 70... Línea 70...
70
    /**
70
    /**
71
     * Data provider for base tests of the execute method.
71
     * Data provider for base tests of the execute method.
72
     *
72
     *
73
     * @return array
73
     * @return array
74
     */
74
     */
75
    public function execute_editor_provider(): array {
75
    public static function execute_editor_provider(): array {
76
        $pluginmanager = \core_plugin_manager::instance();
76
        $pluginmanager = \core_plugin_manager::instance();
77
        $allplugins = array_keys($pluginmanager->get_plugins_of_type('editor'));
77
        $allplugins = array_keys($pluginmanager->get_plugins_of_type('editor'));
Línea 78... Línea 78...
78
 
78
 
79
        // Disabled editors are listed alphabetically at the end.
79
        // Disabled editors are listed alphabetically at the end.
Línea 84... Línea 84...
84
            );
84
            );
85
        };
85
        };
86
        return [
86
        return [
87
            [
87
            [
88
                'initialstate' => 'textarea,tiny',
88
                'initialstate' => 'textarea,tiny',
89
                'pluginname' => 'editor_textarea',
89
                'plugin' => 'editor_textarea',
90
                'direction' => 1, // DOWN.
90
                'direction' => 1, // DOWN.
91
                'expected' => $getorder([
91
                'neworder' => $getorder([
92
                    'tiny',
92
                    'tiny',
93
                    'textarea',
93
                    'textarea',
94
                ]),
94
                ]),
95
                'newtexteditors' => 'tiny,textarea',
95
                'newstate' => 'tiny,textarea',
96
            ],
96
            ],
97
            [
97
            [
98
                'initialstate' => 'textarea,tiny',
98
                'initialstate' => 'textarea,tiny',
99
                'pluginname' => 'editor_textarea',
99
                'plugin' => 'editor_textarea',
100
                'direction' => -1, // UP.
100
                'direction' => -1, // UP.
101
                'expected' => $getorder([
101
                'neworder' => $getorder([
102
                    'textarea',
102
                    'textarea',
103
                    'tiny',
103
                    'tiny',
104
                ]),
104
                ]),
105
                'newtexteditors' => 'textarea,tiny',
105
                'newstate' => 'textarea,tiny',
106
            ],
106
            ],
107
            [
107
            [
108
                'initialstate' => 'textarea,tiny',
108
                'initialstate' => 'textarea,tiny',
109
                'pluginname' => 'editor_tiny',
109
                'plugin' => 'editor_tiny',
110
                'direction' => 1, // DOWN.
110
                'direction' => 1, // DOWN.
111
                // Tiny is already at the bottom of the list of enabled plugins.
111
                // Tiny is already at the bottom of the list of enabled plugins.
112
                'expected' => $getorder([
112
                'neworder' => $getorder([
113
                    'textarea',
113
                    'textarea',
114
                    'tiny',
114
                    'tiny',
115
                ]),
115
                ]),
116
                'newtexteditors' => 'textarea,tiny',
116
                'newstate' => 'textarea,tiny',
117
            ],
117
            ],
118
            [
118
            [
119
                'initialstate' => 'textarea,tiny',
119
                'initialstate' => 'textarea,tiny',
120
                'pluginname' => 'editor_atto',
120
                'plugin' => 'editor_atto',
121
                'direction' => 1, // DOWN.
121
                'direction' => 1, // DOWN.
122
                // Atto is not enabled. Disabled editors are listed lexically after enabled editors.
122
                // Atto is not enabled. Disabled editors are listed lexically after enabled editors.
123
                'expected' => $getorder([
123
                'neworder' => $getorder([
124
                    'textarea',
124
                    'textarea',
125
                    'tiny',
125
                    'tiny',
126
                ]),
126
                ]),
127
                'newtexteditors' => 'textarea,tiny',
127
                'newstate' => 'textarea,tiny',
128
            ],
128
            ],
129
        ];
129
        ];
130
    }
130
    }
Línea 131... Línea 131...
131
 
131
 
-
 
132
    /**
-
 
133
     * Test re-ordering plugins where one plugin is not enabled.
-
 
134
     *
-
 
135
     *  Media plugins are ordered by rank, with enabled plugins first.
-
 
136
     * This is similar to the editors test but covers a scenario that cannot be covered by the editors test due to
-
 
137
     * not having enough plugins.
-
 
138
     */
-
 
139
    public function test_execute_media_including_disabled(): void {
-
 
140
        global $CFG;
-
 
141
 
-
 
142
        $this->resetAfterTest();
-
 
143
        $this->setAdminUser();
-
 
144
 
-
 
145
        $CFG->media_plugins_sortorder = 'videojs,vimeo,html5video';
-
 
146
 
-
 
147
        set_plugin_order::execute('youtube', -1);
-
 
148
 
-
 
149
        $this->assertSame('videojs,vimeo,html5video', $CFG->media_plugins_sortorder);
-
 
150
    }
-
 
151
 
132
    /**
152
    /**
133
     * Text execute method for plugins which do not support ordering.
153
     * Text execute method for plugins which do not support ordering.
134
     *
154
     *
135
     * @dataProvider execute_non_orderable_provider
155
     * @dataProvider execute_non_orderable_provider
136
     * @param string $plugin
156
     * @param string $plugin
Línea 140... Línea 160...
140
        $this->setAdminUser();
160
        $this->setAdminUser();
Línea 141... Línea 161...
141
 
161
 
142
        $this->assertIsArray(set_plugin_order::execute($plugin, 1));
162
        $this->assertIsArray(set_plugin_order::execute($plugin, 1));
Línea 143... Línea 163...
143
    }
163
    }
144
 
164
 
145
    public function execute_non_orderable_provider(): array {
165
    public static function execute_non_orderable_provider(): array {
146
        return [
166
        return [
147
            // Activities do not support ordering.
167
            // Activities do not support ordering.
148
            ['mod_assign'],
168
            ['mod_assign'],