From 956497377e82b861e4a405051b8b779dde313575 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 28 Mar 2017 14:19:58 +0100 Subject: [PATCH] Issue #2843693 by droplet, michielnugter, xjm, Mixologic, klausi: Random test failure in CKEditor AjaxCss --- .../src/FunctionalJavascript/AjaxCssTest.php | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php b/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php index afe033c7cf1..f011554391d 100644 --- a/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/AjaxCssTest.php @@ -41,31 +41,41 @@ class AjaxCssTest extends JavascriptTestBase { * Tests adding style sheets dynamically to CKEditor. */ public function testCkeditorAjaxAddCss() { - // Skip test until #2843693 is fixed. - $this->markTestSkipped(); - $this->drupalGet('/ckeditor_test/ajax_css'); $session = $this->getSession(); - $assert = $this->assertSession(); + $page = $session->getPage(); + + $this->waitOnCkeditorInstance('edit-iframe-value'); + $this->waitOnCkeditorInstance('edit-inline'); $style_color = 'rgb(255, 0, 0)'; // Add the inline CSS and assert that the style is applied to the main body, // but not the iframe. - $session->getPage()->pressButton('Add CSS to inline CKEditor instance'); - $assert->assertWaitOnAjaxRequest(); - $this->assertEquals($style_color, $this->getEditorStyle('edit-inline', 'color')); - $this->assertNotEquals($style_color, $this->getEditorStyle('edit-iframe-value', 'color')); + $page->pressButton('Add CSS to inline CKEditor instance'); + + $result = $page->waitFor(10, function() use ($style_color) { + return ($this->getEditorStyle('edit-inline', 'color') == $style_color) + && ($this->getEditorStyle('edit-iframe-value', 'color') != $style_color); + }); + $this->assertTrue($result); $session->reload(); + $this->waitOnCkeditorInstance('edit-iframe-value'); + $this->waitOnCkeditorInstance('edit-inline'); + // Add the iframe CSS and assert that the style is applied to the iframe, // but not the main body. - $session->getPage()->pressButton('Add CSS to iframe CKEditor instance'); - $assert->assertWaitOnAjaxRequest(); - $this->assertNotEquals($style_color, $this->getEditorStyle('edit-inline', 'color')); - $this->assertEquals($style_color, $this->getEditorStyle('edit-iframe-value', 'color')); + $page->pressButton('Add CSS to iframe CKEditor instance'); + + $result = $page->waitFor(10, function() use ($style_color) { + return ($this->getEditorStyle('edit-inline', 'color') != $style_color) + && ($this->getEditorStyle('edit-iframe-value', 'color') == $style_color); + }); + + $this->assertTrue($result); } /** @@ -88,4 +98,26 @@ class AjaxCssTest extends JavascriptTestBase { return $this->getSession()->evaluateScript($js); } + /** + * Wait for a CKEditor instance to finish loading and initializing. + * + * @param string $instance_id + * The CKEditor instance ID. + * @param int $timeout + * (optional) Timeout in milliseconds, defaults to 10000. + */ + protected function waitOnCkeditorInstance($instance_id, $timeout = 10000) { + $condition = <<getSession()->wait($timeout, $condition); + } + }