Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / ckeditor / tests / src / FunctionalJavascript / CKEditorIntegrationTest.php
index 80de46d6bc425a146907ef74362d7bd5cd96fc7d..9e7b8df53a6ee2d22d166da6ff8175f62a7e922f 100644 (file)
@@ -7,7 +7,7 @@ use Drupal\editor\Entity\Editor;
 use Drupal\field\Entity\FieldConfig;
 use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\filter\Entity\FilterFormat;
-use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
 use Drupal\node\Entity\NodeType;
 
 /**
@@ -15,7 +15,7 @@ use Drupal\node\Entity\NodeType;
  *
  * @group ckeditor
  */
-class CKEditorIntegrationTest extends JavascriptTestBase {
+class CKEditorIntegrationTest extends WebDriverTestBase {
 
   /**
    * The account.
@@ -24,6 +24,13 @@ class CKEditorIntegrationTest extends JavascriptTestBase {
    */
   protected $account;
 
+  /**
+   * The FilterFormat config entity used for testing.
+   *
+   * @var \Drupal\filter\FilterFormatInterface
+   */
+  protected $filterFormat;
+
   /**
    * {@inheritdoc}
    */
@@ -36,12 +43,12 @@ class CKEditorIntegrationTest extends JavascriptTestBase {
     parent::setUp();
 
     // Create a text format and associate CKEditor.
-    $filtered_html_format = FilterFormat::create([
+    $this->filterFormat = FilterFormat::create([
       'format' => 'filtered_html',
       'name' => 'Filtered HTML',
       'weight' => 0,
     ]);
-    $filtered_html_format->save();
+    $this->filterFormat->save();
 
     Editor::create([
       'format' => 'filtered_html',
@@ -92,9 +99,10 @@ class CKEditorIntegrationTest extends JavascriptTestBase {
     $session->getPage();
 
     // Add a bottom margin to the title field to be sure the body field is not
-    // visible. PhantomJS runs with a resolution of 1024x768px.
-    $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = '800px';");
+    // visible.
+    $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 +'px';");
 
+    $this->assertSession()->waitForElementVisible('css', $ckeditor_id);
     // Check that the CKEditor-enabled body field is currently not visible in
     // the viewport.
     $web_assert->assertNotVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is visible.');
@@ -118,4 +126,55 @@ class CKEditorIntegrationTest extends JavascriptTestBase {
     self::assertEquals($before_url, $after_url, 'History back works.');
   }
 
+  /**
+   * Tests if the Image button appears and works as expected.
+   */
+  public function testDrupalImageDialog() {
+    $session = $this->getSession();
+    $web_assert = $this->assertSession();
+
+    $this->drupalGet('node/add/page');
+    $session->getPage();
+
+    // Asserts the Image button is present in the toolbar.
+    $web_assert->elementExists('css', '#cke_edit-body-0-value .cke_button__drupalimage');
+
+    // Asserts the image dialog opens when clicking the Image button.
+    $this->click('.cke_button__drupalimage');
+    $this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));
+
+    $web_assert->elementContains('css', '.ui-dialog .ui-dialog-titlebar', 'Insert Image');
+  }
+
+  /**
+   * Tests if the Drupal Image Caption plugin appears and works as expected.
+   */
+  public function testDrupalImageCaptionDialog() {
+    $web_assert = $this->assertSession();
+
+    // Disable the caption filter.
+    $this->filterFormat->setFilterConfig('filter_caption', [
+      'status' => FALSE,
+    ]);
+    $this->filterFormat->save();
+
+    // If the caption filter is disabled, its checkbox should be absent.
+    $this->drupalGet('node/add/page');
+    $this->click('.cke_button__drupalimage');
+    $this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));
+    $web_assert->elementNotExists('css', '.ui-dialog input[name="attributes[hasCaption]"]');
+
+    // Enable the caption filter again.
+    $this->filterFormat->setFilterConfig('filter_caption', [
+      'status' => TRUE,
+    ]);
+    $this->filterFormat->save();
+
+    // If the caption filter is enabled,  its checkbox should be present.
+    $this->drupalGet('node/add/page');
+    $this->click('.cke_button__drupalimage');
+    $this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));
+    $web_assert->elementExists('css', '.ui-dialog input[name="attributes[hasCaption]"]');
+  }
+
 }