MDL-78251 tiny: Reduce use of UI for setting test expectations

This commit is contained in:
Andrew Nicols 2023-08-09 13:46:35 +08:00
parent 24ce17d13e
commit c7b1cf2651
No known key found for this signature in database
GPG key ID: 6D1E3157C8CFBF14
4 changed files with 56 additions and 26 deletions

View file

@ -1,21 +1,15 @@
@editor @editor_tiny @filter @filter_codehighlighter
@filter @filter_codehighlighter
Feature: Render text content using a codehighliter filter
To display code to be well-styled - I need to render text content.
@javascript
Scenario: Update admin profile description with a code content
Given the "codehighlighter" filter is "on"
And I log in as "admin"
And I follow "Profile" in the user menu
When I click on "Edit profile" "link" in the "region-main" "region"
And I click on "//span[@class='tox-mbtn__select-label'][contains(text(), 'Insert')]" "xpath_element"
And I click on "//div[@class='tox-collection__item-label'][contains(text(), 'Code sample...')]" "xpath_element"
And I set the field with xpath "//div[@class='tox-selectfield']/select" to "PHP"
And I set the field with xpath "//textarea" to "<pre class=\"language-php\"><code>$t = date();</code></pre>"
And I click on "//button[@class='tox-button'][contains(text(), 'Save')]" "xpath_element"
And I click on "Update profile" "button"
Then I should see "Changes saved"
And "//span[@class='token variable'][contains(text(),'$t')]" "xpath_element" should exist
And the following "user" exists:
| username | example |
| description | <pre class="language-php"><code>$t = date();</code></language> |
And I am on the Profile page logged in as "example"
Then "//span[@class='token variable'][contains(text(),'$t')]" "xpath_element" should exist
And "//span[@class='token operator'][contains(text(),'=')]" "xpath_element" should exist
And "//span[@class='token punctuation'][contains(text(),'(')]" "xpath_element" should exist
And "//span[@class='token punctuation'][contains(text(),')')]" "xpath_element" should exist

View file

@ -0,0 +1,12 @@
@core @editor_tiny @javascript
Feature: A user can insert script tag in TinyMCE using the default TinyMCE functionalities.
Scenario: Allow script elements in the editor with the additional HTML plugin disabled.
Given the following config values are set as admin:
| config | value | plugin |
| disabled | 1 | tiny_html |
And I am on the "Profile advanced editing" page logged in as "admin"
And I set the field "Description" to "<p><script>alert('script in tiny');</script></p>"
When I click on the "Tools > Source code" menu item for the "Description" TinyMCE editor
And I click on "Save" "button"
Then the field "Description" matches expression "@<script>.*alert\('script in tiny'\);.*</script>@s"

View file

@ -1,14 +0,0 @@
@core @editor_tiny @source_code @javascript
Feature: A user can insert script tag in TinyMCE using the default TinyMCE functionalities.
Scenario: Allow script elements in the editor with the additional HTML plugin disabled.
Given the following config values are set as admin:
| config | value | plugin |
| disabled | 1 | tiny_html |
And I log in as "admin"
And I open my profile in edit mode
When I click on the "Tools > Source code" menu item for the "Description" TinyMCE editor
Then I set the field with xpath "//textarea[@class='tox-textarea']" to "<p><script>alert('script in tiny');</script></p>"
And I click on "Save" "button"
When I click on the "Tools > Source code" menu item for the "Description" TinyMCE editor
Then the field with xpath "//textarea[@class='tox-textarea']" matches value "<p><script>alert('script in tiny');</script></p>"

View file

@ -318,6 +318,44 @@ class behat_forms extends behat_base {
}
}
/**
* Checks, the field contains the value.
*
* @Then /^the field "(?P<field_string>(?:[^"]|\\")*)" (?P<doesnot_bool>does not )?match(?:es)* expression "(?P<expression_string>(?:[^"]|\\")*)"$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param string $field The naem or reference to the field
* @param bool $doesnot
* @param string $expression The Perl-like regular expression, including any delimeters and flag
* @return void
*/
public function the_field_matches_expression(
string $field,
bool $doesnot,
string $expression,
): void {
// Get the field.
$formfield = behat_field_manager::get_form_field_from_label($field, $this);
// Checks if the provided value matches the current field value.
$fieldvalue = $formfield->get_value();
$matches = preg_match($expression, $fieldvalue);
if ($matches === 1 && $doesnot) {
throw new ExpectationException(
"The '{$field}' field matches the expression '{$expression}' and it should not",
$this->getSession()
);
} else if ($matches === 0 && !$doesnot) {
throw new ExpectationException(
"The '{$field}' field does not match the expression '{$expression}'",
$this->getSession()
);
} else if ($matches === false) {
throw new coding_exception(
"The expression '{$expression}' was not valid",
);
}
}
/**
* Checks, the field matches the value.
*