function GetFilenameUnitTest::testDrupalGetFilename

Tests that drupal_get_filename() works when the file is not in database.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Bootstrap/GetFilenameUnitTest.php, line 28
Definition of Drupal\system\Tests\Bootstrap\GetFilenameUnitTest.

Class

GetFilenameUnitTest
Tests drupal_get_filename()'s availability.

Namespace

Drupal\system\Tests\Bootstrap

Code

function testDrupalGetFilename() {

  // Assert that the test is meaningful by making sure the keyvalue service
  // does not exist.
  $this
    ->assertFalse(drupal_container()
    ->has('keyvalue'), 'The container has no keyvalue service.');

  // Retrieving the location of a module.
  $this
    ->assertIdentical(drupal_get_filename('module', 'php'), 'core/modules/php/php.module', 'Retrieve module location.');

  // Retrieving the location of a theme.
  $this
    ->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info', 'Retrieve theme location.');

  // Retrieving the location of a theme engine.
  $this
    ->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'core/themes/engines/phptemplate/phptemplate.engine', 'Retrieve theme engine location.');

  // Retrieving the location of a profile. Profiles are a special case with
  // a fixed location and naming.
  $this
    ->assertIdentical(drupal_get_filename('profile', 'standard'), 'core/profiles/standard/standard.profile', 'Retrieve installation profile location.');

  // When a file is not found in the database cache, drupal_get_filename()
  // searches several locations on the filesystem, including the core/
  // directory. We use the '.script' extension below because this is a
  // non-existent filetype that will definitely not exist in the database.
  // Since there is already a core/scripts directory, drupal_get_filename()
  // will automatically check there for 'script' files, just as it does
  // for (e.g.) 'module' files in core/modules.
  $this
    ->assertIdentical(drupal_get_filename('script', 'test'), 'core/scripts/test/test.script');
}