Commit 829a07aa authored by Christopher C. Wells's avatar Christopher C. Wells
Browse files

Issue #3243437 by wells: Update existing tests for Drupal 10

parent 9aa3c36e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
 */

/**
 * Gets the path of a CKEditor CodeMirror library.
 * Gets the path of the CodeMirror library.
 *
 * @return bool|string
 *   The path to the specified library or FALSE if the library wasn't found.
+1 −1
Original line number Diff line number Diff line
{
    "name": "drupal/ckeditor_codemirror",
    "description": "CKEditor CodeMirror source syntax highlighter plugin.",
    "description": "CodeMirror source syntax highlighting for CKEditor 5.",
    "type": "drupal-module",
    "keywords": [
        "Drupal"
+15 −24
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ class CkeditorCodeMirrorBasicTest extends BrowserTestBase {
  public function setUp(): void {
    parent::setUp();

    // Create text format, associate CKEditor.
    // Create text format, associate CKEditor 5.
    $full_html_format = FilterFormat::create([
      'format' => 'full_html',
      'name' => 'Full HTML',
@@ -58,15 +58,12 @@ public function setUp(): void {
    $full_html_format->save();
    $editor = Editor::create([
      'format' => 'full_html',
      'editor' => 'ckeditor',
      'editor' => 'ckeditor5',
    ]);
    $editor->save();

    // Create node type.
    $this->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

    $this->privilegedUser = $this->drupalCreateUser([
      'administer site configuration',
@@ -82,7 +79,7 @@ public function setUp(): void {
   * Check the library status on "Status report" page.
   */
  public function testCheckStatusReportPage() {
    \Drupal::moduleHandler()->loadInclude('install', 'ckeditor_codemirror');
    $this->container->get('module_handler')->loadInclude('install', 'ckeditor_codemirror');

    $this->drupalLogin($this->privilegedUser);
    $this->drupalGet('admin/reports/status');
@@ -98,9 +95,7 @@ public function testCheckStatusReportPage() {
      );
    }
    else {
      $this->assertSession()->pageTextContains(
        $this->t('CodeMirror was not found.')
      );
      $this->assertSession()->pageTextContains($this->t('CodeMirror was not found.'));
    }
  }

@@ -110,29 +105,25 @@ public function testCheckStatusReportPage() {
  public function testEnableCkeditorCodeMirrorPlugin() {
    $this->drupalLogin($this->privilegedUser);
    $this->drupalGet('admin/config/content/formats/manage/full_html');
    $this->assertSession()->pageTextContains(
      $this->t('Enable CodeMirror source view syntax highlighting.')
    );
    $this->assertSession()->checkboxNotChecked(
      'edit-editor-settings-plugins-codemirror-enable'
    );
    $this->assertSession()->pageTextContains($this->t('Enable CodeMirror source view syntax highlighting.'));
    $this->assertSession()->checkboxNotChecked('edit-editor-settings-plugins-ckeditor-codemirror-source-editing-enable');

    // Enable the plugin.
    $edit = [
      'editor[settings][plugins][codemirror][enable]' => '1',
    ];
    $this->drupalPostForm(NULL, $edit, $this->t('Save configuration'));
    $this->assertSession()->pageTextContains(
      $this->t('The text format Full HTML has been updated.')
    );
    $edit = ['editor[settings][plugins][ckeditor_codemirror_source_editing][enable]' => '1',];
    $this->submitForm($edit, $this->t('Save configuration'));
    $this->assertSession()->pageTextContains($this->t('The text format Full HTML has been updated.'));

    // Check for the plugin on node add page.
    $this->drupalGet('node/add/article');
    $editor_settings = $this->getDrupalSettings()['editor']['formats']['full_html']['editorSettings'];

    // Ensure the plugin is loaded.
    $this->assertContains('sourceEditingCodemirror.SourceEditingCodeMirror', $editor_settings['plugins']);

    // Ensure the plugin is enabled.
    $library_path = _ckeditor_codemirror_get_library_path();
    if (file_exists("$library_path/package.json")) {
      $ckeditor_enabled = $editor_settings['codemirror']['enable'];
      $ckeditor_enabled = $editor_settings['config']['sourceEditingCodemirror.SourceEditingCodeMirror']['enable'];
      $this->assertTrue($ckeditor_enabled);
    }
  }