View source
<?php
namespace Drupal\Tests\Core\Asset;
use Drupal\Core\Asset\LibrariesDirectoryFileFinder;
use Drupal\Core\Extension\ProfileExtensionList;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
class LibrariesDirectoryFileFinderTest extends UnitTestCase {
public function testFind() {
$structure = [
'sites' => [
'example.com' => [
'libraries' => [
'third_party_library' => [
'css' => [
'example.css' => '/*Some css*/',
],
],
],
],
],
'libraries' => [
'third_party_library' => [
'css' => [
'example.css' => '/*Some css*/',
],
],
],
'profiles' => [
'library_testing' => [
'libraries' => [
'third_party_library' => [
'css' => [
'example.css' => '/*Some css*/',
],
],
],
],
],
];
vfsStream::setup('root', NULL, $structure);
$extension_list = $this
->prophesize(ProfileExtensionList::class);
$extension_list
->getPath('library_testing')
->willReturn('profiles/library_testing');
$finder = new LibrariesDirectoryFileFinder('vfs://root', 'sites/example.com', $extension_list
->reveal(), 'library_testing');
$path = $finder
->find('third_party_library/css/example.css');
$this
->assertEquals('sites/example.com/libraries/third_party_library/css/example.css', $path);
unlink('vfs://root/sites/example.com/libraries/third_party_library/css/example.css');
$path = $finder
->find('third_party_library/css/example.css');
$this
->assertEquals('libraries/third_party_library/css/example.css', $path);
unlink('vfs://root/libraries/third_party_library/css/example.css');
$path = $finder
->find('third_party_library/css/example.css');
$this
->assertEquals('profiles/library_testing/libraries/third_party_library/css/example.css', $path);
unlink('vfs://root/profiles/library_testing/libraries/third_party_library/css/example.css');
$this
->assertFalse($finder
->find('third_party_library/css/example.css'));
$path = $finder
->find('third_party_library');
$this
->assertEquals('sites/example.com/libraries/third_party_library', $path);
}
}