function LibraryDiscoveryParserTest::testVersion

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest::testVersion()
  2. 10 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 263

Class

LibraryDiscoveryParserTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Asset%21LibraryDiscoveryParser.php/class/LibraryDiscoveryParser/9" title="Parses library files to get extension data." class="local">\Drupal\Core\Asset\LibraryDiscoveryParser</a> @group Asset

Namespace

Drupal\Tests\Core\Asset

Code

public function testVersion() {
    $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.