CkeditorCodeMirrorBasicTest.php in CKEditor CodeMirror 8.2
File
tests/src/Functional/CkeditorCodeMirrorBasicTest.php
View source
<?php
namespace Drupal\Tests\ckeditor_codemirror\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
class CkeditorCodeMirrorBasicTest extends BrowserTestBase {
use StringTranslationTrait;
public static $modules = [
'filter',
'node',
'editor',
'ckeditor',
'ckeditor_codemirror',
];
protected $profile = 'minimal';
protected $privilegedUser;
public function setUp() {
parent::setUp();
$full_html_format = FilterFormat::create([
'format' => 'full_html',
'name' => 'Full HTML',
'weight' => 0,
'filters' => [],
]);
$full_html_format
->save();
$editor = Editor::create([
'format' => 'full_html',
'editor' => 'ckeditor',
]);
$editor
->save();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->privilegedUser = $this
->drupalCreateUser([
'administer site configuration',
'administer filters',
'create article content',
'edit any article content',
'use text format full_html',
]);
$this
->drupalLogin($this->privilegedUser);
}
public function testCheckStatusReportPage() {
module_load_include('install', 'ckeditor_codemirror');
$this
->drupalLogin($this->privilegedUser);
$this
->drupalGet('admin/reports/status');
$library_path = _ckeditor_codemirror_get_library_path();
if (file_exists(DRUPAL_ROOT . '/' . $library_path . '/codemirror/plugin.js')) {
$this
->assertSession()
->responseContains($this
->t('CKEditor CodeMirror plugin version %version installed at %path.', [
'%path' => base_path() . $library_path,
'%version' => _ckeditor_codemirror_get_version(),
]));
}
else {
$this
->assertSession()
->pageTextContains($this
->t('CKEditor CodeMirror plugin was not found.'));
}
}
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');
$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.'));
$this
->drupalGet('node/add/article');
$editor_settings = $this
->getDrupalSettings()['editor']['formats']['full_html']['editorSettings'];
$library_path = _ckeditor_codemirror_get_library_path();
if (file_exists(DRUPAL_ROOT . '/' . $library_path . '/codemirror/plugin.js')) {
$ckeditor_enabled = $editor_settings['codemirror']['enable'];
$this
->assertTrue($ckeditor_enabled);
}
}
}