Issue #2863996 by nlisgo, Jo Fitzgerald, scuba_fly, dawehner: Convert web tests to browser tests for ckeditor module

8.4.x
Alex Pott 2017-04-18 09:09:34 +01:00
parent 479813c7fb
commit 40d1faf887
3 changed files with 29 additions and 25 deletions

View File

@ -1,19 +1,19 @@
<?php <?php
namespace Drupal\ckeditor\Tests; namespace Drupal\Tests\ckeditor\Functional;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\filter\FilterFormatInterface; use Drupal\filter\FilterFormatInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat; use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
/** /**
* Tests administration of CKEditor. * Tests administration of CKEditor.
* *
* @group ckeditor * @group ckeditor
*/ */
class CKEditorAdminTest extends WebTestBase { class CKEditorAdminTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.
@ -62,12 +62,12 @@ class CKEditorAdminTest extends WebTestBase {
$select = $this->xpath('//select[@name="editor[editor]"]'); $select = $this->xpath('//select[@name="editor[editor]"]');
$select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]'); $select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor[editor]"]/option'); $options = $this->xpath('//select[@name="editor[editor]"]/option');
$this->assertTrue(count($select) === 1, 'The Text Editor select exists.'); $this->assertCount(1, $select, 'The Text Editor select exists.');
$this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.'); $this->assertCount(0, $select_is_disabled, 'The Text Editor select is not disabled.');
$this->assertTrue(count($options) === 2, 'The Text Editor select has two options.'); $this->assertCount(2, $options, 'The Text Editor select has two options.');
$this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the Text Editor select is "None".'); $this->assertSame('None', $options[0]->getText(), 'Option 1 in the Text Editor select is "None".');
$this->assertTrue(((string) $options[1]) === 'CKEditor', 'Option 2 in the Text Editor select is "CKEditor".'); $this->assertSame('CKEditor', $options[1]->getText(), 'Option 2 in the Text Editor select is "CKEditor".');
$this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.'); $this->assertSame('selected', $options[0]->getAttribute('selected'), 'Option 1 ("None") is selected.');
// Select the "CKEditor" editor and click the "Save configuration" button. // Select the "CKEditor" editor and click the "Save configuration" button.
$edit = [ $edit = [
@ -110,7 +110,7 @@ class CKEditorAdminTest extends WebTestBase {
$this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings); $this->assertIdentical($this->castSafeStrings($ckeditor->getDefaultSettings()), $expected_default_settings);
// Keep the "CKEditor" editor selected and click the "Configure" button. // Keep the "CKEditor" editor selected and click the "Configure" button.
$this->drupalPostAjaxForm(NULL, $edit, 'editor_configure'); $this->drupalPostForm(NULL, $edit, 'editor_configure');
$editor = Editor::load('filtered_html'); $editor = Editor::load('filtered_html');
$this->assertFalse($editor, 'No Editor config entity exists yet.'); $this->assertFalse($editor, 'No Editor config entity exists yet.');
@ -120,8 +120,10 @@ class CKEditorAdminTest extends WebTestBase {
'#editor' => Editor::create(['editor' => 'ckeditor']), '#editor' => Editor::create(['editor' => 'ckeditor']),
'#plugins' => $this->container->get('plugin.manager.ckeditor.plugin')->getButtons(), '#plugins' => $this->container->get('plugin.manager.ckeditor.plugin')->getButtons(),
]; ];
$settings = $this->getDrupalSettings();
$expected = $settings['ckeditor']['toolbarAdmin'];
$this->assertEqual( $this->assertEqual(
$this->drupalSettings['ckeditor']['toolbarAdmin'], $expected,
$this->container->get('renderer')->renderPlain($ckeditor_settings_toolbar), $this->container->get('renderer')->renderPlain($ckeditor_settings_toolbar),
'CKEditor toolbar settings are rendered as part of drupalSettings.' 'CKEditor toolbar settings are rendered as part of drupalSettings.'
); );
@ -230,12 +232,12 @@ class CKEditorAdminTest extends WebTestBase {
$select = $this->xpath('//select[@name="editor[editor]"]'); $select = $this->xpath('//select[@name="editor[editor]"]');
$select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]'); $select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]');
$options = $this->xpath('//select[@name="editor[editor]"]/option'); $options = $this->xpath('//select[@name="editor[editor]"]/option');
$this->assertTrue(count($select) === 1, 'The Text Editor select exists.'); $this->assertCount(1, $select, 'The Text Editor select exists.');
$this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.'); $this->assertCount(0, $select_is_disabled, 'The Text Editor select is not disabled.');
$this->assertTrue(count($options) === 2, 'The Text Editor select has two options.'); $this->assertCount(2, $options, 'The Text Editor select has two options.');
$this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the Text Editor select is "None".'); $this->assertSame('None', $options[0]->getText(), 'Option 1 in the Text Editor select is "None".');
$this->assertTrue(((string) $options[1]) === 'CKEditor', 'Option 2 in the Text Editor select is "CKEditor".'); $this->assertSame('CKEditor', $options[1]->getText(), 'Option 2 in the Text Editor select is "CKEditor".');
$this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.'); $this->assertSame('selected', $options[0]->getAttribute('selected'), 'Option 1 ("None") is selected.');
// Name our fancy new text format, select the "CKEditor" editor and click // Name our fancy new text format, select the "CKEditor" editor and click
// the "Configure" button. // the "Configure" button.
@ -244,7 +246,7 @@ class CKEditorAdminTest extends WebTestBase {
'format' => 'amazing_format', 'format' => 'amazing_format',
'editor[editor]' => 'ckeditor', 'editor[editor]' => 'ckeditor',
]; ];
$this->drupalPostAjaxForm(NULL, $edit, 'editor_configure'); $this->drupalPostForm(NULL, $edit, 'editor_configure');
$filter_format = FilterFormat::load('amazing_format'); $filter_format = FilterFormat::load('amazing_format');
$this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.'); $this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.');
$editor = Editor::load('amazing_format'); $editor = Editor::load('amazing_format');
@ -258,7 +260,9 @@ class CKEditorAdminTest extends WebTestBase {
$this->assertFieldByName('editor[settings][toolbar][button_groups]', $expected_buttons_value); $this->assertFieldByName('editor[settings][toolbar][button_groups]', $expected_buttons_value);
// Regression test for https://www.drupal.org/node/2606460. // Regression test for https://www.drupal.org/node/2606460.
$this->assertTrue(strpos($this->drupalSettings['ckeditor']['toolbarAdmin'], '<li data-drupal-ckeditor-button-name="Bold" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="bold" aria-label="bold"><span class="cke_button_icon cke_button__bold_icon">bold</span></a></li>') !== FALSE); $settings = $this->getDrupalSettings();
$expected = $settings['ckeditor']['toolbarAdmin'];
$this->assertTrue(strpos($expected, '<li data-drupal-ckeditor-button-name="Bold" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="bold" aria-label="bold"><span class="cke_button_icon cke_button__bold_icon">bold</span></a></li>') !== FALSE);
// Ensure the styles textarea exists and is initialized empty. // Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]');

View File

@ -1,17 +1,17 @@
<?php <?php
namespace Drupal\ckeditor\Tests; namespace Drupal\Tests\ckeditor\Functional;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat; use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
/** /**
* Tests loading of CKEditor. * Tests loading of CKEditor.
* *
* @group ckeditor * @group ckeditor
*/ */
class CKEditorLoadingTest extends WebTestBase { class CKEditorLoadingTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.

View File

@ -1,17 +1,17 @@
<?php <?php
namespace Drupal\ckeditor\Tests; namespace Drupal\Tests\ckeditor\Functional;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\simpletest\WebTestBase;
use Drupal\filter\Entity\FilterFormat; use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
/** /**
* Tests administration of the CKEditor StylesCombo plugin. * Tests administration of the CKEditor StylesCombo plugin.
* *
* @group ckeditor * @group ckeditor
*/ */
class CKEditorStylesComboAdminTest extends WebTestBase { class CKEditorStylesComboAdminTest extends BrowserTestBase {
/** /**
* Modules to enable. * Modules to enable.