3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\PhpFile;
5 use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
6 use Drupal\Tests\libraries\Kernel\LibraryTypeKernelTestBase;
9 * Tests that the external library manager properly loads PHP file libraries.
13 class PhpFileLibraryTest extends LibraryTypeKernelTestBase {
18 protected function setUp() {
21 $this->container->set('stream_wrapper.php_file_libraries', new TestLibraryFilesStream(
22 $this->container->get('module_handler'),
23 $this->container->get('string_translation'),
31 protected function getLibraryTypeId() {
36 * Tests that the list of PHP files is correctly gathered.
38 public function testPhpFileInfo() {
39 /** @var \Drupal\libraries\ExternalLibrary\PhpFile\PhpFileLibrary $library */
40 $library = $this->getLibrary();
41 $this->assertTrue($library->isInstalled());
42 $library_path = $this->modulePath . '/tests/libraries/test_php_file_library';
43 $this->assertEquals($library_path, $library->getLocalPath());
44 $this->assertEquals(["$library_path/test_php_file_library.php"], $library->getPhpFiles());
48 * Tests that the external library manager properly loads PHP files.
50 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryManager
51 * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryTrait
52 * @see \Drupal\libraries\ExternalLibrary\PhpFile\PhpRequireLoader
54 public function testFileLoading() {
55 $function_name = '_libraries_test_php_function';
56 if (function_exists($function_name)) {
57 $this->markTestSkipped('Cannot test file inclusion if the file to be included has already been included prior.');
61 $this->assertFalse(function_exists($function_name));
62 $this->libraryManager->load('test_php_file_library');
63 $this->assertTrue(function_exists($function_name));