GetFilenameUnitTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php
View source
<?php
namespace Drupal\system\Tests\Bootstrap;
use Drupal\simpletest\KernelTestBase;
class GetFilenameUnitTest extends KernelTestBase {
function testDrupalGetFilename() {
global $install_state;
$install_state['parameters']['profile'] = 'testing';
drupal_static_reset('system_rebuild_module_data');
system_rebuild_module_data();
$this
->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml');
\Drupal::service('theme_handler')
->install(array(
'stark',
));
$this
->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info.yml');
$this
->assertIdentical(drupal_get_filename('theme_engine', 'twig'), 'core/themes/engines/twig/twig.info.yml');
$this
->assertIdentical(drupal_get_filename('profile', 'testing'), 'core/profiles/testing/testing.info.yml');
$non_existing_module = uniqid("", TRUE);
set_error_handler(function ($severity, $message, $file, $line) {
if (strstr($message, 'is missing from the file system:')) {
\Drupal::state()
->set('get_filename_test_triggered_error', TRUE);
return;
}
throw new \ErrorException($message, 0, $severity, $file, $line);
});
$this
->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for an item that does not exist returns NULL.');
$this
->assertTrue(\Drupal::state()
->get('get_filename_test_triggered_error'), 'Searching for an item that does not exist triggers an error.');
restore_error_handler();
}
}