You are here

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

Tests \Drupal\ckeditor_media_embed\AssetManager::getPluginsVersion().

File

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

Class

AssetManagerTest
Tests the asset manager.

Namespace

Drupal\Tests\ckeditor_media_embed\Unit

Code

public function testGetPluginsVersion() {
  $test_library_path = '';
  $test_extension = 'test.core';

  // Retrieve the version from the CKEditor plugins.
  $library_discovery = $this
    ->getMockBuilder('Drupal\\Core\\Asset\\LibraryDiscovery')
    ->disableOriginalConstructor()
    ->setMethods([
    'getLibraryByName',
  ])
    ->getMock();
  $config_set = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();
  $config_set
    ->expects($this
    ->once())
    ->method('get')
    ->with('plugins_version_installed')
    ->willReturn('x.x.x');
  $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('x.x.x', AssetManager::getPluginsVersion($library_discovery, $config_factory, $test_library_path, $test_extension), 'The plugin version that should be retrieved is x.x.x');

  // Retrieve the version from the CKEditor.
  $value_map = [
    [
      'plugins_version_installed',
      '',
    ],
    [
      'ckeditor_version',
      '4.5.0',
    ],
  ];
  $config_set = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ImmutableConfig')
    ->disableOriginalConstructor()
    ->getMock();
  $config_set
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->will($this
    ->returnValueMap($value_map));
  $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_set);
  $this
    ->assertSame('4.5.0', AssetManager::getPluginsVersion($library_discovery, $config_factory, $test_library_path, $test_extension), 'The plugin version that should be retrieved is 4.5.0');
}