Skip to content

Commit

Permalink
SubSup: Fix git action error #800212
Browse files Browse the repository at this point in the history
  • Loading branch information
Khoa Nguyen Dang committed Oct 8, 2024
1 parent 96e6774 commit 4e5aeaa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 100 deletions.
5 changes: 2 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Privacy Subsystem implementation for editor_ousupsub.
*
Expand All @@ -23,8 +24,6 @@

namespace editor_ousupsub\privacy;

defined('MOODLE_INTERNAL') || die();


/**
* Privacy Subsystem for editor_ousupsub implementing null_provider.
Expand All @@ -39,7 +38,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}
}
2 changes: 0 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Run all OU sup-sub editor upgrade steps between the current DB version and
* the current version on disk.
Expand Down
5 changes: 3 additions & 2 deletions lang/en/editor_ousupsub.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
$string['plugin_title_shortcut'] = '{$a->title} [{$a->shortcut}]';
$string['pluginname'] = 'Superscript/subscript editor';
$string['privacy:metadata'] = 'The Superscript/subscript editor plugin does not store any personal data.';
$string['redo'] = 'Redo';
$string['settings'] = 'Superscript/subscript editor settings';
$string['subscript'] = 'Subscript';
$string['superscript'] = 'Superscript';
$string['undo'] = 'Undo';
$string['useeditor'] = 'Use this editor';
$string['useeditor_desc'] = 'Use this editor in question types, in preference to the old superscript/subscript editor, if both are installed.';
$string['redo'] = 'Redo';
$string['undo'] = 'Undo';

59 changes: 12 additions & 47 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* YUI text editor integration.
* New OU text editor integration.
*
* @package editor_ousupsub
* @copyright 2014 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();


/**
* This is the texteditor implementation.
Expand All @@ -48,7 +46,7 @@ public function supported_by_browser() {
*/
public function get_supported_formats() {
// FORMAT_MOODLE is not supported here, sorry.
return array(FORMAT_HTML => FORMAT_HTML);
return [FORMAT_HTML => FORMAT_HTML];
}

/**
Expand All @@ -72,9 +70,9 @@ public function supports_repositories() {
*
* @param string $elementid
* @param array $options
* @param null $fpoptions
* @param obejct $fpoptions file picker options
*/
public function use_editor($elementid, array $options = null, $fpoptions = null) {
public function use_editor($elementid, ?array $options = null, $fpoptions = null) {
global $PAGE, $OUTPUT;

if (empty($options['context'])) {
Expand All @@ -86,25 +84,25 @@ public function use_editor($elementid, array $options = null, $fpoptions = null)

switch ($options['supsub']) {
case 'both':
$groups = array('style1' => array('superscript', 'subscript'));
$groups = ['style1' => ['superscript', 'subscript']];
break;

case 'sup':
$groups = array('style1' => array('superscript'));
$groups = ['style1' => ['superscript']];
break;

case 'sub':
$groups = array('style1' => array('subscript'));
$groups = ['style1' => ['subscript']];
break;

default:
throw new coding_exception("Invalid value '" .$options['supsub'] .
"' for option 'supsub'. Must be one of 'both', 'sup' or 'sub'.");
}

$groupplugins = array();
$groupplugins = [];
foreach ($groups['style1'] as $plugin) {
$groupplugins[] = array('name' => $plugin, 'params' => array());
$groupplugins[] = ['name' => $plugin, 'params' => []];
}

$PAGE->requires->js_call_amd('editor_ousupsub/editor', 'loadEditor', [
Expand All @@ -119,42 +117,9 @@ public function use_editor($elementid, array $options = null, $fpoptions = null)
'subscript' => [
'icon' => $OUTPUT->pix_icon('e/subscript', '', 'core'),
'title' => get_string('button_sub_title', 'editor_ousupsub'),
]
]
]
],
],
],
]);
}

/**
* Create a params array to init the editor.
*
* @param string $elementid
* @param array $options
* @param array $fpoptions
*/
protected function get_init_params($elementid, array $options = null, array $fpoptions = null, $plugins = null) {
global $PAGE;

$directionality = get_string('thisdirection', 'langconfig');
$strtime = get_string('strftimetime');
$strdate = get_string('strftimedaydate');
$lang = current_language();
$contentcss = $PAGE->theme->editor_css_url()->out(false);

$params = array(
'elementid' => $elementid,
'content_css' => $contentcss,
'contextid' => $options['context']->id,
'language' => $lang,
'directionality' => $directionality,
'filepickeroptions' => array(),
'plugins' => $plugins,
'pageHash' => sha1($PAGE->url)
);
if ($fpoptions) {
$params['filepickeroptions'] = $fpoptions;
}

return $params;
}
}
48 changes: 21 additions & 27 deletions tests/behat/behat_editor_ousupsub.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class behat_editor_ousupsub extends behat_base {
* Opens an ousupsubtest page.
*
* @Given /^I am on the integrated "(sup|sub|both)" editor test page$/
* @param string $type
*/
public function i_am_on_integrated_test_page($type) {
$this->getSession()->visit($this->locate_path(
Expand All @@ -58,7 +59,7 @@ public function i_am_on_standalone_test_page() {
*
* @Given /^I select the text in the "([^"]*)" ousupsub editor$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $field
* @param string $fieldlocator
* @return void
*/
public function select_the_text_in_the_ousupsub_editor($fieldlocator) {
Expand All @@ -81,7 +82,7 @@ public function select_the_text_in_the_ousupsub_editor($fieldlocator) {
* @Given /^I should see "([^"]*)" in the "([^"]*)" ousupsub editor$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $text
* @param string $field
* @param string $fieldlocator
* @return void
*/
public function should_see_in_the_ousupsub_editor($text, $fieldlocator) {
Expand Down Expand Up @@ -130,8 +131,8 @@ public function i_set_the_standalone_ousupsub_editor_to($label, $text) {
*
* @Given /^I select the range "([^"]*)" in the "([^"]*)" ousupsub editor$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $text
* @param string $field
* @param string $range
* @param string $fieldlocator
*/
public function select_range_in_the_ousupsub_editor($range, $fieldlocator) {
// NodeElement.keyPress simply doesn't work.
Expand Down Expand Up @@ -205,7 +206,7 @@ function SelectTextBehat() {
* @Given /^I press the key "([^"]*)" in the "([^"]*)" ousupsub editor$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $keys
* @param string $field
* @param string $fieldlocator
*/
public function press_key_in_the_ousupsub_editor($keys, $fieldlocator) {
// NodeElement.keyPress simply doesn't work.
Expand Down Expand Up @@ -289,7 +290,7 @@ function TriggerKeyPressBehat(id, keys) {
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $action 'enter', 'insert' or 'append' text.
* @param string $text
* @param string $field
* @param string $fieldlocator
*/
public function enter_text_in_the_ousupsub_editor($action, $text, $fieldlocator) {
// NodeElement.keyPress simply doesn't work.
Expand Down Expand Up @@ -329,7 +330,7 @@ function EnterTextBehat (action, id, text) {
* @Given /^I paste the text "([^"]*)" in the "([^"]*)" ousupsub editor$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $text
* @param string $field
* @param string $fieldlocator
*/
public function paste_text_in_the_ousupsub_editor($text, $fieldlocator) {
// NodeElement.keyPress simply doesn't work.
Expand Down Expand Up @@ -383,8 +384,7 @@ function PasteTextBehat (id, text) {
* Select the first button in a stand-alone ousupsub field.
*
* @Given /^I select and click the first button in the "([^"]*)" ousupsub editor$/
* @param string $text
* @param string $field
* @param string $fieldlocator
*/
public function select_and_click_first_button_in_the_ousupsub_editor($fieldlocator) {
// NodeElement.keyPress simply doesn't work.
Expand Down Expand Up @@ -415,67 +415,64 @@ function SelectAndClickFirstButtonBehat (id) {
*
* @Given /^I press the superscript key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_superscript_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_superscript_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('94', 'Input'));
['94', 'Input']);
}

/**
* Press the subscript key in an ousupsub field.
*
* @Given /^I press the subscript key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_subscript_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_subscript_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('95', 'Input'));
['95', 'Input']);
}

/**
* Press the up arrow key in an ousupsub field.
*
* @Given /^I press the up arrow key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_up_arrow_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_up_arrow_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('\'ArrowUp\'', 'Input'));
['\'ArrowUp\'', 'Input']);
}

/**
* Press the down arrow key in a stand-alone ousupsub field.
*
* @Given /^I press the down arrow key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_down_arrow_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_down_arrow_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('\'ArrowDown\'', 'Input'));
['\'ArrowDown\'', 'Input']);
}

/**
* Press the undo key in an ousupsub field.
*
* @Given /^I press the undo key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_undo_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_undo_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('\'ctrlKey\', \'z\'', 'Input'));
['\'ctrlKey\', \'z\'', 'Input']);
}

/**
* Press the redo key in an ousupsub field.
*
* @Given /^I press the redo key in the "([^"]*)" ousupsub editor$/
*/
public function i_press_redo_key_in_the_ousupsub_edito($fieldlocator) {
public function i_press_redo_key_in_the_ousupsub_edito() {
$this->execute('behat_editor_ousupsub::press_key_in_the_ousupsub_editor',
array('\'ctrlKey\', \'y\'', 'Input'));
['\'ctrlKey\', \'y\'', 'Input']);
}

/**
* Returns a javascript helper method to update the textarea text from the contenteditable div
* and trigger required key and html events for the editor.
*
* @method UpdateTextArea
* @param {String} id
*/
protected function get_js_update_textarea() {
$js = $this->get_js_get_editor();
Expand All @@ -490,9 +487,6 @@ function UpdateTextArea(id) {
/**
* Returns a javascript helper method to update the textarea text from the contenteditable div
* and trigger required key and html events for the editor.
*
* @method UpdateTextArea
* @param {String} id
*/
protected function get_js_get_editor() {
$js = '
Expand Down
28 changes: 9 additions & 19 deletions tests/fixtures/editortestpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
require_login();
require_capability('moodle/site:config', context_system::instance());

if (!in_array($type, array('both', 'sub', 'sup'))) {
if (!in_array($type, ['both', 'sub', 'sup'])) {
throw new coding_exception("'type' in the URL must be 'both', 'sub', or 'sup'.");
}

Expand All @@ -45,35 +45,25 @@
echo $OUTPUT->header();
echo html_writer::tag('h2', 'New supsub');
echo html_writer::label('Input', 'supsub') . ' ';
echo html_writer::tag('textarea', '', array('name' => 'supsub', 'id' => 'supsub', 'rows' => 2, 'cols' => 20));
$neweditor->use_editor('supsub', array('supsub' => $type));
$submitoptions = array('id' => 'submitsupsub', 'type' => 'submit', 'value' => 'submit supsub',
'onClick' => 'emulateSubmit(this.id.substring(6, this.id.length));');
echo html_writer::tag('textarea', '', ['name' => 'supsub', 'id' => 'supsub', 'rows' => 2, 'cols' => 20]);
$neweditor->use_editor('supsub', ['supsub' => $type]);
$submitoptions = ['id' => 'submitsupsub', 'type' => 'submit', 'value' => 'submit supsub',
'onClick' => 'emulateSubmit(this.id.substring(6, this.id.length));'];
echo ' ', html_writer::tag('input', '', $submitoptions);

echo html_writer::tag('h2', 'New supsub rows 4, cols 40');
echo html_writer::label('Input rows 4 cols 40', 'supsub2') . ' ';
echo html_writer::tag('textarea', '', array('name' => 'supsub2', 'id' => 'supsub2', 'rows' => 4, 'cols' => 40));
$neweditor->use_editor('supsub2', array('supsub' => $type));
echo html_writer::tag('textarea', '', ['name' => 'supsub2', 'id' => 'supsub2', 'rows' => 4, 'cols' => 40]);
$neweditor->use_editor('supsub2', ['supsub' => $type]);

$submitoptions['id'] = 'submitsupsub2';
$submitoptions['value'] = 'submit supsub2';
echo ' ', html_writer::tag('input', '', $submitoptions);

echo html_writer::tag('h2', 'ATTO Editor');
echo html_writer::label('ATTO Input', 'attoeditor');
echo html_writer::tag('textarea', '', array('name' => 'attoeditor', 'id' => 'attoeditor', 'rows' => 2, 'cols' => 20));
$attoeditor->use_editor('attoeditor', array('supsub' => $type));
echo html_writer::tag('textarea', '', ['name' => 'attoeditor', 'id' => 'attoeditor', 'rows' => 2, 'cols' => 20]);
$attoeditor->use_editor('attoeditor', ['supsub' => $type]);
$submitoptions['id'] = 'submitattoeditor';
echo html_writer::tag('input', '', $submitoptions);
?>
<script type="text/javascript">
YUI().use("moodle-editor_ousupsub-editor", function(Y) {
window.emulateSubmit = function(id) {
Y.M.editor_ousupsub.getEditor(id).updateFromTextArea();
}
});
</script>
<?php
echo $OUTPUT->footer();

0 comments on commit 4e5aeaa

Please sign in to comment.