You are here

public function LibraryBuilderTest::testLibraryBuild in The CodeMirror Editor 8

Test callback.

File

tests/src/Kernel/LibraryBuilderTest.php, line 112

Class

LibraryBuilderTest
A test for codemirror_editor_library_info_build().

Namespace

Drupal\Tests\codemirror_editor\Kernel

Code

public function testLibraryBuild() {
  $config = \Drupal::configFactory()
    ->getEditable('codemirror_editor.settings');

  // Remote minified.
  $expected_build = [
    'codemirror' => self::minify($this->remoteFixture),
  ];
  self::assertEquals($expected_build, codemirror_editor_library_info_build());

  // Remote non-minified.
  $settings = [
    'cdn' => TRUE,
    'minified' => FALSE,
    'theme' => 'default',
    'language_modes' => [
      'xml',
    ],
  ];
  $config
    ->setData($settings)
    ->save();
  $expected_build = [
    'codemirror' => $this->remoteFixture,
  ];
  self::assertEquals($expected_build, codemirror_editor_library_info_build());

  // Local non-minified.
  $settings = [
    'cdn' => FALSE,
    'minified' => FALSE,
    'theme' => 'default',
    'language_modes' => [
      'xml',
    ],
  ];
  $config
    ->setData($settings)
    ->save();
  $expected_build = [
    'codemirror' => $this->localFixture,
  ];
  self::assertEquals($expected_build, codemirror_editor_library_info_build());

  // Local minified.
  $settings = [
    'cdn' => FALSE,
    'minified' => TRUE,
    'theme' => 'default',
    'language_modes' => [
      'xml',
    ],
  ];
  $config
    ->setData($settings)
    ->save();
  $expected_build = [
    'codemirror' => self::minify($this->localFixture),
  ];
  self::assertEquals($expected_build, codemirror_editor_library_info_build());

  // Local non-minified with Yaml mode and Cobalt theme.
  $settings = [
    'cdn' => FALSE,
    'minified' => FALSE,
    'theme' => 'cobalt',
    'language_modes' => [
      'xml',
      'yaml',
    ],
  ];
  $config
    ->setData($settings)
    ->save();
  $expected_build = [
    'codemirror' => $this->localFixture,
  ];
  $expected_build['codemirror']['js']['/libraries/codemirror/mode/yaml/yaml.js'] = [];
  $expected_build['codemirror']['css']['theme']['/libraries/codemirror/theme/cobalt.css'] = [];
  self::assertEquals($expected_build, codemirror_editor_library_info_build());
}