View source
<?php
namespace Drupal\Tests\codemirror_editor\Kernel;
use Drupal\KernelTests\KernelTestBase;
final class ModeManagerTest extends KernelTestBase {
public static $modules = [
'codemirror_editor',
'codemirror_editor_test',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'codemirror_editor',
]);
}
public function testGetDefinitions() {
$manager = \Drupal::service('plugin.manager.codemirror_mode');
$definitions = $manager
->getDefinitions();
self::assertCount(12, $definitions);
$expected_modes = [
'clike',
'css',
'htmlmixed',
'javascript',
'markdown',
'php',
'python',
'ruby',
'sql',
'twig',
'xml',
'yaml',
];
self::assertEquals($expected_modes, array_keys($definitions));
self::assertEquals([
'codemirror_editor_test',
], $definitions['php']['usage']);
}
public function testGetActiveModes() {
$manager = \Drupal::service('plugin.manager.codemirror_mode');
$expected_modes = [
'php',
'clike',
'xml',
];
self::assertEquals($expected_modes, $manager
->getActiveModes());
}
public function testNormalizeMode($input, $expected_output) {
$manager = \Drupal::service('plugin.manager.codemirror_mode');
$output = $manager
->normalizeMode($input);
self::assertEquals($expected_output, $output);
}
public function getData() {
return [
[
'text/x-sql',
'text/x-sql',
],
[
'PHP',
'text/x-php',
],
[
'html',
'text/html',
],
[
'missing/mode',
'missing/mode',
],
];
}
}