Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
1bce7388
Unverified
Commit
1bce7388
authored
Jan 14, 2020
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3073261
by oknate, phenaproxima, Wim Leers: Improve CKEditorTestTrait
(cherry picked from commit
b28a392e
)
parent
3416efa6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
+27
-15
27 additions, 15 deletions
core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
with
27 additions
and
15 deletions
core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
+
27
−
15
View file @
1bce7388
...
...
@@ -13,7 +13,7 @@ trait CKEditorTestTrait {
* Waits for CKEditor to initialize.
*
* @param string $instance_id
* The CKEditor instance ID.
*
(optional)
The CKEditor instance ID.
Defaults to 'edit-body-0-value'.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
...
...
@@ -22,24 +22,28 @@ protected function waitForEditor($instance_id = 'edit-body-0-value', $timeout =
(function() {
return (
typeof CKEDITOR !== 'undefined'
&& typeof CKEDITOR.instances["$instance_id"] !== 'undefined'
&& CKEDITOR.instances["$instance_id"].instanceReady
&& typeof CKEDITOR.instances["
{
$instance_id
}
"] !== 'undefined'
&& CKEDITOR.instances["
{
$instance_id
}
"].instanceReady
);
}());
JS;
$this
->
getSession
()
->
wait
(
$timeout
,
$condition
);
$this
->
assertJsCondition
(
$condition
,
$timeout
);
}
/**
* Assigns a name to the CKEditor iframe.
*
* @param string $id
* (optional) The id to assign the iframe element. Defaults to 'ckeditor'.
* @param string $instance_id
* (optional) The CKEditor instance ID. Defaults to 'edit-body-0-value'.
*
* @see \Behat\Mink\Session::switchToIFrame()
*/
protected
function
assignNameToCkeditorIframe
()
{
protected
function
assignNameToCkeditorIframe
(
$id
=
'ckeditor'
,
$instance_id
=
'edit-body-0-value'
)
{
$javascript
=
<<<JS
(function(){
document.getElementsByClassName
('cke_wysiwyg_frame')[0].id = '
ckeditor
';
CKEDITOR.instances['{$instance_id}'].element.getParent().find
('
.
cke_wysiwyg_frame')
.$
[0].id = '
{$id}
';
})()
JS;
$this
->
getSession
()
->
evaluateScript
(
$javascript
);
...
...
@@ -50,9 +54,11 @@ protected function assignNameToCkeditorIframe() {
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
* @param string $instance_id
* (optional) The CKEditor instance ID. Defaults to 'edit-body-0-value'.
*/
protected
function
pressEditorButton
(
$name
)
{
$this
->
getEditorButton
(
$name
)
->
click
();
protected
function
pressEditorButton
(
$name
,
$instance_id
=
'edit-body-0-value'
)
{
$this
->
getEditorButton
(
$name
,
$instance_id
)
->
click
();
}
/**
...
...
@@ -60,13 +66,15 @@ protected function pressEditorButton($name) {
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
* @param string $instance_id
* (optional) The CKEditor instance ID. Defaults to 'edit-body-0-value'.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
protected
function
getEditorButton
(
$name
)
{
protected
function
getEditorButton
(
$name
,
$instance_id
=
'edit-body-0-value'
)
{
$this
->
getSession
()
->
switchToIFrame
();
$button
=
$this
->
assertSession
()
->
waitForElementVisible
(
'css'
,
'
a.cke_button__
'
.
$name
);
$button
=
$this
->
assertSession
()
->
waitForElementVisible
(
'css'
,
"#cke_
$instance_id
a.cke_button__
"
.
$name
);
$this
->
assertNotEmpty
(
$button
);
return
$button
;
...
...
@@ -77,9 +85,11 @@ protected function getEditorButton($name) {
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
* @param string $instance_id
* (optional) The CKEditor instance ID. Defaults to 'edit-body-0-value'.
*/
protected
function
assertEditorButtonDisabled
(
$name
)
{
$button
=
$this
->
getEditorButton
(
$name
);
protected
function
assertEditorButtonDisabled
(
$name
,
$instance_id
=
'edit-body-0-value'
)
{
$button
=
$this
->
getEditorButton
(
$name
,
$instance_id
);
$this
->
assertTrue
(
$button
->
hasClass
(
'cke_button_disabled'
));
$this
->
assertSame
(
'true'
,
$button
->
getAttribute
(
'aria-disabled'
));
}
...
...
@@ -89,9 +99,11 @@ protected function assertEditorButtonDisabled($name) {
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
* @param string $instance_id
* (optional) The CKEditor instance ID. Defaults to 'edit-body-0-value'.
*/
protected
function
assertEditorButtonEnabled
(
$name
)
{
$button
=
$this
->
getEditorButton
(
$name
);
protected
function
assertEditorButtonEnabled
(
$name
,
$instance_id
=
'edit-body-0-value'
)
{
$button
=
$this
->
getEditorButton
(
$name
,
$instance_id
);
$this
->
assertFalse
(
$button
->
hasClass
(
'cke_button_disabled'
));
$this
->
assertSame
(
'false'
,
$button
->
getAttribute
(
'aria-disabled'
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment