function LibraryDiscoveryParserTest::testLibraryWithDataTypes

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

Tests a library with a couple of data formats like full URL.

@covers ::buildByExtension

File

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

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 testLibraryWithDataTypes() {
    $this->moduleHandler
        ->expects($this->atLeastOnce())
        ->method('moduleExists')
        ->with('data_types')
        ->willReturn(TRUE);
    $this->streamWrapperManager
        ->expects($this->atLeastOnce())
        ->method('isValidUri')
        ->willReturn(TRUE);
    $path = __DIR__ . '/library_test_files';
    $path = substr($path, strlen($this->root) + 1);
    $this->extensionPathResolver
        ->expects($this->atLeastOnce())
        ->method('getPath')
        ->with('module', 'data_types')
        ->willReturn($path);
    $this->libraryDiscoveryParser
        ->setFileValidUri('public://test.css', TRUE);
    $this->libraryDiscoveryParser
        ->setFileValidUri('public://test2.css', FALSE);
    $libraries = $this->libraryDiscoveryParser
        ->buildByExtension('data_types');
    $library = $libraries['example'];
    $this->assertCount(5, $library['css']);
    $this->assertEquals('external', $library['css'][0]['type']);
    $this->assertEquals('http://example.com/test.css', $library['css'][0]['data']);
    $this->assertEquals('file', $library['css'][1]['type']);
    $this->assertEquals('tmp/test.css', $library['css'][1]['data']);
    $this->assertEquals('external', $library['css'][2]['type']);
    $this->assertEquals('//cdn.com/test.css', $library['css'][2]['data']);
    $this->assertEquals('file', $library['css'][3]['type']);
    $this->assertEquals('public://test.css', $library['css'][3]['data']);
}

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