diff --git a/core/core.services.yml b/core/core.services.yml index 9c3f606..94cdec4 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -42,6 +42,7 @@ services: arguments: ['@database'] cache.backend.apcu: class: Drupal\Core\Cache\ApcuBackendFactory + arguments: ['@app.root'] cache.backend.php: class: Drupal\Core\Cache\PhpBackendFactory cache.bootstrap: @@ -182,7 +183,7 @@ services: arguments: ['@request_stack', '@url_generator'] form_cache: class: Drupal\Core\Form\FormCache - arguments: ['@keyvalue.expirable', '@module_handler', '@current_user', '@csrf_token', '@logger.channel.form', '@config.factory', '@request_stack', '@page_cache_request_policy'] + arguments: ['@app.root', '@keyvalue.expirable', '@module_handler', '@current_user', '@csrf_token', '@logger.channel.form', '@config.factory', '@request_stack', '@page_cache_request_policy'] public: false # Private to form_builder keyvalue: class: Drupal\Core\KeyValueStore\KeyValueFactory @@ -287,10 +288,10 @@ services: arguments: ['@container.namespaces', '@cache.discovery', '@module_handler'] module_handler: class: Drupal\Core\Extension\ModuleHandler - arguments: ['%container.modules%', '@kernel', '@cache.bootstrap'] + arguments: ['@app.root', '%container.modules%', '@kernel', '@cache.bootstrap'] theme_handler: class: Drupal\Core\Extension\ThemeHandler - arguments: ['@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator'] + arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator'] entity.manager: class: Drupal\Core\Entity\EntityManager arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed', '@event_dispatcher'] @@ -382,6 +383,13 @@ services: event_dispatcher: class: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher arguments: ['@service_container'] + app.root: + class: SplString + factory_service: 'app.root.factory' + factory_method: 'get' + app.root.factory: + class: Drupal\Core\AppRootFactory + arguments: ['@kernel'] controller_resolver: class: Drupal\Core\Controller\ControllerResolver arguments: ['@class_resolver', '@logger.channel.default'] @@ -981,10 +989,10 @@ services: arguments: ['@theme.registry', '@theme.negotiator', '@theme.initialization', '@request_stack'] theme.initialization: class: Drupal\Core\Theme\ThemeInitialization - arguments: ['@theme_handler', '@state'] + arguments: ['@app.root', '@theme_handler', '@state'] theme.registry: class: Drupal\Core\Theme\Registry - arguments: ['@cache.default', '@lock', '@module_handler'] + arguments: ['@app.root', '@cache.default', '@lock', '@module_handler'] tags: - { name: needs_destruction } authentication: @@ -1041,12 +1049,12 @@ services: - { name: needs_destruction } library.discovery.parser: class: Drupal\Core\Asset\LibraryDiscoveryParser - arguments: ['@module_handler'] + arguments: ['@app.root', '@module_handler'] info_parser: class: Drupal\Core\Extension\InfoParser twig: class: Drupal\Core\Template\TwigEnvironment - arguments: ['@twig.loader', '@module_handler', '@theme_handler', '%twig.config%'] + arguments: ['@app.root', '@twig.loader', '@module_handler', '@theme_handler', '%twig.config%'] tags: - { name: service_collector, tag: 'twig.extension', call: addExtension } twig.extension: @@ -1066,7 +1074,7 @@ services: alias: twig.loader.filesystem twig.loader.filesystem: class: Twig_Loader_Filesystem - arguments: ['%app.root%'] + arguments: ['@app.root'] element_info: alias: plugin.manager.element_info file.mime_type.guesser: diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 9e693f5..d77c7a2 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -236,7 +236,7 @@ function _batch_process() { // request, we check if it requires an additional file for functions // definitions. if ($set_changed && isset($current_set['file']) && is_file($current_set['file'])) { - include_once DRUPAL_ROOT . '/' . $current_set['file']; + include_once \Drupal::root() . '/' . $current_set['file']; } $task_message = $label = ''; @@ -409,7 +409,7 @@ function _batch_finished() { if (isset($batch_set['finished'])) { // Check if the set requires an additional file for function definitions. if (isset($batch_set['file']) && is_file($batch_set['file'])) { - include_once DRUPAL_ROOT . '/' . $batch_set['file']; + include_once \Drupal::root() . '/' . $batch_set['file']; } if (is_callable($batch_set['finished'])) { $queue = _batch_queue($batch_set); diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 207fdda..c8e146a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -277,7 +277,7 @@ function drupal_get_filename($type, $name, $filename = NULL) { } // If still unknown, perform a filesystem scan. if (!isset($files[$type][$name])) { - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(DRUPAL_ROOT); // Prevent an infinite recursion by this legacy function. if ($original_type == 'profile') { $listing->setProfileDirectories(array()); @@ -1189,7 +1189,7 @@ function _current_path($path = NULL) { */ function drupal_classloader_register($name, $path) { $loader = \Drupal::service('class_loader'); - $loader->addPsr4('Drupal\\' . $name . '\\', DRUPAL_ROOT . '/' . $path . '/src'); + $loader->addPsr4('Drupal\\' . $name . '\\', \Drupal::root() . '/' . $path . '/src'); } /** diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 4065408..92fb992 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -200,8 +200,8 @@ function _drupal_log_error($error, $fatal = FALSE) { // Attempt to reduce verbosity by removing DRUPAL_ROOT from the file path // in the message. This does not happen for (false) security. - $root_length = strlen(DRUPAL_ROOT); - if (substr($error['%file'], 0, $root_length) == DRUPAL_ROOT) { + $root_length = strlen(\Drupal::root()); + if (substr($error['%file'], 0, $root_length) == \Drupal::root()) { $error['%file'] = substr($error['%file'], $root_length + 1); } // Should not translate the string to avoid errors producing more errors. diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d6e40d1..1c8b9c3 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -288,7 +288,7 @@ function install_begin_request(&$install_state) { $site_path = DrupalKernel::findSitePath($request, FALSE); $class_loader = require __DIR__ . '/../vendor/autoload.php'; - Settings::initialize($site_path, $class_loader); + Settings::initialize(dirname(dirname(__DIR__)), $site_path, $class_loader); // Ensure that procedural dependencies are loaded as early as possible, // since the error/exception handlers depend on them. @@ -390,7 +390,7 @@ function install_begin_request(&$install_state) { } // Add list of all available profiles to the installation state. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery($container->getParameter('app.root')); $listing->setProfileDirectories(array()); $install_state['profiles'] += $listing->scan('profile'); @@ -718,7 +718,7 @@ function install_tasks($install_state) { $profile = $install_state['parameters']['profile']; $profile_install_file = $install_state['profiles'][$profile]->getPath() . '/' . $profile . '.install'; if (file_exists($profile_install_file)) { - include_once DRUPAL_ROOT . '/' . $profile_install_file; + include_once \Drupal::root() . '/' . $profile_install_file; } $function = $install_state['parameters']['profile'] . '_install_tasks'; if (function_exists($function)) { diff --git a/core/includes/install.inc b/core/includes/install.inc index ec6283b..cd305b3 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -593,7 +593,7 @@ function drupal_verify_profile($install_state) { $info = $install_state['profile_info']; // Get the list of available modules for the selected installation profile. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(DRUPAL_ROOT); $present_modules = array(); foreach ($listing->scan('module') as $present_module) { $present_modules[] = $present_module->getName(); diff --git a/core/includes/module.inc b/core/includes/module.inc index ac19a62..606d813 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -179,7 +179,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) * Returns an array of modules required by core. */ function drupal_required_modules() { - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(\Drupal::root()); $files = $listing->scan('module'); $required = array(); diff --git a/core/includes/theme.inc b/core/includes/theme.inc index e772289..d8e7488 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -343,7 +343,7 @@ function _theme($hook, $variables = array()) { // elsewhere. if (!empty($info['includes'])) { foreach ($info['includes'] as $include_file) { - include_once DRUPAL_ROOT . '/' . $include_file; + include_once \Drupal::root() . '/' . $include_file; } } @@ -355,7 +355,7 @@ function _theme($hook, $variables = array()) { // might reside there. if (!empty($base_hook_info['includes'])) { foreach ($base_hook_info['includes'] as $include_file) { - include_once DRUPAL_ROOT . '/' . $include_file; + include_once \Drupal::root() . '/' . $include_file; } } // Replace the preprocess functions with those from the base hook. diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 363cf12..d7e4ee2 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -153,6 +153,15 @@ public static function hasService($id) { } /** + * Gets the app root. + * + * @return string + */ + public static function root() { + return static::$container->getParameter('app.root'); + } + + /** * Indicates if there is a currently active request object. * * @return bool diff --git a/core/lib/Drupal/Core/AppRootFactory.php b/core/lib/Drupal/Core/AppRootFactory.php new file mode 100644 index 0000000..f57d262 --- /dev/null +++ b/core/lib/Drupal/Core/AppRootFactory.php @@ -0,0 +1,42 @@ +drupalKernel = $drupal_kernel; + } + + /** + * Gets the app root. + * + * @return string + */ + public function get() { + return $this->drupalKernel->getAppRoot(); + } + +} + diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index bd962bd..a28ca6e 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -27,10 +27,22 @@ class LibraryDiscoveryParser { protected $moduleHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** + * Constructs a new LibraryDiscoveryParser instance. + * + * @param string $root + * The app root. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(ModuleHandlerInterface $module_handler) { + public function __construct($root, ModuleHandlerInterface $module_handler) { + $this->root = $root; $this->moduleHandler = $module_handler; } @@ -67,7 +79,7 @@ public function buildByExtension($extension) { $library_file = $path . '/' . $extension . '.libraries.yml'; - if ($library_file && file_exists(DRUPAL_ROOT . '/' . $library_file)) { + if ($library_file && file_exists($this->root . '/' . $library_file)) { $libraries = $this->parseLibraryInfo($extension, $library_file); } @@ -222,7 +234,7 @@ public function buildByExtension($extension) { */ protected function parseLibraryInfo($extension, $library_file) { try { - $libraries = Yaml::decode(file_get_contents(DRUPAL_ROOT . '/' . $library_file)); + $libraries = Yaml::decode(file_get_contents($this->root . '/' . $library_file)); } catch (InvalidDataTypeException $e) { // Rethrow a more helpful exception to provide context. diff --git a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php index 341203c..ffe5993 100644 --- a/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php +++ b/core/lib/Drupal/Core/Cache/ApcuBackendFactory.php @@ -20,9 +20,12 @@ class ApcuBackendFactory implements CacheFactoryInterface { /** * Constructs an ApcuBackendFactory object. + * + * @param string $root + * The app root. */ - public function __construct() { - $this->sitePrefix = Crypt::hashBase64(DRUPAL_ROOT . '/' . conf_path()); + public function __construct($root) { + $this->sitePrefix = Crypt::hashBase64($root . '/' . conf_path()); } /** diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index e9bd690..d4e7d5c 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -157,7 +157,7 @@ protected function getAllFolders() { if ($profile = drupal_get_profile()) { $this->folders += $this->getComponentNames('profile', array($profile)); } - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(DRUPAL_ROOT); $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module'))); $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme'))); } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 600fd21..9c926ea 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -180,6 +180,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { protected $sitePath; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Create a DrupalKernel object from a request. * * @param \Symfony\Component\HttpFoundation\Request $request @@ -198,7 +205,8 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { */ public static function createFromRequest(Request $request, $class_loader, $environment, $allow_dumping = TRUE) { // Include our bootstrap file. - require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; + $core_root = dirname(dirname(dirname(__DIR__))); + require_once $core_root . '/includes/bootstrap.inc'; $kernel = new static($environment, $class_loader, $allow_dumping); @@ -206,7 +214,9 @@ public static function createFromRequest(Request $request, $class_loader, $envir static::bootEnvironment(); // Get our most basic settings setup. - $kernel->initializeSettings($request); + $site_path = static::findSitePath($request); + $kernel->setSitePath($site_path); + Settings::initialize(dirname($core_root), $site_path, $class_loader); // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the @@ -220,18 +230,6 @@ public static function createFromRequest(Request $request, $class_loader, $envir } /** - * Initializes the kernel's site path and the Settings singleton. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request that will be used to determine the site path. - */ - protected function initializeSettings(Request $request) { - $site_path = static::findSitePath($request); - $this->setSitePath($site_path); - Settings::initialize($site_path, $this->classLoader); - } - - /** * Constructs a DrupalKernel object. * * @param string $environment @@ -248,6 +246,7 @@ public function __construct($environment, $class_loader, $allow_dumping = TRUE) $this->environment = $environment; $this->classLoader = $class_loader; $this->allowDumping = $allow_dumping; + $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); } /** @@ -352,6 +351,13 @@ public function getSitePath() { /** * {@inheritdoc} */ + public function getAppRoot() { + return $this->root; + } + + /** + * {@inheritdoc} + */ public function boot() { if ($this->booted) { return $this; @@ -361,21 +367,21 @@ public function boot() { Timer::start('page'); // Load legacy and other functional code. - require_once DRUPAL_ROOT . '/core/includes/common.inc'; - require_once DRUPAL_ROOT . '/core/includes/database.inc'; - require_once DRUPAL_ROOT . '/core/includes/path.inc'; - require_once DRUPAL_ROOT . '/core/includes/module.inc'; - require_once DRUPAL_ROOT . '/core/includes/theme.inc'; - require_once DRUPAL_ROOT . '/core/includes/pager.inc'; - require_once DRUPAL_ROOT . '/core/includes/menu.inc'; - require_once DRUPAL_ROOT . '/core/includes/tablesort.inc'; - require_once DRUPAL_ROOT . '/core/includes/file.inc'; - require_once DRUPAL_ROOT . '/core/includes/unicode.inc'; - require_once DRUPAL_ROOT . '/core/includes/form.inc'; - require_once DRUPAL_ROOT . '/core/includes/mail.inc'; - require_once DRUPAL_ROOT . '/core/includes/errors.inc'; - require_once DRUPAL_ROOT . '/core/includes/schema.inc'; - require_once DRUPAL_ROOT . '/core/includes/entity.inc'; + require_once $this->root . '/core/includes/common.inc'; + require_once $this->root . '/core/includes/database.inc'; + require_once $this->root . '/core/includes/path.inc'; + require_once $this->root . '/core/includes/module.inc'; + require_once $this->root . '/core/includes/theme.inc'; + require_once $this->root . '/core/includes/pager.inc'; + require_once $this->root . '/core/includes/menu.inc'; + require_once $this->root . '/core/includes/tablesort.inc'; + require_once $this->root . '/core/includes/file.inc'; + require_once $this->root . '/core/includes/unicode.inc'; + require_once $this->root . '/core/includes/form.inc'; + require_once $this->root . '/core/includes/mail.inc'; + require_once $this->root . '/core/includes/errors.inc'; + require_once $this->root . '/core/includes/schema.inc'; + require_once $this->root . '/core/includes/entity.inc'; // Ensure that findSitePath is set. if (!$this->sitePath) { @@ -588,7 +594,7 @@ public function prepareLegacyRequest(Request $request) { protected function moduleData($module) { if (!$this->moduleData) { // First, find profiles. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery($this->root); $listing->setProfileDirectories(array()); $all_profiles = $listing->scan('profile'); $profiles = array_intersect_key($all_profiles, $this->moduleList); @@ -1017,7 +1023,7 @@ protected function compileContainer() { // - Entity // - Plugin foreach (array('Core', 'Component') as $parent_directory) { - $path = DRUPAL_ROOT . '/core/lib/Drupal/' . $parent_directory; + $path = $this->root . '/core/lib/Drupal/' . $parent_directory; $parent_namespace = 'Drupal\\' . $parent_directory; foreach (new \DirectoryIterator($path) as $component) { /** @var $component \DirectoryIterator */ @@ -1230,7 +1236,7 @@ protected function getModuleFileNames() { protected function getModuleNamespacesPsr4($module_file_names) { $namespaces = array(); foreach ($module_file_names as $module => $filename) { - $namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/src'; + $namespaces["Drupal\\$module"] = $this->root . '/' . dirname($filename) . '/src'; } return $namespaces; } diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index a5eb3b9..e7c468f 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -74,6 +74,13 @@ public function setSitePath($path); public function getSitePath(); /** + * Gets the app root. + * + * @return string + */ + public function getAppRoot(); + + /** * Updates the kernel's list of modules to the new list. * * The kernel needs to update its bundle list and container to match the new diff --git a/core/lib/Drupal/Core/Extension/Extension.php b/core/lib/Drupal/Core/Extension/Extension.php index b335495..3c765fe 100644 --- a/core/lib/Drupal/Core/Extension/Extension.php +++ b/core/lib/Drupal/Core/Extension/Extension.php @@ -43,8 +43,17 @@ class Extension implements \Serializable { protected $splFileInfo; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new Extension object. * + * @param string $root + * The app root. * @param string $type * The type of the extension; e.g., 'module'. * @param string $pathname @@ -53,7 +62,8 @@ class Extension implements \Serializable { * @param string $filename * (optional) The filename of the main extension file; e.g., 'node.module'. */ - public function __construct($type, $pathname, $filename = NULL) { + public function __construct($root, $type, $pathname, $filename = NULL) { + $this->root = $root; $this->type = $type; $this->pathname = $pathname; $this->filename = $filename; @@ -132,7 +142,7 @@ public function getExtensionFilename() { */ public function load() { if ($this->filename) { - include_once DRUPAL_ROOT . '/' . $this->getPath() . '/' . $this->filename; + include_once $this->root . '/' . $this->getPath() . '/' . $this->filename; return TRUE; } return FALSE; @@ -157,6 +167,7 @@ public function __call($method, array $args) { */ public function serialize() { $data = array( + 'root' => $this->root, 'type' => $this->type, 'pathname' => $this->pathname, 'filename' => $this->filename, @@ -177,6 +188,7 @@ public function serialize() { */ public function unserialize($data) { $data = unserialize($data); + $this->root = $data['root']; $this->type = $data['type']; $this->pathname = $data['pathname']; $this->filename = $data['filename']; diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php index f51cbb3..9681162 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -74,13 +74,30 @@ class ExtensionDiscovery { protected $profileDirectories; /** + * The app root. + * + * @var string + */ + protected $root; + + /** + * Constructs a new ExtensionDiscovery object. + * + * @param string $root + * The app root. + */ + public function __construct($root) { + $this->root = $root; + } + + /** * Discovers available extensions of a given type. * * Finds all extensions (modules, themes, etc) that exist on the site. It * searches in several locations. For instance, to discover all available * modules: * @code - * $listing = new ExtensionDiscovery(); + * $listing = new ExtensionDiscovery(\Drupal::root()); * $modules = $listing->scan('module'); * @endcode * @@ -304,9 +321,9 @@ protected function scanDirectory($dir, $include_tests) { // be used (which also improves performance, since any configured PHP // include_paths will not be consulted). Retain the relative originating // directory being scanned, so relative paths can be reconstructed below - // (all paths are expected to be relative to DRUPAL_ROOT). + // (all paths are expected to be relative to $this->root). $dir_prefix = ($dir == '' ? '' : "$dir/"); - $absolute_dir = ($dir == '' ? DRUPAL_ROOT : DRUPAL_ROOT . "/$dir"); + $absolute_dir = ($dir == '' ? $this->root : $this->root . "/$dir"); if (!is_dir($absolute_dir)) { return $files; @@ -370,7 +387,7 @@ protected function scanDirectory($dir, $include_tests) { $filename = NULL; } - $extension = new Extension($type, $pathname, $filename); + $extension = new Extension($this->root, $type, $pathname, $filename); // Track the originating directory for sorting purposes. $extension->subpath = $fileinfo->getSubPath(); diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 028d7d4..12d2805 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -93,8 +93,17 @@ class ModuleHandler implements ModuleHandlerInterface { protected $alterFunctions; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a ModuleHandler object. * + * @param string $root + * The app root. * @param array $module_list * An associative array whose keys are the names of installed modules and * whose values are Extension class parameters. This is normally the @@ -107,10 +116,11 @@ class ModuleHandler implements ModuleHandlerInterface { * @see \Drupal\Core\DrupalKernel * @see \Drupal\Core\CoreServiceProvider */ - public function __construct(array $module_list = array(), DrupalKernelInterface $kernel, CacheBackendInterface $cache_backend) { + public function __construct($root, array $module_list = array(), DrupalKernelInterface $kernel, CacheBackendInterface $cache_backend) { + $this->root = $root; $this->moduleList = array(); foreach ($module_list as $name => $module) { - $this->moduleList[$name] = new Extension($module['type'], $module['pathname'], $module['filename']); + $this->moduleList[$name] = new Extension($this->root, $module['type'], $module['pathname'], $module['filename']); } $this->kernel = $kernel; $this->cacheBackend = $cache_backend; @@ -212,8 +222,8 @@ public function addProfile($name, $path) { */ protected function add($type, $name, $path) { $pathname = "$path/$name.info.yml"; - $filename = file_exists(DRUPAL_ROOT . "/$path/$name.$type") ? "$name.$type" : NULL; - $this->moduleList[$name] = new Extension($type, $pathname, $filename); + $filename = file_exists($this->root . "/$path/$name.$type") ? "$name.$type" : NULL; + $this->moduleList[$name] = new Extension($this->root, $type, $pathname, $filename); $this->resetImplementations(); } @@ -262,12 +272,12 @@ public function loadAllIncludes($type, $name = NULL) { public function loadInclude($module, $type, $name = NULL) { if ($type == 'install') { // Make sure the installation API is available - include_once DRUPAL_ROOT . '/core/includes/install.inc'; + include_once $this->root . '/core/includes/install.inc'; } $name = $name ?: $module; if (isset($this->moduleList[$module])) { - $file = DRUPAL_ROOT . '/' . $this->moduleList[$module]->getPath() . "/$name.$type"; + $file = $this->root . '/' . $this->moduleList[$module]->getPath() . "/$name.$type"; if (is_file($file)) { require_once $file; return $file; @@ -736,7 +746,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { } // Required for module installation checks. - include_once DRUPAL_ROOT . '/core/includes/install.inc'; + include_once $this->root . '/core/includes/install.inc'; /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */ $config_installer = \Drupal::service('config.installer'); @@ -783,7 +793,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $module_path = drupal_get_path('module', $name); $pathname = "$module_path/$name.info.yml"; $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL; - $module_filenames[$name] = new Extension('module', $pathname, $filename); + $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename); } } @@ -1076,7 +1086,7 @@ protected function removeCacheBins($module) { public function getModuleDirectories() { $dirs = array(); foreach ($this->getModuleList() as $name => $module) { - $dirs[$name] = DRUPAL_ROOT . '/' . $module->getPath(); + $dirs[$name] = $this->root . '/' . $module->getPath(); } return $dirs; } diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index a316f36..02100fb 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -115,8 +115,17 @@ class ThemeHandler implements ThemeHandlerInterface { protected $configManager; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new ThemeHandler. * + * @param string $root + * The app root. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory to get the installed themes. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -141,7 +150,8 @@ class ThemeHandler implements ThemeHandlerInterface { * @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery * (optional) A extension discovery instance (for unit tests). */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderIndicatorInterface $route_builder_indicator = NULL, ExtensionDiscovery $extension_discovery = NULL) { + public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderIndicatorInterface $route_builder_indicator = NULL, ExtensionDiscovery $extension_discovery = NULL) { + $this->root = $root; $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; $this->state = $state; @@ -639,7 +649,7 @@ protected function doGetBaseThemes(array $themes, $theme, $used_themes = array() */ protected function getExtensionDiscovery() { if (!isset($this->extensionDiscovery)) { - $this->extensionDiscovery = new ExtensionDiscovery(); + $this->extensionDiscovery = new ExtensionDiscovery($this->root); } return $this->extensionDiscovery; } @@ -700,7 +710,7 @@ protected function systemThemeList() { public function getThemeDirectories() { $dirs = array(); foreach ($this->listInfo() as $name => $theme) { - $dirs[$name] = DRUPAL_ROOT . '/' . $theme->getPath(); + $dirs[$name] = $this->root . '/' . $theme->getPath(); } return $dirs; } diff --git a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php index e163c04..ccd491c 100644 --- a/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php +++ b/core/lib/Drupal/Core/FileTransfer/Form/FileTransferAuthorizeForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides the file transfer authorization form. @@ -17,6 +18,30 @@ class FileTransferAuthorizeForm extends FormBase { /** + * The app root. + * + * @var string + */ + protected $root; + + /** + * Constructs a new FileTransferAuthorizeForm object. + * + * @param string $root + * The app root. + */ + public function __construct($root) { + $this->root = $root; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static ($container->getParameter('app.root')); + } + + /** * {@inheritdoc} */ public function getFormID() { @@ -241,7 +266,7 @@ protected function getFiletransfer($backend, $settings = array()) { if (!empty($_SESSION['authorize_filetransfer_info'][$backend])) { $backend_info = $_SESSION['authorize_filetransfer_info'][$backend]; if (class_exists($backend_info['class'])) { - $filetransfer = $backend_info['class']::factory(DRUPAL_ROOT, $settings); + $filetransfer = $backend_info['class']::factory($this->root, $settings); } } return $filetransfer; @@ -316,7 +341,7 @@ protected function runOperation($filetransfer) { $operation = $_SESSION['authorize_operation']; unset($_SESSION['authorize_operation']); - require_once DRUPAL_ROOT . '/' . $operation['file']; + require_once $this->root . '/' . $operation['file']; call_user_func_array($operation['callback'], array_merge(array($filetransfer), $operation['arguments'])); } diff --git a/core/lib/Drupal/Core/Form/FormCache.php b/core/lib/Drupal/Core/Form/FormCache.php index 9eba042..ea38fd2 100644 --- a/core/lib/Drupal/Core/Form/FormCache.php +++ b/core/lib/Drupal/Core/Form/FormCache.php @@ -82,8 +82,17 @@ class FormCache implements FormCacheInterface { protected $requestPolicy; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new FormCache. * + * @param string $root + * The app root. * @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $key_value_expirable_factory * The key value expirable factory, used to create key value expirable * stores for the form cache and form state cache. @@ -102,7 +111,8 @@ class FormCache implements FormCacheInterface { * @param \Drupal\Core\PageCache\RequestPolicyInterface $request_policy * A policy rule determining the cacheability of a request. */ - public function __construct(KeyValueExpirableFactoryInterface $key_value_expirable_factory, ModuleHandlerInterface $module_handler, AccountInterface $current_user, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, ConfigFactoryInterface $config_factory, RequestStack $request_stack, RequestPolicyInterface $request_policy) { + public function __construct($root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, ModuleHandlerInterface $module_handler, AccountInterface $current_user, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, ConfigFactoryInterface $config_factory, RequestStack $request_stack, RequestPolicyInterface $request_policy) { + $this->root = $root; $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->moduleHandler = $module_handler; $this->currentUser = $current_user; @@ -160,7 +170,7 @@ protected function loadCachedFormState($form_build_id, FormStateInterface $form_ $this->moduleHandler->loadInclude($file['module'], $file['type'], $file['name']); } elseif (file_exists($file)) { - require_once DRUPAL_ROOT . '/' . $file; + require_once $this->root . '/' . $file; } } // Retrieve the list of previously known safe strings and store it for diff --git a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php index db3fd15..05c9c23 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php @@ -49,8 +49,17 @@ class SiteConfigureForm extends FormBase { protected $countryManager; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new SiteConfigureForm. * + * @param string $root + * The app root. * @param \Drupal\user\UserStorageInterface $user_storage * The user storage. * @param \Drupal\Core\State\StateInterface $state @@ -60,7 +69,8 @@ class SiteConfigureForm extends FormBase { * @param \Drupal\Core\Locale\CountryManagerInterface $country_manager * The country manager. */ - public function __construct(UserStorageInterface $user_storage, StateInterface $state, ModuleHandlerInterface $module_handler, CountryManagerInterface $country_manager) { + public function __construct($root, UserStorageInterface $user_storage, StateInterface $state, ModuleHandlerInterface $module_handler, CountryManagerInterface $country_manager) { + $this->root = $root; $this->userStorage = $user_storage; $this->state = $state; $this->moduleHandler = $module_handler; @@ -72,6 +82,7 @@ public function __construct(UserStorageInterface $user_storage, StateInterface $ */ public static function create(ContainerInterface $container) { return new static( + $container->get('app.root'), $container->get('entity.manager')->getStorage('user'), $container->get('state'), $container->get('module_handler'), @@ -103,7 +114,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // distract from the message that the Drupal installation has completed // successfully.) $post_params = $this->getRequest()->request->all(); - if (empty($post_params) && (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file(DRUPAL_ROOT . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) { + if (empty($post_params) && (!drupal_verify_install_file($this->root . '/' . $settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file($this->root . '/' . $settings_dir, FILE_NOT_WRITABLE, 'dir'))) { drupal_set_message(t('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, consult the online handbook.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'warning'); } diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php index def307f..4fe80b3 100644 --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@ -85,6 +85,8 @@ public static function getAll() { /** * Bootstraps settings.php and the Settings singleton. * + * @param string $app_root + * The app root. * @param string $site_path * The current site path. * @param \Composer\Autoload\ClassLoader $class_loader @@ -94,7 +96,7 @@ public static function getAll() { * * @see default.settings.php */ - public static function initialize($site_path, &$class_loader) { + public static function initialize($app_root, $site_path, &$class_loader) { // Export these settings.php variables to the global namespace. global $base_url, $cookie_domain, $config_directories, $config; $settings = array(); @@ -102,8 +104,8 @@ public static function initialize($site_path, &$class_loader) { $databases = array(); // Make conf_path() available as local variable in settings.php. - if (is_readable(DRUPAL_ROOT . '/' . $site_path . '/settings.php')) { - require DRUPAL_ROOT . '/' . $site_path . '/settings.php'; + if (is_readable($app_root . '/' . $site_path . '/settings.php')) { + require $app_root . '/' . $site_path . '/settings.php'; } // Initialize Database. diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php index 97341ac..3716277 100644 --- a/core/lib/Drupal/Core/Template/TwigEnvironment.php +++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php @@ -33,14 +33,17 @@ class TwigEnvironment extends \Twig_Environment { /** * Constructs a TwigEnvironment object and stores cache and storage * internally. + * + * @param string $root + * The app root; */ - public function __construct(\Twig_LoaderInterface $loader = NULL, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, $options = array()) { + public function __construct($root, \Twig_LoaderInterface $loader = NULL, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, $options = array()) { // @todo Pass as arguments from the DIC. $this->cache_object = \Drupal::cache(); // Ensure that twig.engine is loaded, given that it is needed to render a // template because functions like twig_drupal_escape_filter are called. - require_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine'; + require_once $root . '/core/themes/engines/twig/twig.engine'; // Set twig path namespace for themes and modules. $namespaces = array(); diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php index 8829113..9fa7430 100644 --- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php @@ -42,8 +42,8 @@ public function __construct($environment, $class_loader) { 'simpletest' => 0, ); $this->moduleData = array( - 'system' => new Extension('module', 'core/modules/system/system.info.yml', 'system.module'), - 'simpletest' => new Extension('module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'), + 'system' => new Extension(DRUPAL_ROOT, 'module', 'core/modules/system/system.info.yml', 'system.module'), + 'simpletest' => new Extension(DRUPAL_ROOT, 'module', 'core/modules/simpletest/simpletest.info.yml', 'simpletest.module'), ); } diff --git a/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php index 8c9efb3..ff4f678 100644 --- a/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -130,8 +130,17 @@ class Registry implements DestructableInterface { protected $themeName; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a \Drupal\Core\\Theme\Registry object. * + * @param string $root + * The app root. * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend interface to use for the complete theme registry data. * @param \Drupal\Core\Lock\LockBackendInterface $lock @@ -141,7 +150,8 @@ class Registry implements DestructableInterface { * @param string $theme_name * (optional) The name of the theme for which to construct the registry. */ - public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, $theme_name = NULL) { + public function __construct($root, CacheBackendInterface $cache, LockBackendInterface $lock, ModuleHandlerInterface $module_handler, $theme_name = NULL) { + $this->root = $root; $this->cache = $cache; $this->lock = $lock; $this->moduleHandler = $module_handler; @@ -180,14 +190,14 @@ protected function init($theme_name = NULL) { $ancestor = $themes[$ancestor]->base_theme; $this->baseThemes[] = $themes[$ancestor]; if (!empty($themes[$ancestor]->owner)) { - include_once DRUPAL_ROOT . '/' . $themes[$ancestor]->owner; + include_once $this->root . '/' . $themes[$ancestor]->owner; } } $this->baseThemes = array_reverse($this->baseThemes); if (isset($this->theme->engine)) { $this->engine = $this->theme->engine; - include_once DRUPAL_ROOT . '/' . $this->theme->owner; + include_once $this->root . '/' . $this->theme->owner; if (function_exists($this->theme->engine . '_init')) { foreach ($this->baseThemes as $base) { call_user_func($this->theme->engine . '_init', $base); @@ -444,7 +454,7 @@ protected function processExtension(&$cache, $name, $type, $theme, $path) { if (isset($info['file'])) { $include_file = isset($info['path']) ? $info['path'] : $path; $include_file .= '/' . $info['file']; - include_once DRUPAL_ROOT . '/' . $include_file; + include_once $this->root . '/' . $include_file; $result[$hook]['includes'][] = $include_file; } diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php index d4e1d95..bbe5cc7 100644 --- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php +++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php @@ -32,14 +32,24 @@ class ThemeInitialization implements ThemeInitializationInterface { protected $state; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new ThemeInitialization object. * + * @param string $root + * The app root. * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. * @param \Drupal\Core\State\StateInterface $state * The state. */ - public function __construct(ThemeHandlerInterface $theme_handler, StateInterface $state) { + public function __construct($root, ThemeHandlerInterface $theme_handler, StateInterface $state) { + $this->root = $root; $this->themeHandler = $theme_handler; $this->state = $state; } @@ -77,7 +87,7 @@ public function getActiveThemeByName($theme_name) { $theme_name = 'core'; // /core/core.info.yml does not actually exist, but is required because // Extension expects a pathname. - $active_theme = $this->getActiveTheme(new Extension('theme', 'core/core.info.yml')); + $active_theme = $this->getActiveTheme(new Extension($this->root, 'theme', 'core/core.info.yml')); // Early-return and do not set state, because the initialized $theme_name // differs from the original $theme_name. @@ -105,7 +115,7 @@ public function loadActiveTheme(ActiveTheme $active_theme) { // Initialize the theme. if ($theme_engine = $active_theme->getEngine()) { // Include the engine. - include_once DRUPAL_ROOT . '/' . $active_theme->getOwner(); + include_once $this->root . '/' . $active_theme->getOwner(); if (function_exists($theme_engine . '_init')) { foreach ($active_theme->getBaseThemes() as $base) { @@ -119,17 +129,17 @@ public function loadActiveTheme(ActiveTheme $active_theme) { foreach ($active_theme->getBaseThemes() as $base) { // Include the theme file or the engine. if ($base->getOwner()) { - include_once DRUPAL_ROOT . '/' . $base->getOwner(); + include_once $this->root . '/' . $base->getOwner(); } } // and our theme gets one too. if ($active_theme->getOwner()) { - include_once DRUPAL_ROOT . '/' . $active_theme->getOwner(); + include_once $this->root . '/' . $active_theme->getOwner(); } } // Always include Twig as the default theme engine. - include_once DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine'; + include_once $this->root . '/core/themes/engines/twig/twig.engine'; } /** diff --git a/core/modules/block/tests/src/Unit/Menu/BlockLocalTasksTest.php b/core/modules/block/tests/src/Unit/Menu/BlockLocalTasksTest.php index b1a84a4..0b63d7e 100644 --- a/core/modules/block/tests/src/Unit/Menu/BlockLocalTasksTest.php +++ b/core/modules/block/tests/src/Unit/Menu/BlockLocalTasksTest.php @@ -49,6 +49,7 @@ protected function setUp() { $container = new ContainerBuilder(); $container->set('config.factory', $config_factory); $container->set('theme_handler', $theme_handler); + $container->setParameter('app.root', $this->root); \Drupal::setContainer($container); } diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index 0762728..41259d5 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -323,7 +323,7 @@ public function getLangcodes() { if (empty($langcodes)) { $langcodes = array(); // Collect languages included with CKEditor based on file listing. - $ckeditor_languages = new \GlobIterator(DRUPAL_ROOT . '/core/assets/vendor/ckeditor/lang/*.js'); + $ckeditor_languages = new \GlobIterator(\Drupal::root() . '/core/assets/vendor/ckeditor/lang/*.js'); foreach ($ckeditor_languages as $language_file) { $langcode = $language_file->getBasename('.js'); $langcodes[$langcode] = $langcode; diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 92e2136..138385c 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -150,7 +150,7 @@ function color_get_info($theme) { } $path = drupal_get_path('theme', $theme); - $file = DRUPAL_ROOT . '/' . $path . '/color/color.inc'; + $file = \Drupal::root() . '/' . $path . '/color/color.inc'; if ($path && file_exists($file)) { include $file; // Add in default values. @@ -308,7 +308,7 @@ function template_preprocess_color_scheme_form(&$variables) { $form['scheme']['#attached']['js'][$preview_js_path] = array('weight' => -1); // Attempt to load preview HTML if the theme provides it. - $preview_html_path = DRUPAL_ROOT . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html'); + $preview_html_path = \Drupal::root() . '/' . (isset($info['preview_html']) ? drupal_get_path('theme', $theme) . '/' . $info['preview_html'] : drupal_get_path('module', 'color') . '/preview.html'); $variables['html_preview'] = SafeMarkup::set(file_get_contents($preview_html_path)); } diff --git a/core/modules/config/tests/config_test/src/TestInstallStorage.php b/core/modules/config/tests/config_test/src/TestInstallStorage.php index f85de95..e4b3864 100644 --- a/core/modules/config/tests/config_test/src/TestInstallStorage.php +++ b/core/modules/config/tests/config_test/src/TestInstallStorage.php @@ -25,7 +25,7 @@ protected function getAllFolders() { if (!isset($this->folders)) { $this->folders = $this->getComponentNames('core', array('core')); // @todo Refactor getComponentNames() to use the extension list directly. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(\Drupal::root()); $listing->setProfileDirectories(array()); $this->folders += $this->getComponentNames('profile', array_keys($listing->scan('profile'))); $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module'))); diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index a14d730..6d558fe 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -787,7 +787,7 @@ function _filter_html_image_secure_process($text) { $base_path_length = Unicode::strlen($base_path); // Find the directory on the server where index.php resides. - $local_dir = DRUPAL_ROOT . '/'; + $local_dir = \Drupal::root() . '/'; $html_dom = Html::load($text); $images = $html_dom->getElementsByTagName('img'); diff --git a/core/modules/image/src/Tests/ImageItemTest.php b/core/modules/image/src/Tests/ImageItemTest.php index e0a3b36..4f7dd15 100644 --- a/core/modules/image/src/Tests/ImageItemTest.php +++ b/core/modules/image/src/Tests/ImageItemTest.php @@ -55,7 +55,7 @@ protected function setUp() { 'field_name' => 'image_test', 'bundle' => 'entity_test', ))->save(); - file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); + file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array( 'uri' => 'public://example.jpg', )); @@ -88,7 +88,7 @@ public function testImageItem() { $this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid()); // Make sure the computed entity reflects updates to the referenced file. - file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/feed.png', 'public://example-2.jpg'); + file_unmanaged_copy(\Drupal::root() . '/core/misc/feed.png', 'public://example-2.jpg'); $image2 = entity_create('file', array( 'uri' => 'public://example-2.jpg', )); diff --git a/core/modules/image/src/Tests/ImageThemeFunctionTest.php b/core/modules/image/src/Tests/ImageThemeFunctionTest.php index 43a6338..06e9710 100644 --- a/core/modules/image/src/Tests/ImageThemeFunctionTest.php +++ b/core/modules/image/src/Tests/ImageThemeFunctionTest.php @@ -50,7 +50,7 @@ protected function setUp() { 'field_name' => 'image_test', 'bundle' => 'entity_test', ))->save(); - file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); + file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array( 'uri' => 'public://example.jpg', )); diff --git a/core/modules/rdf/src/Tests/StandardProfileTest.php b/core/modules/rdf/src/Tests/StandardProfileTest.php index 29e9804..05c2fac 100644 --- a/core/modules/rdf/src/Tests/StandardProfileTest.php +++ b/core/modules/rdf/src/Tests/StandardProfileTest.php @@ -131,7 +131,7 @@ protected function setUp() { $this->term->save(); // Create image. - file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); + file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array('uri' => 'public://example.jpg')); $this->image->save(); diff --git a/core/modules/search/src/Tests/SearchSimplifyTest.php b/core/modules/search/src/Tests/SearchSimplifyTest.php index d1c2774..4594459 100644 --- a/core/modules/search/src/Tests/SearchSimplifyTest.php +++ b/core/modules/search/src/Tests/SearchSimplifyTest.php @@ -25,7 +25,7 @@ function testSearchSimplifyUnicode() { // their own lines). So the even-numbered lines should simplify to nothing, // and the odd-numbered lines we need to split into shorter chunks and // verify that simplification doesn't lose any characters. - $input = file_get_contents(DRUPAL_ROOT . '/core/modules/search/tests/UnicodeTest.txt'); + $input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt'); $basestrings = explode(chr(10), $input); $strings = array(); foreach ($basestrings as $key => $string) { diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install index 4e5e01b..9d8e3c7 100644 --- a/core/modules/simpletest/simpletest.install +++ b/core/modules/simpletest/simpletest.install @@ -66,17 +66,17 @@ function simpletest_requirements($phase) { } $site_directory = 'sites/simpletest'; - if (!drupal_verify_install_file(DRUPAL_ROOT . '/' . $site_directory, FILE_EXIST|FILE_READABLE|FILE_WRITABLE|FILE_EXECUTABLE, 'dir')) { + if (!drupal_verify_install_file(\Drupal::root() . '/' . $site_directory, FILE_EXIST|FILE_READABLE|FILE_WRITABLE|FILE_EXECUTABLE, 'dir')) { $requirements['simpletest_site_directory'] = array( 'title' => t('Simpletest site directory'), - 'value' => is_dir(DRUPAL_ROOT . '/' . $site_directory) ? t('Not writable') : t('Missing'), + 'value' => is_dir(\Drupal::root() . '/' . $site_directory) ? t('Not writable') : t('Missing'), 'severity' => REQUIREMENT_ERROR, 'description' => t('The testing framework requires the !sites-simpletest directory to exist and be writable in order to run tests.', array( '!sites-simpletest' => './' . String::checkPlain($site_directory) . '', )), ); } - elseif (!file_save_htaccess(DRUPAL_ROOT . '/' . $site_directory, FALSE)) { + elseif (!file_save_htaccess(\Drupal::root() . '/' . $site_directory, FALSE)) { $requirements['simpletest_site_directory'] = array( 'title' => t('Simpletest site directory'), 'value' => t('Not protected'), diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 3768b90..8c14e52 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -222,7 +222,7 @@ function simpletest_phpunit_xml_filepath($test_id) { * The path to core's phpunit.xml.dist configuration file. */ function simpletest_phpunit_configuration_filepath() { - return DRUPAL_ROOT . '/core/phpunit.xml.dist'; + return \Drupal::root() . '/core/phpunit.xml.dist'; } /** @@ -267,7 +267,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun // Need to change directories before running the command so that we can use // relative paths in the configuration file's exclusions. $old_cwd = getcwd(); - chdir(DRUPAL_ROOT . "/core"); + chdir(\Drupal::root() . "/core"); // exec in a subshell so that the environment is isolated when running tests // via the simpletest UI. @@ -288,10 +288,10 @@ function simpletest_phpunit_command() { if (substr(PHP_OS, 0, 3) == 'WIN') { $php_executable_finder = new PhpExecutableFinder(); $php = $php_executable_finder->find(); - $phpunit_bin = escapeshellarg($php) . " -f " . escapeshellarg(DRUPAL_ROOT . "/core/vendor/phpunit/phpunit/composer/bin/phpunit") . " --"; + $phpunit_bin = escapeshellarg($php) . " -f " . escapeshellarg(\Drupal::root() . "/core/vendor/phpunit/phpunit/composer/bin/phpunit") . " --"; } else { - $phpunit_bin = DRUPAL_ROOT . "/core/vendor/bin/phpunit"; + $phpunit_bin = \Drupal::root() . "/core/vendor/bin/phpunit"; } return $phpunit_bin; } diff --git a/core/modules/simpletest/src/InstallerTestBase.php b/core/modules/simpletest/src/InstallerTestBase.php index 90f318b..6e0324a 100644 --- a/core/modules/simpletest/src/InstallerTestBase.php +++ b/core/modules/simpletest/src/InstallerTestBase.php @@ -117,6 +117,8 @@ protected function setUp() { $this->container ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager') ->addArgument(new Reference('language_manager')); + $this->container + ->setParameter('app.root', DRUPAL_ROOT); \Drupal::setContainer($this->container); $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); @@ -138,8 +140,8 @@ protected function setUp() { // Import new settings.php written by the installer. $request = Request::createFromGlobals(); - $class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php'; - Settings::initialize(DrupalKernel::findSitePath($request), $class_loader); + $class_loader = require $this->container->getParameter('app.root') . '/core/vendor/autoload.php'; + Settings::initialize($this->container->getParameter('app.root'), DrupalKernel::findSitePath($request), $class_loader); foreach ($GLOBALS['config_directories'] as $type => $path) { $this->configDirectories[$type] = $path; } @@ -150,7 +152,7 @@ protected function setUp() { // directory has to be writable. // WebTestBase::tearDown() will delete the entire test site directory. // Not using File API; a potential error must trigger a PHP warning. - chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777); + chmod($this->container->getParameter('app.root') . '/' . $this->siteDirectory, 0777); $this->kernel = DrupalKernel::createFromRequest($request, $class_loader, 'prod', FALSE); $this->kernel->prepareLegacyRequest($request); $this->container = $this->kernel->getContainer(); diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index 2c86907..50e19f0 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -439,7 +439,7 @@ public static function parseTestClassAnnotations(\ReflectionClass $class) { * An array of Extension objects, keyed by extension name. */ protected function getExtensions() { - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(DRUPAL_ROOT); // Ensure that tests in all profiles are discovered. $listing->setProfileDirectories(array()); $extensions = $listing->scan('module', TRUE); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index a8568d6..260d983 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -836,14 +836,14 @@ protected function setUp() { // bootstrap into DRUPAL_BOOTSTRAP_CONFIGURATION (again). Hence, we have to // reload the newly written custom settings.php manually. $class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php'; - Settings::initialize($directory, $class_loader); + Settings::initialize(DRUPAL_ROOT, $directory, $class_loader); // Execute the non-interactive installer. require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; install_drupal($parameters); // Import new settings.php written by the installer. - Settings::initialize($directory, $class_loader); + Settings::initialize(DRUPAL_ROOT, $directory, $class_loader); foreach ($GLOBALS['config_directories'] as $type => $path) { $this->configDirectories[$type] = $path; } diff --git a/core/modules/system/src/Controller/BatchController.php b/core/modules/system/src/Controller/BatchController.php index 4245480..df025ed 100644 --- a/core/modules/system/src/Controller/BatchController.php +++ b/core/modules/system/src/Controller/BatchController.php @@ -36,14 +36,24 @@ class BatchController implements ContainerInjectionInterface { protected $titleResolver; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new BatchController. * + * @param string $root + * The app root. * @param \Drupal\Core\Page\DefaultHtmlFragmentRenderer $html_fragment_renderer * The fragment rendering service. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. */ - public function __construct(DefaultHtmlFragmentRenderer $html_fragment_renderer, TitleResolverInterface $title_resolver) { + public function __construct($root, DefaultHtmlFragmentRenderer $html_fragment_renderer, TitleResolverInterface $title_resolver) { + $this->root = $root; $this->fragmentRenderer = $html_fragment_renderer; $this->titleResolver = $title_resolver; } @@ -53,6 +63,7 @@ public function __construct(DefaultHtmlFragmentRenderer $html_fragment_renderer, */ public static function create(ContainerInterface $container) { return new static( + $container->getParameter('app.root'), $container->get('html_fragment_renderer'), $container->get('title_resolver') ); @@ -71,7 +82,7 @@ public static function create(ContainerInterface $container) { * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException */ public function batchPage(Request $request) { - require_once DRUPAL_ROOT . '/core/includes/batch.inc'; + require_once $this->root . '/core/includes/batch.inc'; $output = _batch_page($request); if ($output === FALSE) { diff --git a/core/modules/system/src/Controller/DbUpdateController.php b/core/modules/system/src/Controller/DbUpdateController.php index 7dff04a..f4c1939 100644 --- a/core/modules/system/src/Controller/DbUpdateController.php +++ b/core/modules/system/src/Controller/DbUpdateController.php @@ -69,8 +69,17 @@ class DbUpdateController extends ControllerBase { protected $entityDefinitionUpdateManager; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new UpdateController. * + * @param string $root + * The app root. * @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $key_value_expirable_factory * The keyvalue expirable factory. * @param \Drupal\Core\Cache\CacheBackendInterface $cache @@ -84,7 +93,8 @@ class DbUpdateController extends ControllerBase { * @param \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $entity_definition_update_manager * The entity definition update manager. */ - public function __construct(KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account, EntityDefinitionUpdateManagerInterface $entity_definition_update_manager) { + public function __construct($root, KeyValueExpirableFactoryInterface $key_value_expirable_factory, CacheBackendInterface $cache, StateInterface $state, ModuleHandlerInterface $module_handler, AccountInterface $account, EntityDefinitionUpdateManagerInterface $entity_definition_update_manager) { + $this->root = $root; $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->cache = $cache; $this->state = $state; @@ -98,6 +108,7 @@ public function __construct(KeyValueExpirableFactoryInterface $key_value_expirab */ public static function create(ContainerInterface $container) { return new static( + $container->getParameter('app.root'), $container->get('keyvalue.expirable'), $container->get('cache.default'), $container->get('state'), @@ -123,8 +134,8 @@ public static function create(ContainerInterface $container) { * A response object object. */ public function handle($op, Request $request) { - require_once DRUPAL_ROOT . '/core/includes/install.inc'; - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once $this->root . '/core/includes/install.inc'; + require_once $this->root . '/core/includes/update.inc'; drupal_load_updates(); update_fix_compatibility(); @@ -164,7 +175,7 @@ public function handle($op, Request $request) { // Regular batch ops : defer to batch processing API. default: - require_once DRUPAL_ROOT . '/core/includes/batch.inc'; + require_once $this->root . '/core/includes/batch.inc'; $regions['sidebar_first'] = $this->updateTasksList('run'); $output = _batch_page($request); break; diff --git a/core/modules/system/src/Tests/Ajax/FormValuesTest.php b/core/modules/system/src/Tests/Ajax/FormValuesTest.php index c4f1a7c..17e74f6 100644 --- a/core/modules/system/src/Tests/Ajax/FormValuesTest.php +++ b/core/modules/system/src/Tests/Ajax/FormValuesTest.php @@ -59,6 +59,6 @@ function testSimpleAjaxFormValue() { } // The exceptions are expected. Do not interpret them as a test failure. // Not using File API; a potential error must trigger a PHP warning. - unlink(DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'); + unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); } } diff --git a/core/modules/system/src/Tests/Common/SystemListingTest.php b/core/modules/system/src/Tests/Common/SystemListingTest.php index fc1cebf..6b2e1bb 100644 --- a/core/modules/system/src/Tests/Common/SystemListingTest.php +++ b/core/modules/system/src/Tests/Common/SystemListingTest.php @@ -37,13 +37,13 @@ function testDirectoryPrecedence() { foreach ($expected_directories as $module => $directories) { foreach ($directories as $directory) { $filename = "$directory/$module/$module.info.yml"; - $this->assertTrue(file_exists(DRUPAL_ROOT . '/' . $filename), format_string('@filename exists.', array('@filename' => $filename))); + $this->assertTrue(file_exists(\Drupal::root() . '/' . $filename), format_string('@filename exists.', array('@filename' => $filename))); } } // Now scan the directories and check that the files take precedence as // expected. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(\Drupal::root()); $listing->setProfileDirectories(array('core/profiles/testing')); $files = $listing->scan('module'); foreach ($expected_directories as $module => $directories) { diff --git a/core/modules/system/src/Tests/FileTransfer/FileTransferTest.php b/core/modules/system/src/Tests/FileTransfer/FileTransferTest.php index ef7a43a..07ce6ad 100644 --- a/core/modules/system/src/Tests/FileTransfer/FileTransferTest.php +++ b/core/modules/system/src/Tests/FileTransfer/FileTransferTest.php @@ -25,7 +25,7 @@ class FileTransferTest extends WebTestBase { protected function setUp() { parent::setUp(); - $this->testConnection = TestFileTransfer::factory(DRUPAL_ROOT, array('hostname' => $this->hostname, 'username' => $this->username, 'password' => $this->password, 'port' => $this->port)); + $this->testConnection = TestFileTransfer::factory(\Drupal::root(), array('hostname' => $this->hostname, 'username' => $this->username, 'password' => $this->password, 'port' => $this->port)); } function _getFakeModuleFiles() { @@ -87,7 +87,7 @@ function testJail() { $gotit = TRUE; try { - $this->testConnection->copyDirectory($source, DRUPAL_ROOT . '/' . PublicStream::basePath()); + $this->testConnection->copyDirectory($source, \Drupal::root() . '/' . PublicStream::basePath()); } catch (FileTransferException $e) { $gotit = FALSE; diff --git a/core/modules/system/src/Tests/Installer/InstallerLanguageDirectionTest.php b/core/modules/system/src/Tests/Installer/InstallerLanguageDirectionTest.php index cd7bce5..0c183d8 100644 --- a/core/modules/system/src/Tests/Installer/InstallerLanguageDirectionTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerLanguageDirectionTest.php @@ -28,8 +28,8 @@ class InstallerLanguageDirectionTest extends InstallerTestBase { */ protected function setUpLanguage() { // Place a custom local translation in the translations directory. - mkdir(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); - file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.ar.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Arabic\""); + mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); + file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.ar.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Arabic\""); parent::setUpLanguage(); // After selecting a different language than English, all following screens diff --git a/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php b/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php index 4c74ddc..ce573ba 100644 --- a/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php @@ -21,8 +21,8 @@ class InstallerLanguagePageTest extends InstallerTestBase { */ protected function setUpLanguage() { // Place a custom local translation in the translations directory. - mkdir(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); - touch(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po'); + mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); + touch(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po'); // Check that all predefined languages show up with their native names. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); diff --git a/core/modules/system/src/Tests/Installer/InstallerTest.php b/core/modules/system/src/Tests/Installer/InstallerTest.php index 760a942..6d48123 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTest.php @@ -26,7 +26,7 @@ public function testInstaller() { $this->assertText($this->root_user->getUsername()); // Verify that the confirmation message appears. - require_once DRUPAL_ROOT . '/core/includes/install.inc'; + require_once \Drupal::root() . '/core/includes/install.inc'; $this->assertRaw(t('Congratulations, you installed @drupal!', array( '@drupal' => drupal_install_profile_distribution_name(), ))); diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php index abecc2a..fb0a236 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php @@ -30,8 +30,8 @@ class InstallerTranslationTest extends InstallerTestBase { */ protected function setUpLanguage() { // Place a custom local translation in the translations directory. - mkdir(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); - file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue German\""); + mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); + file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue German\""); parent::setUpLanguage(); // After selecting a different language than English, all following screens diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationVersionUnitTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationVersionUnitTest.php index 882af17..c458716 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationVersionUnitTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationVersionUnitTest.php @@ -19,7 +19,7 @@ class InstallerTranslationVersionUnitTest extends DrupalUnitTestBase { protected function setUp() { parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; + require_once \Drupal::root() . '/core/includes/install.core.inc'; } /** diff --git a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php index 166f3ff..bad4c2f 100644 --- a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php +++ b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php @@ -59,7 +59,7 @@ public function testGetOverride() { $this->setSettings('test', array('directory' => NULL)); $php = PhpStorageFactory::get('test'); $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.'); - $this->assertIdentical(DRUPAL_ROOT . '/' . PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.'); + $this->assertIdentical(\Drupal::root() . '/' . PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.'); // Test that a default storage class is set if it's empty. $this->setSettings('test', array('class' => NULL)); diff --git a/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php index 101dee6..6cca8f5 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php @@ -59,7 +59,7 @@ protected function setUp() { ), ); - $base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src'; + $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory)); $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces); diff --git a/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php index eb5285e..890329c 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php @@ -35,7 +35,7 @@ protected function setUp() { ), ); - $base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src'; + $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $root_namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory)); $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); diff --git a/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php index 92a73f3..39e7caf 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php @@ -73,7 +73,7 @@ protected function setUp() { ), ); - $base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src'; + $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory)); $this->discovery = new AnnotatedClassDiscovery('', $namespaces); diff --git a/core/modules/system/src/Tests/Plugin/PluginTestBase.php b/core/modules/system/src/Tests/Plugin/PluginTestBase.php index 0285312..618c4ef 100644 --- a/core/modules/system/src/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/src/Tests/Plugin/PluginTestBase.php @@ -47,7 +47,7 @@ protected function setUp() { // as derivatives and ReflectionFactory. $this->testPluginManager = new TestPluginManager(); $this->mockBlockManager = new MockBlockManager(); - $module_handler = new ModuleHandler(array(), $this->container->get('kernel'), new MemoryBackend('plugin'), $this->container->get('event_dispatcher')); + $module_handler = new ModuleHandler(\Drupal::root(), array(), $this->container->get('kernel'), new MemoryBackend('plugin')); $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler); // The expected plugin definitions within each manager. Several tests assert diff --git a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php index 2d53082..f7691bf 100644 --- a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php +++ b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorCurrentIntegrationTest.php @@ -44,7 +44,7 @@ public function testProcessOutbound() { // Test request with subdir on homepage. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir', 'GET', [], [], [], $server); @@ -58,7 +58,7 @@ public function testProcessOutbound() { // Test request with subdir on other page. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server); @@ -72,7 +72,7 @@ public function testProcessOutbound() { // Test request without subdir on the homepage. $server = [ 'SCRIPT_NAME' => '/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/', 'GET', [], [], [], $server); @@ -86,7 +86,7 @@ public function testProcessOutbound() { // Test request without subdir on other page. $server = [ 'SCRIPT_NAME' => '/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/node/add', 'GET', [], [], [], $server); diff --git a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorNoneIntegrationTest.php b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorNoneIntegrationTest.php index 1089498..6a3ca05 100644 --- a/core/modules/system/src/Tests/RouteProcessor/RouteProcessorNoneIntegrationTest.php +++ b/core/modules/system/src/Tests/RouteProcessor/RouteProcessorNoneIntegrationTest.php @@ -44,7 +44,7 @@ public function testProcessOutbound() { // Test request with subdir on homepage. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir', 'GET', [], [], [], $server); @@ -59,7 +59,7 @@ public function testProcessOutbound() { // Test request with subdir on other page. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server); @@ -74,7 +74,7 @@ public function testProcessOutbound() { // Test request without subdir on the homepage. $server = [ 'SCRIPT_NAME' => '/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/', 'GET', [], [], [], $server); @@ -89,7 +89,7 @@ public function testProcessOutbound() { // Test request without subdir on other page. $server = [ 'SCRIPT_NAME' => '/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/node/add', 'GET', [], [], [], $server); diff --git a/core/modules/system/src/Tests/System/ErrorHandlerTest.php b/core/modules/system/src/Tests/System/ErrorHandlerTest.php index 69f1760..30a77b8 100644 --- a/core/modules/system/src/Tests/System/ErrorHandlerTest.php +++ b/core/modules/system/src/Tests/System/ErrorHandlerTest.php @@ -121,7 +121,7 @@ function testExceptionHandler() { // The exceptions are expected. Do not interpret them as a test failure. // Not using File API; a potential error must trigger a PHP warning. - unlink(DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'); + unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); } /** diff --git a/core/modules/system/src/Tests/System/HtaccessTest.php b/core/modules/system/src/Tests/System/HtaccessTest.php index 29f133d..3e8f36d 100644 --- a/core/modules/system/src/Tests/System/HtaccessTest.php +++ b/core/modules/system/src/Tests/System/HtaccessTest.php @@ -33,7 +33,7 @@ public function testYamlFileAccess() { * Path to file. Without leading slash. */ protected function assertNoFileAccess($path) { - $this->assertTrue(file_exists(DRUPAL_ROOT . '/' . $path)); + $this->assertTrue(file_exists(\Drupal::root() . '/' . $path)); $this->drupalGet($path); $this->assertResponse(403); } diff --git a/core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php b/core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php index f9ceb3a..3615c43 100644 --- a/core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php +++ b/core/modules/system/src/Tests/System/IgnoreReplicaSubscriberTest.php @@ -32,7 +32,7 @@ function testSystemInitIgnoresSecondaries() { Database::addConnectionInfo('default', 'replica', $connection_info['default']); db_ignore_replica(); - $class_loader = require DRUPAL_ROOT . '/core/vendor/autoload.php'; + $class_loader = require \Drupal::root() . '/core/vendor/autoload.php'; $kernel = new DrupalKernel('testing', $class_loader, FALSE); $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST); $subscriber = new ReplicaDatabaseIgnoreSubscriber(); diff --git a/core/modules/system/src/Tests/System/SettingsRewriteTest.php b/core/modules/system/src/Tests/System/SettingsRewriteTest.php index 741f92c..70b4043 100644 --- a/core/modules/system/src/Tests/System/SettingsRewriteTest.php +++ b/core/modules/system/src/Tests/System/SettingsRewriteTest.php @@ -20,7 +20,7 @@ class SettingsRewriteTest extends KernelTestBase { * Tests the drupal_rewrite_settings() function. */ function testDrupalRewriteSettings() { - include_once DRUPAL_ROOT . '/core/includes/install.inc'; + include_once \Drupal::root() . '/core/includes/install.inc'; $tests = array( array( 'original' => '$no_index_value_scalar = TRUE;', @@ -100,9 +100,9 @@ function testDrupalRewriteSettings() { ); foreach ($tests as $test) { $filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php'; - file_put_contents(DRUPAL_ROOT . '/' . $filename, "assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "assertEqual(file_get_contents(DRUPAL_ROOT . '/' . $filename), "assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "siteDirectory . '/error.log'); + unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); parent::tearDown(); } diff --git a/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php index 8454fe9..001f65b 100644 --- a/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/src/Tests/Theme/EntityFilteringThemeTest.php @@ -79,7 +79,7 @@ protected function setUp() { parent::setUp(); // Install all available non-testing themes. - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(\Drupal::root()); $this->themes = $listing->scan('theme', FALSE); \Drupal::service('theme_handler')->install(array_keys($this->themes)); diff --git a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php index 9275922..299a96b 100644 --- a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php @@ -38,7 +38,7 @@ protected function setUp() { $this->installConfig(array('system')); if (!isset($this->availableThemes)) { - $discovery = new ExtensionDiscovery(); + $discovery = new ExtensionDiscovery(\Drupal::root()); $this->availableThemes = $discovery->scan('theme'); } } diff --git a/core/modules/system/src/Tests/TypedData/TypedDataTest.php b/core/modules/system/src/Tests/TypedData/TypedDataTest.php index 4185c17..e1dcc4d 100644 --- a/core/modules/system/src/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/src/Tests/TypedData/TypedDataTest.php @@ -244,7 +244,7 @@ public function testGetAndSet() { $files = array(); for ($i = 0; $i < 3; $i++){ $path = "public://example_$i.png"; - file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', $path); + file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', $path); $image = entity_create('file', array('uri' => $path)); $image->save(); $files[] = $image; diff --git a/core/modules/system/src/Tests/Update/DependencyHookInvocationTest.php b/core/modules/system/src/Tests/Update/DependencyHookInvocationTest.php index f75190a..1dd0bef 100644 --- a/core/modules/system/src/Tests/Update/DependencyHookInvocationTest.php +++ b/core/modules/system/src/Tests/Update/DependencyHookInvocationTest.php @@ -26,7 +26,7 @@ class DependencyHookInvocationTest extends WebTestBase { protected function setUp() { parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once \Drupal::root() . '/core/includes/update.inc'; } /** diff --git a/core/modules/system/src/Tests/Update/DependencyMissingTest.php b/core/modules/system/src/Tests/Update/DependencyMissingTest.php index 7c31851..70cd56b 100644 --- a/core/modules/system/src/Tests/Update/DependencyMissingTest.php +++ b/core/modules/system/src/Tests/Update/DependencyMissingTest.php @@ -27,7 +27,7 @@ protected function setUp() { // Only install update_test_2.module, even though its updates have a // dependency on update_test_3.module. parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once \Drupal::root() . '/core/includes/update.inc'; } function testMissingUpdate() { diff --git a/core/modules/system/src/Tests/Update/DependencyOrderingTest.php b/core/modules/system/src/Tests/Update/DependencyOrderingTest.php index 4bf270a..1360c6d 100644 --- a/core/modules/system/src/Tests/Update/DependencyOrderingTest.php +++ b/core/modules/system/src/Tests/Update/DependencyOrderingTest.php @@ -25,7 +25,7 @@ class DependencyOrderingTest extends WebTestBase { protected function setUp() { parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once \Drupal::root() . '/core/includes/update.inc'; } /** diff --git a/core/modules/system/src/Tests/Update/InvalidUpdateHookTest.php b/core/modules/system/src/Tests/Update/InvalidUpdateHookTest.php index b5ea8fc..228d62c 100644 --- a/core/modules/system/src/Tests/Update/InvalidUpdateHookTest.php +++ b/core/modules/system/src/Tests/Update/InvalidUpdateHookTest.php @@ -41,7 +41,7 @@ class InvalidUpdateHookTest extends WebTestBase { protected function setUp() { parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once \Drupal::root() . '/core/includes/update.inc'; $this->update_url = $GLOBALS['base_url'] . '/update.php'; $this->update_user = $this->drupalCreateUser(array('administer software updates')); diff --git a/core/modules/system/src/Tests/Update/UpdatesWith7xTest.php b/core/modules/system/src/Tests/Update/UpdatesWith7xTest.php index b6c215d..09daad3 100644 --- a/core/modules/system/src/Tests/Update/UpdatesWith7xTest.php +++ b/core/modules/system/src/Tests/Update/UpdatesWith7xTest.php @@ -36,7 +36,7 @@ class UpdatesWith7xTest extends WebTestBase { protected function setUp() { parent::setUp(); - require_once DRUPAL_ROOT . '/core/includes/update.inc'; + require_once \Drupal::root() . '/core/includes/update.inc'; $this->update_url = $GLOBALS['base_url'] . '/update.php'; $this->update_user = $this->drupalCreateUser(array('administer software updates')); } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 0d41bba..3d7bdf9 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -770,7 +770,7 @@ function system_get_info($type, $name = NULL) { * An associative array of module information. */ function _system_rebuild_module_data() { - $listing = new ExtensionDiscovery(); + $listing = new ExtensionDiscovery(\Drupal::root()); // Find modules $modules = $listing->scan('module'); diff --git a/core/modules/system/tests/src/Unit/Menu/SystemLocalTasksTest.php b/core/modules/system/tests/src/Unit/Menu/SystemLocalTasksTest.php index 6d98ebd..e1b48e9 100644 --- a/core/modules/system/tests/src/Unit/Menu/SystemLocalTasksTest.php +++ b/core/modules/system/tests/src/Unit/Menu/SystemLocalTasksTest.php @@ -36,7 +36,7 @@ protected function setUp() { $this->themeHandler = $this->getMock('Drupal\Core\Extension\ThemeHandlerInterface'); - $theme = new Extension('theme', DRUPAL_ROOT . '/core/themes/bartik', 'bartik.info.yml'); + $theme = new Extension($this->root, 'theme', '/core/themes/bartik', 'bartik.info.yml'); $theme->status = 1; $theme->info = array('name' => 'bartik'); $this->themeHandler->expects($this->any()) diff --git a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php index b167840..f265ec2 100644 --- a/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php +++ b/core/modules/taxonomy/src/Tests/VocabularyCrudTest.php @@ -193,7 +193,7 @@ function testUninstallReinstall() { ); entity_create('field_config', $field_definition)->save(); - require_once DRUPAL_ROOT . '/core/includes/install.inc'; + require_once \Drupal::root() . '/core/includes/install.inc'; $this->container->get('module_handler')->uninstall(array('taxonomy')); \Drupal::moduleHandler()->install(array('taxonomy')); diff --git a/core/modules/update/src/Form/UpdateManagerInstall.php b/core/modules/update/src/Form/UpdateManagerInstall.php index 3198a28..2b9467a 100644 --- a/core/modules/update/src/Form/UpdateManagerInstall.php +++ b/core/modules/update/src/Form/UpdateManagerInstall.php @@ -27,12 +27,22 @@ class UpdateManagerInstall extends FormBase { protected $moduleHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * Constructs a new UpdateManagerInstall. * + * @param string $root + * The app root. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(ModuleHandlerInterface $module_handler) { + public function __construct($root, ModuleHandlerInterface $module_handler) { + $this->root = $root; $this->moduleHandler = $module_handler; } @@ -48,6 +58,7 @@ public function getFormID() { */ public static function create(ContainerInterface $container) { return new static( + $container->getParameter('app.root'), $container->get('module_handler') ); } @@ -207,7 +218,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // update_authorize_run_install() directly. if (fileowner($project_real_location) == fileowner(conf_path())) { $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); - $filetransfer = new Local(DRUPAL_ROOT); + $filetransfer = new Local($this->root); call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments)); } diff --git a/core/modules/update/src/Form/UpdateReady.php b/core/modules/update/src/Form/UpdateReady.php index 7f4c5da..3afdf3d 100644 --- a/core/modules/update/src/Form/UpdateReady.php +++ b/core/modules/update/src/Form/UpdateReady.php @@ -21,6 +21,13 @@ class UpdateReady extends FormBase { /** + * The app root. + * + * @var string + */ + protected $root; + + /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface @@ -37,12 +44,15 @@ class UpdateReady extends FormBase { /** * Constructs a new UpdateReady object. * + * @param string $root + * The app root. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The object that manages enabled modules in a Drupal installation. * @param \Drupal\Core\State\StateInterface $state * The state key value store. */ - public function __construct(ModuleHandlerInterface $module_handler, StateInterface $state) { + public function __construct($root, ModuleHandlerInterface $module_handler, StateInterface $state) { + $this->root = $root; $this->moduleHandler = $module_handler; $this->state = $state; } @@ -59,6 +69,7 @@ public function getFormID() { */ public static function create(ContainerInterface $container) { return new static( + $container->getParameter('app.root'), $container->get('module_handler'), $container->get('state') ); @@ -133,7 +144,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // and invoke update_authorize_run_update() directly. if (fileowner($project_real_location) == fileowner(conf_path())) { $this->moduleHandler->loadInclude('update', 'inc', 'update.authorize'); - $filetransfer = new Local(DRUPAL_ROOT); + $filetransfer = new Local($this->root); update_authorize_run_update($filetransfer, $updates); } // Otherwise, go through the regular workflow to prompt for FTP/SSH diff --git a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php index e242a07..33c094c 100644 --- a/core/modules/user/src/Tests/UserAccountFormFieldsTest.php +++ b/core/modules/user/src/Tests/UserAccountFormFieldsTest.php @@ -29,8 +29,8 @@ class UserAccountFormFieldsTest extends DrupalUnitTestBase { * Tests the root user account form section in the "Configure site" form. */ function testInstallConfigureForm() { - require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; - require_once DRUPAL_ROOT . '/core/includes/install.inc'; + require_once \Drupal::root() . '/core/includes/install.core.inc'; + require_once \Drupal::root() . '/core/includes/install.inc'; $install_state = install_state_defaults(); $form_state = new FormState(); $form_state->addBuildInfo('args', [&$install_state]); diff --git a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php index cbe28dd..1180846 100644 --- a/core/modules/user/tests/src/Unit/PermissionHandlerTest.php +++ b/core/modules/user/tests/src/Unit/PermissionHandlerTest.php @@ -55,6 +55,8 @@ class PermissionHandlerTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $this->stringTranslation = $this->getStringTranslationStub(); $this->controllerResolver = $this->getMock('Drupal\Core\Controller\ControllerResolverInterface'); } @@ -71,7 +73,7 @@ protected function setUp() { * The extension object. */ protected function mockModuleExtension($module, $name) { - $extension = new Extension($module, "modules/$module"); + $extension = new Extension($this->root, $module, "modules/$module"); $extension->info['name'] = $name; return $extension; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index c216872..8a9bb0f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -181,7 +181,7 @@ function views_theme($existing, $type, $theme, $path) { // Whenever we have a theme file, we include it directly so we can // auto-detect the theme function. if (isset($def['theme_file'])) { - $include = DRUPAL_ROOT . '/' . $module_dir . '/' . $def['theme_file']; + $include = \Drupal::root() . '/' . $module_dir. '/' . $def['theme_file']; if (is_file($include)) { require_once $include; } diff --git a/core/rebuild.php b/core/rebuild.php index c915aff..be3e603 100644 --- a/core/rebuild.php +++ b/core/rebuild.php @@ -25,7 +25,7 @@ // Manually resemble early bootstrap of DrupalKernel::boot(). require_once __DIR__ . '/includes/bootstrap.inc'; DrupalKernel::bootEnvironment(); -Settings::initialize(DrupalKernel::findSitePath($request), $autoloader); +Settings::initialize(dirname(__DIR__), DrupalKernel::findSitePath($request), $autoloader); if (Settings::get('rebuild_access', FALSE) || ($request->get('token') && $request->get('timestamp') && diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index f1a7146..49830f7 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -31,6 +31,13 @@ class LibraryDiscoveryParserTest extends UnitTestCase { /** + * The app root. + * + * @var string + */ + protected $root; + + /** * The tested library provider. * * @var \Drupal\Core\Asset\LibraryDiscoveryParser|\Drupal\Tests\Core\Asset\TestLibraryDiscoveryParser @@ -62,8 +69,10 @@ class LibraryDiscoveryParserTest extends UnitTestCase { * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); - $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->moduleHandler); + $this->libraryDiscoveryParser = new TestLibraryDiscoveryParser($this->root, $this->moduleHandler); } /** @@ -78,7 +87,7 @@ public function testBuildByExtensionSimple() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'example_module', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('example_module', 'example'); @@ -105,7 +114,7 @@ public function testBuildByExtensionWithTheme() { ->will($this->returnValue(FALSE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('theme', 'example_theme', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('example_theme'); @@ -129,7 +138,7 @@ public function testBuildByExtensionWithMissingLibraryFile() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files_not_existing'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'example_module', $path); $this->assertSame($this->libraryDiscoveryParser->buildByExtension('example_module'), array()); @@ -149,7 +158,7 @@ public function testInvalidLibrariesFile() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'invalid_file', $path); $this->libraryDiscoveryParser->buildByExtension('invalid_file'); @@ -170,7 +179,7 @@ public function testBuildByExtensionWithMissingInformation() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'example_module_missing_information', $path); $this->libraryDiscoveryParser->buildByExtension('example_module_missing_information'); @@ -188,7 +197,7 @@ public function testExternalLibraries() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'external', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('external', 'example_external'); @@ -210,7 +219,7 @@ public function testDefaultCssWeights() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'css_weights', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('css_weights'); @@ -250,7 +259,7 @@ public function testJsWithPositiveWeight() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'js_positive_weight', $path); $this->libraryDiscoveryParser->buildByExtension('js_positive_weight'); @@ -268,7 +277,7 @@ public function testLibraryWithCssJsSetting() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'css_js_settings', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('css_js_settings'); @@ -299,7 +308,7 @@ public function testLibraryWithDependencies() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'dependencies', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('dependencies'); @@ -322,7 +331,7 @@ public function testLibraryWithDataTypes() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'data_types', $path); $this->libraryDiscoveryParser->setFileValidUri('public://test.css', TRUE); @@ -354,7 +363,7 @@ public function testLibraryWithJavaScript() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'js', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('js'); @@ -379,7 +388,7 @@ public function testLibraryThirdPartyWithMissingLicense() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'licenses_missing_information', $path); $this->libraryDiscoveryParser->buildByExtension('licenses_missing_information'); @@ -397,7 +406,7 @@ public function testLibraryWithLicenses() { ->will($this->returnValue(TRUE)); $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen(DRUPAL_ROOT) + 1); + $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', 'licenses', $path); $libraries = $this->libraryDiscoveryParser->buildByExtension('licenses'); diff --git a/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php b/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php index a4bb8b1..e65c651 100644 --- a/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/DefaultConfigTest.php @@ -28,7 +28,7 @@ class DefaultConfigTest extends UnitTestCase { * would not exist. Installation hooks would never be executed. */ public function testConfigIsEmpty() { - $config = Yaml::parse(file_get_contents(DRUPAL_ROOT . '/core/config/install/core.extension.yml')); + $config = Yaml::parse(file_get_contents($this->root . '/core/config/install/core.extension.yml')); $expected = array( 'module' => array(), 'theme' => array(), diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php index 493e201..10b8890 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php @@ -39,14 +39,24 @@ class ModuleHandlerTest extends UnitTestCase { protected $moduleHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * {@inheritdoc} * * @covers ::__construct */ protected function setUp() { + parent::setUp(); + $this->kernel = $this->getMock('Drupal\Core\DrupalKernelInterface'); + $this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); - $this->moduleHandler = new ModuleHandler(array( + $this->moduleHandler = new ModuleHandler($this->root, array( 'module_handler_test' => array( 'type' => 'module', 'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', @@ -97,6 +107,7 @@ public function testLoadAllModules() { public function testModuleReloading() { $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( + $this->root, array( 'module_handler_test' => array( 'type' => 'module', @@ -141,7 +152,7 @@ public function testIsLoaded() { */ public function testGetModuleList() { $this->assertEquals($this->moduleHandler->getModuleList(), array( - 'module_handler_test' => new Extension('module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'), + 'module_handler_test' => new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'), )); } @@ -151,7 +162,7 @@ public function testGetModuleList() { * @covers ::getModule */ public function testGetModuleWithExistingModule() { - $this->assertEquals($this->moduleHandler->getModule('module_handler_test'), new Extension('module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module')); + $this->assertEquals($this->moduleHandler->getModule('module_handler_test'), new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module')); } /** @@ -171,7 +182,7 @@ public function testGetModuleWithNonExistingModule() { public function testSetModuleList() { $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - array(), $this->kernel, $this->cacheBackend + $this->root, array(), $this->kernel, $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); @@ -199,7 +210,7 @@ public function testAddModule() { $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - array(), $this->kernel, $this->cacheBackend + $this->root, array(), $this->kernel, $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); @@ -221,7 +232,7 @@ public function testAddProfile() { $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - array(), $this->kernel, $this->cacheBackend + $this->root, array(), $this->kernel, $this->cacheBackend )) ->setMethods(array('resetImplementations')) ->getMock(); @@ -251,6 +262,7 @@ public function testLoadAllIncludes() { $this->assertTrue(true); $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( + $this->root, array( 'module_handler_test' => array( 'type' => 'module', @@ -332,7 +344,7 @@ public function testCachedGetImplementations() { // Ensure buildImplementationInfo doesn't get called and that we work off cached results. $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - array( + $this->root, array( 'module_handler_test' => array( 'type' => 'module', 'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', @@ -367,7 +379,7 @@ public function testCachedGetImplementationsMissingMethod() { // Ensure buildImplementationInfo doesn't get called and that we work off cached results. $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler') ->setConstructorArgs(array( - array( + $this->root, array( 'module_handler_test' => array( 'type' => 'module', 'pathname' => 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', @@ -512,6 +524,6 @@ public function dependencyProvider() { public function testGetModuleDirectories() { $this->moduleHandler->setModuleList(array()); $this->moduleHandler->addModule('module', 'place'); - $this->assertEquals(array('module' => DRUPAL_ROOT . '/place'), $this->moduleHandler->getModuleDirectories()); + $this->assertEquals(array('module' => $this->root . '/place'), $this->moduleHandler->getModuleDirectories()); } } diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 22b1f25..8ccfb73 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -92,9 +92,18 @@ class ThemeHandlerTest extends UnitTestCase { protected $themeHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $this->configFactory = $this->getConfigFactoryStub(array( 'core.extension' => array( 'module' => array(), @@ -117,7 +126,7 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); $logger = $this->getMock('Psr\Log\LoggerInterface'); - $this->themeHandler = new TestThemeHandler($this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery); + $this->themeHandler = new TestThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery); $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->getContainerWithCacheBins($cache_backend); @@ -133,17 +142,17 @@ public function testRebuildThemeData() { ->method('scan') ->with('theme') ->will($this->returnValue(array( - 'seven' => new Extension('theme', DRUPAL_ROOT . '/core/themes/seven/seven.info.yml', 'seven.theme'), + 'seven' => new Extension($this->root, 'theme', $this->root . '/core/themes/seven/seven.info.yml', 'seven.theme'), ))); $this->extensionDiscovery->expects($this->at(1)) ->method('scan') ->with('theme_engine') ->will($this->returnValue(array( - 'twig' => new Extension('theme_engine', DRUPAL_ROOT . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'), + 'twig' => new Extension($this->root, 'theme_engine', $this->root . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'), ))); $this->infoParser->expects($this->once()) ->method('parse') - ->with(DRUPAL_ROOT . '/core/themes/seven/seven.info.yml') + ->with($this->root . '/core/themes/seven/seven.info.yml') ->will($this->returnCallback(function ($file) { $info_parser = new InfoParser(); return $info_parser->parse($file); @@ -162,9 +171,9 @@ public function testRebuildThemeData() { // Ensure some basic properties. $this->assertInstanceOf('Drupal\Core\Extension\Extension', $info); $this->assertEquals('seven', $info->getName()); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/seven/seven.info.yml', $info->getPathname()); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/seven/seven.theme', $info->getExtensionPathname()); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine', $info->owner); + $this->assertEquals($this->root . '/core/themes/seven/seven.info.yml', $info->getPathname()); + $this->assertEquals($this->root . '/core/themes/seven/seven.theme', $info->getExtensionPathname()); + $this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info->owner); $this->assertEquals('twig', $info->prefix); $this->assertEquals('twig', $info->info['engine']); @@ -173,40 +182,40 @@ public function testRebuildThemeData() { // Ensure that the css paths are set with the proper prefix. $this->assertEquals(array( 'screen' => array( - 'css/base/elements.css' => DRUPAL_ROOT . '/core/themes/seven/css/base/elements.css', - 'css/base/typography.css' => DRUPAL_ROOT . '/core/themes/seven/css/base/typography.css', - 'css/components/admin-list.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/admin-list.css', - 'css/components/admin-options.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/admin-options.css', - 'css/components/admin-panel.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/admin-panel.css', - 'css/components/block-recent-content.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/block-recent-content.css', - 'css/components/content-header.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/content-header.css', - 'css/components/breadcrumb.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/breadcrumb.css', - 'css/components/buttons.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/buttons.css', - 'css/components/buttons.theme.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/buttons.theme.css', - 'css/components/comments.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/comments.css', - 'css/components/messages.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/messages.css', - 'css/components/dropbutton.component.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/dropbutton.component.css', - 'css/components/entity-meta.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/entity-meta.css', - 'css/components/field-ui.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/field-ui.css', - 'css/components/form.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/form.css', - 'css/components/help.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/help.css', - 'css/components/menus-and-lists.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/menus-and-lists.css', - 'css/components/modules-page.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/modules-page.css', - 'css/components/node.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/node.css', - 'css/components/page-title.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/page-title.css', - 'css/components/pager.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/pager.css', - 'css/components/skip-link.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/skip-link.css', - 'css/components/tables.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/tables.css', - 'css/components/tabs.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/tabs.css', - 'css/components/tour.theme.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/tour.theme.css', - 'css/components/update-status.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/update-status.css', - 'css/components/views-ui.css' => DRUPAL_ROOT . '/core/themes/seven/css/components/views-ui.css', - 'css/layout/layout.css' => DRUPAL_ROOT . '/core/themes/seven/css/layout/layout.css', - 'css/layout/node-add.css' => DRUPAL_ROOT . '/core/themes/seven/css/layout/node-add.css', - 'css/theme/appearance-page.css' => DRUPAL_ROOT . '/core/themes/seven/css/theme/appearance-page.css', + 'css/base/elements.css' => $this->root . '/core/themes/seven/css/base/elements.css', + 'css/base/typography.css' => $this->root . '/core/themes/seven/css/base/typography.css', + 'css/components/admin-list.css' => $this->root . '/core/themes/seven/css/components/admin-list.css', + 'css/components/admin-options.css' => $this->root . '/core/themes/seven/css/components/admin-options.css', + 'css/components/admin-panel.css' => $this->root . '/core/themes/seven/css/components/admin-panel.css', + 'css/components/block-recent-content.css' => $this->root . '/core/themes/seven/css/components/block-recent-content.css', + 'css/components/content-header.css' => $this->root . '/core/themes/seven/css/components/content-header.css', + 'css/components/breadcrumb.css' => $this->root . '/core/themes/seven/css/components/breadcrumb.css', + 'css/components/buttons.css' => $this->root . '/core/themes/seven/css/components/buttons.css', + 'css/components/buttons.theme.css' => $this->root . '/core/themes/seven/css/components/buttons.theme.css', + 'css/components/comments.css' => $this->root . '/core/themes/seven/css/components/comments.css', + 'css/components/messages.css' => $this->root . '/core/themes/seven/css/components/messages.css', + 'css/components/dropbutton.component.css' => $this->root . '/core/themes/seven/css/components/dropbutton.component.css', + 'css/components/entity-meta.css' => $this->root . '/core/themes/seven/css/components/entity-meta.css', + 'css/components/field-ui.css' => $this->root . '/core/themes/seven/css/components/field-ui.css', + 'css/components/form.css' => $this->root . '/core/themes/seven/css/components/form.css', + 'css/components/help.css' => $this->root . '/core/themes/seven/css/components/help.css', + 'css/components/menus-and-lists.css' => $this->root . '/core/themes/seven/css/components/menus-and-lists.css', + 'css/components/modules-page.css' => $this->root . '/core/themes/seven/css/components/modules-page.css', + 'css/components/node.css' => $this->root . '/core/themes/seven/css/components/node.css', + 'css/components/page-title.css' => $this->root . '/core/themes/seven/css/components/page-title.css', + 'css/components/pager.css' => $this->root . '/core/themes/seven/css/components/pager.css', + 'css/components/skip-link.css' => $this->root . '/core/themes/seven/css/components/skip-link.css', + 'css/components/tables.css' => $this->root . '/core/themes/seven/css/components/tables.css', + 'css/components/tabs.css' => $this->root . '/core/themes/seven/css/components/tabs.css', + 'css/components/tour.theme.css' => $this->root . '/core/themes/seven/css/components/tour.theme.css', + 'css/components/update-status.css' => $this->root . '/core/themes/seven/css/components/update-status.css', + 'css/components/views-ui.css' => $this->root . '/core/themes/seven/css/components/views-ui.css', + 'css/layout/layout.css' => $this->root . '/core/themes/seven/css/layout/layout.css', + 'css/layout/node-add.css' => $this->root . '/core/themes/seven/css/layout/node-add.css', + 'css/theme/appearance-page.css' => $this->root . '/core/themes/seven/css/theme/appearance-page.css', ), ), $info->info['stylesheets']); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/seven/screenshot.png', $info->info['screenshot']); + $this->assertEquals($this->root . '/core/themes/seven/screenshot.png', $info->info['screenshot']); } /** @@ -217,25 +226,25 @@ public function testRebuildThemeDataWithThemeParents() { ->method('scan') ->with('theme') ->will($this->returnValue(array( - 'test_subtheme' => new Extension('theme', DRUPAL_ROOT . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'test_subtheme.info.yml'), - 'test_basetheme' => new Extension('theme', DRUPAL_ROOT . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'test_basetheme.info.yml'), + 'test_subtheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'test_subtheme.info.yml'), + 'test_basetheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'test_basetheme.info.yml'), ))); $this->extensionDiscovery->expects($this->at(1)) ->method('scan') ->with('theme_engine') ->will($this->returnValue(array( - 'twig' => new Extension('theme_engine', DRUPAL_ROOT . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'), + 'twig' => new Extension($this->root, 'theme_engine', $this->root . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'), ))); $this->infoParser->expects($this->at(0)) ->method('parse') - ->with(DRUPAL_ROOT . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml') + ->with($this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml') ->will($this->returnCallback(function ($file) { $info_parser = new InfoParser(); return $info_parser->parse($file); })); $this->infoParser->expects($this->at(1)) ->method('parse') - ->with(DRUPAL_ROOT . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml') + ->with($this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml') ->will($this->returnCallback(function ($file) { $info_parser = new InfoParser(); return $info_parser->parse($file); @@ -260,9 +269,9 @@ public function testRebuildThemeDataWithThemeParents() { $info_subtheme->info['base theme'] = 'test_basetheme'; $info_basetheme->sub_themes = array('test_subtheme'); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine', $info_basetheme->owner); + $this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_basetheme->owner); $this->assertEquals('twig', $info_basetheme->prefix); - $this->assertEquals(DRUPAL_ROOT . '/core/themes/engines/twig/twig.engine', $info_subtheme->owner); + $this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_subtheme->owner); $this->assertEquals('twig', $info_subtheme->prefix); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php index 41d76df..138309e 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php @@ -125,8 +125,7 @@ protected function setUp() { $this->requestStack = $this->getMock('\Symfony\Component\HttpFoundation\RequestStack'); $this->requestPolicy = $this->getMock('\Drupal\Core\PageCache\RequestPolicyInterface'); - - $this->formCache = new FormCache($this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy); + $this->formCache = new FormCache($this->root, $this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy); } /** @@ -511,8 +510,9 @@ public function testSetCacheImmutableForm() { // Rebuild the FormCache with a config factory that will return a config // object with the internal page cache enabled. $this->configFactory = $this->getConfigFactoryStub(['system.performance' => ['cache.page.use_internal' => TRUE]]); + $root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); $this->formCache = $this->getMockBuilder('Drupal\Core\Form\FormCache') - ->setConstructorArgs([$this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy]) + ->setConstructorArgs([$root, $this->keyValueExpirableFactory, $this->moduleHandler, $this->account, $this->csrfToken, $this->logger, $this->configFactory, $this->requestStack, $this->requestPolicy]) ->setMethods(['isPageCacheable']) ->getMock(); diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index 13eae9a..dbdf93b 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -133,6 +133,13 @@ */ protected $themeManager; + /** + * The app root. + * + * @var string + */ + protected $root; + protected function setUp() { $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -160,6 +167,7 @@ protected function setUp() { ->setConstructorArgs(array($this->requestStack, $this->urlGenerator)) ->setMethods(array('batchGet', 'drupalInstallationAttempted')) ->getMock(); + $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); $this->formBuilder = new TestFormBuilder($this->formValidator, $this->formSubmitter, $this->formCache, $this->moduleHandler, $this->eventDispatcher, $this->requestStack, $this->classResolver, $this->themeManager, $this->csrfToken, $this->kernel); $this->formBuilder->setCurrentUser($this->account); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php index a295e27..bb8f298 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskIntegrationTest.php @@ -23,6 +23,13 @@ abstract class LocalTaskIntegrationTest extends UnitTestCase { /** + * The app root. + * + * @var string + */ + protected $root; + + /** * A list of module directories used for YAML searching. * * @var array @@ -47,9 +54,12 @@ * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $container = new ContainerBuilder(); $config_factory = $this->getConfigFactoryStub(array()); $container->set('config.factory', $config_factory); + $container->setParameter('app.root', $this->root); \Drupal::setContainer($container); $this->container = $container; } @@ -142,7 +152,7 @@ protected function assertLocalTasks($route_name, $expected_tasks, $route_params $directory_list = array(); foreach ($this->directoryList as $key => $value) { - $directory_list[$key] = DRUPAL_ROOT . '/' . $value; + $directory_list[$key] = $this->root . '/' . $value; } $manager = $this->getLocalTaskManager($directory_list, $route_name, $route_params); diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index a4750ca..7767ff0 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -55,7 +55,7 @@ protected function setUp() { ); $this->namespaces = new \ArrayObject(); - $this->namespaces['Drupal\plugin_test'] = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src'; + $this->namespaces['Drupal\plugin_test'] = $this->root . '/core/modules/system/tests/modules/plugin_test/src'; } /** diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 7404372..ff14dae 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -293,7 +293,7 @@ public function testPathBasedURLGeneration() { // To reproduce the values install Drupal like that and use a debugger. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => $this->root . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir/' . $script_path, 'GET', [], [], [], $server); diff --git a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php index eb8881d..46dc5f6 100644 --- a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php @@ -46,9 +46,18 @@ class RegistryTest extends UnitTestCase { protected $moduleHandler; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); @@ -65,7 +74,7 @@ public function testGetRegistryForModule() { $this->registry->setBaseThemes(array()); // Include the module so that hook_theme can be called. - include_once DRUPAL_ROOT . '/core/modules/system/tests/modules/theme_test/theme_test.module'; + include_once $this->root . '/core/modules/system/tests/modules/theme_test/theme_test.module'; $this->moduleHandler->expects($this->once()) ->method('getImplementations') ->with('theme') @@ -96,7 +105,7 @@ public function testGetRegistryForModule() { } protected function setupTheme($theme_name = NULL) { - $this->registry = new TestRegistry($this->cache, $this->lock, $this->moduleHandler, $theme_name); + $this->registry = new TestRegistry($this->root, $this->cache, $this->lock, $this->moduleHandler, $theme_name); } } diff --git a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php index 03b3375..1790aef 100644 --- a/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/UnroutedUrlAssemblerTest.php @@ -97,7 +97,7 @@ public function testAssembleWithLocalUri($uri, array $options, $subdir, $expecte // To reproduce the values install Drupal like that and use a debugger. $server = [ 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => DRUPAL_ROOT . '/index.php', + 'SCRIPT_FILENAME' => $this->root . '/index.php', 'SERVER_NAME' => 'http://www.example.com', ]; $request = Request::create('/subdir'); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index d37a040..43748e8 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -27,6 +27,13 @@ protected $randomGenerator; /** + * The app root. + * + * @var string + */ + protected $root; + + /** * {@inheritdoc} */ protected function setUp() { @@ -34,6 +41,8 @@ protected function setUp() { // Ensure that an instantiated container in the global state of \Drupal from // a previous test does not leak into this test. \Drupal::setContainer(NULL); + + $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); } /** diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index e74dc24..76f745c 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -83,7 +83,6 @@ function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $l // Look into removing these later. define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); -define('DRUPAL_ROOT', realpath(__DIR__ . '/../../')); // Set sane locale settings, to ensure consistent string, dates, times and // numbers handling. diff --git a/core/themes/engines/phptemplate/phptemplate.engine b/core/themes/engines/phptemplate/phptemplate.engine index a4eee49..232f78d 100644 --- a/core/themes/engines/phptemplate/phptemplate.engine +++ b/core/themes/engines/phptemplate/phptemplate.engine @@ -51,7 +51,7 @@ function phptemplate_render_template($template_file, $variables) { ob_start(); // Include the template file - include DRUPAL_ROOT . '/' . $template_file; + include \Drupal::root() . '/' . $template_file; // End buffering and return its contents return ob_get_clean();