You are here

public function AssetManagerTest::testGetCKEditorVersion in CKEditor Media Embed Plugin 8

File

tests/src/Unit/AssetManagerTest.php, line 89

Class

AssetManagerTest
Tests the asset manager.

Namespace

Drupal\Tests\ckeditor_media_embed\Unit

Code

public function testGetCKEditorVersion() {
  $library_discovery = $this
    ->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')
    ->disableOriginalConstructor()
    ->setMethods([
    'getLibraryByName',
  ])
    ->getMock();
  $config_empty = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();
  $config_empty
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->with('ckeditor_version')
    ->willReturn('');
  $config_factory = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $config_factory
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->with('ckeditor_media_embed.settings')
    ->willReturn($config_empty);
  $container = new ContainerBuilder();
  $container
    ->set('app.root', __DIR__ . '/../../assets');
  $container
    ->set('config.factory', $config_factory);
  \Drupal::setContainer($container);
  $test_library_path = '';
  $test_extension = 'test.core';
  $test_empty_extension = 'empty.test.core';

  // Test with a config file that has no ckeditor_version set, and the
  // drupal library yml file isn't found or can't be parsed.
  $this
    ->assertSame('4.5.x', AssetManager::getCKEditorVersion($library_discovery, $config_factory, $test_library_path, $test_empty_extension), 'The version that should be retrieved is 4.5.x');

  // Test with a config file that has no ckeditor_version set, and the
  // drupal library yml file is able to be found and parsed.
  $this
    ->assertSame('x.x.x', AssetManager::getCKEditorVersion($library_discovery, $config_factory, $test_library_path, $test_extension), 'The version that should be retrieved is x.x.x');

  // Test with a config file that has ckeditor_version set.
  $config_set = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();
  $config_set
    ->expects($this
    ->once())
    ->method('get')
    ->with('ckeditor_version')
    ->willReturn('4.5.0');
  $config_factory = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $config_factory
    ->expects($this
    ->once())
    ->method('get')
    ->with('ckeditor_media_embed.settings')
    ->willReturn($config_set);
  $this
    ->assertSame('4.5.0', AssetManager::getCKEditorVersion($library_discovery, $config_factory, $test_library_path, $test_extension), 'The version that should be retrieved is 4.5.0');
}