You are here

public function FilterTest::testFilter in The CodeMirror Editor 8

Test callback.

File

tests/src/FunctionalJavascript/FilterTest.php, line 43

Class

FilterTest
Tests the CodeMirror editor filter.

Namespace

Drupal\Tests\codemirror_editor\FunctionalJavascript

Code

public function testFilter() {
  $permissions = [
    'edit any test content',
    'administer filters',
    'use text format codemirror',
  ];
  $user = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('node/1');
  $this->activeEditor = 1;
  $this
    ->assertEditorOption('mode', 'text/html');
  $this
    ->assertEditorOption('lineNumbers', TRUE);
  $this
    ->assertEditorOption('foldGutter', FALSE);
  $this->activeEditor = 2;
  $this
    ->assertEditorOption('mode', 'text/x-php');
  $this
    ->assertEditorOption('lineNumbers', TRUE);
  $this
    ->assertEditorOption('foldGutter', FALSE);
  $this->activeEditor = 3;
  $this
    ->assertEditorOption('mode', 'text/css');
  $this
    ->assertEditorOption('lineNumbers', TRUE);
  $this
    ->assertEditorOption('foldGutter', FALSE);
  $this
    ->drupalGet('admin/config/content/formats/manage/codemirror');
  $assert_session = $this
    ->assertSession();
  $xpath = '//input[@name = "filters[codemirror_editor][settings][lineNumbers]" and @checked = "checked"]';
  $assert_session
    ->elementExists('xpath', $xpath);
  $xpath = '//input[@name = "filters[codemirror_editor][settings][foldGutter]" and not(@checked)]';
  $assert_session
    ->elementExists('xpath', $xpath);
  $this
    ->scrollToBottom();
  $edit = [
    'filters[codemirror_editor][settings][lineNumbers]' => FALSE,
    'filters[codemirror_editor][settings][foldGutter]' => TRUE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save configuration');
  $this
    ->drupalGet('node/1');
  $this->activeEditor = 1;
  $this
    ->assertEditorOption('mode', 'text/html');
  $this
    ->assertEditorOption('lineNumbers', FALSE);
  $this
    ->assertEditorOption('foldGutter', TRUE);
}