Commit 868da6c2 authored by catch's avatar catch

Issue #3076609 by oknate, catch, larowlan:...

Issue #3076609 by oknate, catch, larowlan: \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest fails on Sqlite
parent a66fc231
......@@ -9,6 +9,7 @@
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\ckeditor\Traits\CKEditorTestTrait;
/**
* Tests the integration of CKEditor.
......@@ -17,6 +18,8 @@
*/
class CKEditorIntegrationTest extends WebDriverTestBase {
use CKEditorTestTrait;
/**
* The account.
*
......@@ -160,7 +163,8 @@ public function testDrupalImageCaptionDialog() {
// If the caption filter is disabled, its checkbox should be absent.
$this->drupalGet('node/add/page');
$this->click('.cke_button__drupalimage');
$this->waitForEditor();
$this->pressEditorButton('drupalimage');
$this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));
$web_assert->elementNotExists('css', '.ui-dialog input[name="attributes[hasCaption]"]');
......@@ -170,9 +174,10 @@ public function testDrupalImageCaptionDialog() {
]);
$this->filterFormat->save();
// If the caption filter is enabled, its checkbox should be present.
// If the caption filter is enabled, its checkbox should be present.
$this->drupalGet('node/add/page');
$this->click('.cke_button__drupalimage');
$this->waitForEditor();
$this->pressEditorButton('drupalimage');
$this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));
$web_assert->elementExists('css', '.ui-dialog input[name="attributes[hasCaption]"]');
}
......
<?php
namespace Drupal\Tests\ckeditor\Traits;
/**
* Provides methods to test CKEditor.
*
* This trait is meant to be used only by functional JavaScript test classes.
*/
trait CKEditorTestTrait {
/**
* Waits for CKEditor to initialize.
*
* @param string $instance_id
* The CKEditor instance ID.
* @param int $timeout
* (optional) Timeout in milliseconds, defaults to 10000.
*/
protected function waitForEditor($instance_id = 'edit-body-0-value', $timeout = 10000) {
$condition = <<<JS
(function() {
return (
typeof CKEDITOR !== 'undefined'
&& typeof CKEDITOR.instances["$instance_id"] !== 'undefined'
&& CKEDITOR.instances["$instance_id"].instanceReady
);
}());
JS;
$this->getSession()->wait($timeout, $condition);
}
/**
* Assigns a name to the CKEditor iframe.
*
* @see \Behat\Mink\Session::switchToIFrame()
*/
protected function assignNameToCkeditorIframe() {
$javascript = <<<JS
(function(){
document.getElementsByClassName('cke_wysiwyg_frame')[0].id = 'ckeditor';
})()
JS;
$this->getSession()->evaluateScript($javascript);
}
/**
* Clicks a CKEditor button.
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
*/
protected function pressEditorButton($name) {
$this->getEditorButton($name)->click();
}
/**
* Waits for a CKEditor button and returns it when available and visible.
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
*
* @return \Behat\Mink\Element\NodeElement|null
* The page element node if found, NULL if not.
*/
protected function getEditorButton($name) {
$this->getSession()->switchToIFrame();
$button = $this->assertSession()->waitForElementVisible('css', 'a.cke_button__' . $name);
$this->assertNotEmpty($button);
return $button;
}
/**
* Asserts a CKEditor button is disabled.
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
*/
protected function assertEditorButtonDisabled($name) {
$button = $this->getEditorButton($name);
$this->assertTrue($button->hasClass('cke_button_disabled'));
$this->assertSame('true', $button->getAttribute('aria-disabled'));
}
/**
* Asserts a CKEditor button is enabled.
*
* @param string $name
* The name of the button, such as `drupallink`, `source`, etc.
*/
protected function assertEditorButtonEnabled($name) {
$button = $this->getEditorButton($name);
$this->assertFalse($button->hasClass('cke_button_disabled'));
$this->assertSame('false', $button->getAttribute('aria-disabled'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment