MDL-45227 editor_atto: PR changes and improved behat

This commit is contained in:
Shamim Rezaie 2020-02-04 02:37:53 +11:00
parent dbae95c6da
commit 372616ace0
6 changed files with 139 additions and 94 deletions

View File

@ -1,20 +1,16 @@
@editor @editor_atto @atto @mod @mod_forum @javascript
Feature: Add text direction
To support bidi text sent by email
@editor @editor_atto @atto
Feature: Add text direction and alignment
In order to generate a content that can be displayed in the proper direction to everyone
As a user
I should see the Atto editor with explicit direction and alignment being set
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode | summary | summaryformat |
| Course 1 | C1 | 0 | 1 | | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
Given the following "user preferences" exist:
| user | preference | value |
| admin | htmleditor | atto |
And I log in as "admin"
And I navigate to "Plugins > Atto HTML editor" in site administration
And I set the field "id_s_editor_atto_toolbar" to multiline:
And I navigate to "Plugins > Text editors > Atto HTML editor > Atto toolbar settings" in site administration
And I set the field "Toolbar config" to multiline:
"""
collapse = collapse
style1 = title, bold, italic
@ -30,45 +26,24 @@ Feature: Add text direction
other = html
"""
And I press "Save changes"
And I navigate to "Plugins > Manage editors" in site administration
And I click on "Disable" "link" in the "Plain text area" "table_row"
And I click on "Disable" "link" in the "TinyMCE HTML editor" "table_row"
And I log out
@javascript
Scenario: Check default direction exist in atto
Given I log in as "teacher1"
Scenario Outline: Atto should apply user's direction and alignment by default
Given the following "courses" exist:
| fullname | shortname | summary | summaryformat |
| Course 1 | C1 | | 1 |
And the following "language customisations" exist:
| component | stringid | value |
| <component> | <stringid> | <localstring> |
And I log in as "admin"
And I am on "Course 1" course homepage
And I navigate to "Edit settings" in current page administration
And I wait until the page is ready
When I navigate to "Edit settings" in current page administration
And I press "Show more buttons"
And I press "HTML"
Then I should see "dir=\"ltr\" style=\"text-align: left;\"" in the "//span[@role='presentation']" "xpath_element"
Then I should see "<partialtext>"
@javascript
Scenario: Test RTL support in atto
Given I log in as "admin"
And I navigate to "Language > Language packs" in site administration
And I set the field "Available language packs" to "he"
And I press "Install selected language pack(s)"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Edit settings" in current page administration
And I set the field "Course summary" to "<p dir=\"ltr\" style=\"text-align: left;\">My ltr text</p>"
And I click on "Save and display" "button"
And I follow "Preferences" in the user menu
And I follow "Preferred language"
And I set the field "Preferred language" to "he"
And I press "Save changes"
And I wait until the page is ready
And I am on "Course 1" course homepage
And I navigate to "הגדרות" in current page administration
And I wait until the page is ready
And I set the field "תקציר הקורס" to ""
And I click on "שמירת השינויים והצגתם" "button"
And I navigate to "הגדרות" in current page administration
And I wait until the page is ready
And I press "הצגת כפתורים נוספים"
And I press "HTML"
Then I should see "dir=\"rtl\" style=\"text-align: right;\"" in the "//span[@role='presentation']" "xpath_element"
Examples:
| component | stringid | localstring | partialtext |
| core_langconfig | thisdirection | ltr | dir=\"ltr\" style=\"text-align: left;\" |
| core_langconfig | thisdirection | rtl | dir=\"rtl\" style=\"text-align: right;\" |

View File

@ -906,14 +906,24 @@ EditorAutosave.prototype = {
}
// Revert untouched editor contents to an empty string.
// Check for FF and Chrome.
if (response.result === '<p></p>' || response.result === '<p><br></p>' ||
response.result === '<br>') {
response.result = '';
}
// Check for IE 9 and 10.
if (response.result === '<p>&nbsp;</p>' || response.result === '<p><br>&nbsp;</p>') {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(response.result)) {
response.result = '';
}
@ -1341,16 +1351,29 @@ EditorClean.prototype = {
html = editorClone.get('innerHTML');
// Revert untouched editor contents to an empty string.
if ((html === '<p></p>' || html === '<p><br></p>') ||
(html === '<p dir="rtl" style="text-align: right;"></p>' ||
html === '<p dir="rtl" style="text-align: right;"><br></p>') ||
(html === '<p dir="ltr" style="text-align: left;"></p>' ||
html === '<p dir="ltr" style="text-align: left;"><br></p>')) {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(html)) {
return '';
}
// Remove any and all nasties from source.
return this._cleanHTML(html);
return this._cleanHTML(html);
},
/**

File diff suppressed because one or more lines are too long

View File

@ -900,14 +900,24 @@ EditorAutosave.prototype = {
}
// Revert untouched editor contents to an empty string.
// Check for FF and Chrome.
if (response.result === '<p></p>' || response.result === '<p><br></p>' ||
response.result === '<br>') {
response.result = '';
}
// Check for IE 9 and 10.
if (response.result === '<p>&nbsp;</p>' || response.result === '<p><br>&nbsp;</p>') {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(response.result)) {
response.result = '';
}
@ -1330,16 +1340,29 @@ EditorClean.prototype = {
html = editorClone.get('innerHTML');
// Revert untouched editor contents to an empty string.
if ((html === '<p></p>' || html === '<p><br></p>') ||
(html === '<p dir="rtl" style="text-align: right;"></p>' ||
html === '<p dir="rtl" style="text-align: right;"><br></p>') ||
(html === '<p dir="ltr" style="text-align: left;"></p>' ||
html === '<p dir="ltr" style="text-align: left;"><br></p>')) {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(html)) {
return '';
}
// Remove any and all nasties from source.
return this._cleanHTML(html);
return this._cleanHTML(html);
},
/**

View File

@ -143,14 +143,24 @@ EditorAutosave.prototype = {
}
// Revert untouched editor contents to an empty string.
// Check for FF and Chrome.
if (response.result === '<p></p>' || response.result === '<p><br></p>' ||
response.result === '<br>') {
response.result = '';
}
// Check for IE 9 and 10.
if (response.result === '<p>&nbsp;</p>' || response.result === '<p><br>&nbsp;</p>') {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(response.result)) {
response.result = '';
}

View File

@ -55,16 +55,29 @@ EditorClean.prototype = {
html = editorClone.get('innerHTML');
// Revert untouched editor contents to an empty string.
if ((html === '<p></p>' || html === '<p><br></p>') ||
(html === '<p dir="rtl" style="text-align: right;"></p>' ||
html === '<p dir="rtl" style="text-align: right;"><br></p>') ||
(html === '<p dir="ltr" style="text-align: left;"></p>' ||
html === '<p dir="ltr" style="text-align: left;"><br></p>')) {
var emptyContents = [
// For FF and Chrome.
'<p></p>',
'<p><br></p>',
'<br>',
'<p dir="rtl" style="text-align: right;"></p>',
'<p dir="rtl" style="text-align: right;"><br></p>',
'<p dir="ltr" style="text-align: left;"></p>',
'<p dir="ltr" style="text-align: left;"><br></p>',
// For IE 9 and 10.
'<p>&nbsp;</p>',
'<p><br>&nbsp;</p>',
'<p dir="rtl" style="text-align: right;">&nbsp;</p>',
'<p dir="rtl" style="text-align: right;"><br>&nbsp;</p>',
'<p dir="ltr" style="text-align: left;">&nbsp;</p>',
'<p dir="ltr" style="text-align: left;"><br>&nbsp;</p>'
];
if (emptyContents.includes(html)) {
return '';
}
// Remove any and all nasties from source.
return this._cleanHTML(html);
return this._cleanHTML(html);
},
/**