function CKEditor5Test::languageOfPartsPluginTestHelper

Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test::languageOfPartsPluginTestHelper()
  2. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test::languageOfPartsPluginTestHelper()

Validate the available languages on the basis of selected language option.

1 call to CKEditor5Test::languageOfPartsPluginTestHelper()
CKEditor5Test::testLanguageOfPartsPlugin in core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php
Test for plugin Language of parts.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php, line 268

Class

CKEditor5Test
Tests for CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function languageOfPartsPluginTestHelper($page, $assert_session, $predefined_languages, $option) {
    $this->assertNotEmpty($assert_session->waitForElement('css', 'a[href^="#edit-editor-settings-plugins-ckeditor5-language"]'));
    // Set correct value.
    $vertical_tab_link = $page->find('xpath', "//ul[contains(@class, 'vertical-tabs__menu')]/li/a[starts-with(@href, '#edit-editor-settings-plugins-ckeditor5-language')]");
    $vertical_tab_link->click();
    $page->selectFieldOption('editor[settings][plugins][ckeditor5_language][language_list]', $option);
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Save configuration');
    // Validate plugin on node add page.
    $this->drupalGet('node/add');
    $this->assertNotEmpty($assert_session->waitForText('Choose language'));
    // Click on the dropdown button.
    $page->find('css', '.ck-text-fragment-language-dropdown button')
        ->click();
    // Get all the languages available in dropdown.
    $current_languages = $page->findAll('css', '.ck-text-fragment-language-dropdown li .ck-button__label');
    // Remove "Remove language" element from current languages.
    array_shift($current_languages);
    // Create array of full language name.
    $languages = [];
    foreach ($current_languages as $item) {
        $languages[] = $item->getText();
    }
    // Return the values from a single column.
    $predefined_languages = array_column($predefined_languages, 0);
    // Sort on full language name.
    asort($predefined_languages);
    $this->assertSame(array_values($predefined_languages), $languages);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.