You are here

public function DrupalNbspTest::testButton in CKEditor Non-breaking space Plugin ( ) 8.2

Same name and namespace in other branches
  1. 8 tests/src/FunctionalJavascript/DrupalNbspTest.php \Drupal\Tests\nbsp\FunctionalJavascript\DrupalNbspTest::testButton()

Tests using DurpalNbsp button to add non-breaking space into CKEditor.

File

tests/src/FunctionalJavascript/DrupalNbspTest.php, line 202

Class

DrupalNbspTest
Ensure the NBSP CKeditor dialog works.

Namespace

Drupal\Tests\nbsp\FunctionalJavascript

Code

public function testButton() {
  $this
    ->drupalGet('node/add/page');
  $this
    ->waitForEditor();
  $this
    ->pressEditorButton('drupalnbsp');
  $this
    ->pressEditorButton('source');
  $assert_session = $this
    ->assertSession();
  $value = $assert_session
    ->elementExists('css', 'textarea.cke_source')
    ->getValue();
  $dom = Html::load($value);
  $xpath = new \DOMXPath($dom);
  $nbsp = $xpath
    ->query('//span')[0];
  $expected_attributes = [
    'class' => 'nbsp',
  ];
  foreach ($expected_attributes as $name => $expected) {
    $this
      ->assertSame($expected, $nbsp
      ->getAttribute($name));
  }
  $this
    ->assertEquals(" ", $nbsp->firstChild->nodeValue);
}