Further modules included.
[yaffs-website] / web / modules / contrib / libraries / tests / src / Kernel / ExternalLibrary / PhpFile / PhpFileLibraryTest.php
1 <?php
2
3 namespace Drupal\Tests\libraries\Kernel\ExternalLibrary\PhpFile;
4
5 use Drupal\Tests\libraries\Kernel\ExternalLibrary\TestLibraryFilesStream;
6 use Drupal\Tests\libraries\Kernel\LibraryTypeKernelTestBase;
7
8 /**
9  * Tests that the external library manager properly loads PHP file libraries.
10  *
11  * @group libraries
12  */
13 class PhpFileLibraryTest extends LibraryTypeKernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   protected function setUp() {
19     parent::setUp();
20
21     $this->container->set('stream_wrapper.php_file_libraries', new TestLibraryFilesStream(
22       $this->container->get('module_handler'),
23       $this->container->get('string_translation'),
24       'libraries'
25     ));
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function getLibraryTypeId() {
32     return 'php_file';
33   }
34
35   /**
36    * Tests that the list of PHP files is correctly gathered.
37    */
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());
45   }
46
47   /**
48    * Tests that the external library manager properly loads PHP files.
49    *
50    * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryManager
51    * @see \Drupal\libraries\ExternalLibrary\ExternalLibraryTrait
52    * @see \Drupal\libraries\ExternalLibrary\PhpFile\PhpRequireLoader
53    */
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.');
58       return;
59     }
60
61     $this->assertFalse(function_exists($function_name));
62     $this->libraryManager->load('test_php_file_library');
63     $this->assertTrue(function_exists($function_name));
64   }
65
66 }