function LibraryDiscoveryParserTest::testVersion

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testVersion()
  2. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testVersion()
  3. 11.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testVersion()

Tests the version property, and how it propagates to the contained assets.

@covers ::buildByExtension

File

core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php, line 282

Class

LibraryDiscoveryParserTest
@coversDefaultClass \Drupal\Core\Asset\LibraryDiscoveryParser[[api-linebreak]] @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testVersion() : void {
  $this->moduleHandler
    ->expects($this->atLeastOnce())
    ->method('moduleExists')
    ->with('versions')
    ->willReturn(TRUE);
  $path = __DIR__ . '/library_test_files';
  $path = substr($path, strlen($this->root) + 1);
  $this->extensionPathResolver
    ->expects($this->atLeastOnce())
    ->method('getPath')
    ->with('module', 'versions')
    ->willReturn($path);
  $libraries = $this->libraryDiscoveryParser
    ->buildByExtension('versions');
  $this->assertArrayNotHasKey('version', $libraries['versionless']);
  $this->assertEquals(-1, $libraries['versionless']['css'][0]['version']);
  $this->assertEquals(-1, $libraries['versionless']['js'][0]['version']);
  $this->assertEquals('9.8.7.6', $libraries['versioned']['version']);
  $this->assertEquals('9.8.7.6', $libraries['versioned']['css'][0]['version']);
  $this->assertEquals('9.8.7.6', $libraries['versioned']['js'][0]['version']);
  $this->assertEquals(\Drupal::VERSION, $libraries['core-versioned']['version']);
  $this->assertEquals(\Drupal::VERSION, $libraries['core-versioned']['css'][0]['version']);
  $this->assertEquals(\Drupal::VERSION, $libraries['core-versioned']['js'][0]['version']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.