Issue #2928710 by borisson_, dawehner, idebr: Eliminate usages of \Drupal::root() in tests

merge-requests/1654/head
Nathaniel Catchpole 2018-06-07 21:55:18 +01:00
parent a26816d190
commit c00b97b2a5
45 changed files with 71 additions and 75 deletions

View File

@ -205,7 +205,7 @@ class BigPipeTest extends BrowserTestBase {
$this->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent: error occurred before then.'); $this->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent: error occurred before then.');
$this->assertNoRaw('</body>', 'Closing body tag absent: error occurred before then.'); $this->assertNoRaw('</body>', 'Closing body tag absent: error occurred before then.');
// The exception is expected. Do not interpret it as a test failure. // The exception is expected. Do not interpret it as a test failure.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); unlink($this->root . '/' . $this->siteDirectory . '/error.log');
} }
/** /**
@ -273,7 +273,7 @@ class BigPipeTest extends BrowserTestBase {
$this->assertRaw('You are not allowed to say llamas are not cool!'); $this->assertRaw('You are not allowed to say llamas are not cool!');
$this->assertNoRaw('</body>', 'Closing body tag absent: error occurred before then.'); $this->assertNoRaw('</body>', 'Closing body tag absent: error occurred before then.');
// The exception is expected. Do not interpret it as a test failure. // The exception is expected. Do not interpret it as a test failure.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); unlink($this->root . '/' . $this->siteDirectory . '/error.log');
} }
/** /**

View File

@ -112,7 +112,7 @@ class FieldTypePluginManagerTest extends FieldKernelTestBase {
* Enable all core modules. * Enable all core modules.
*/ */
protected function enableAllCoreModules() { protected function enableAllCoreModules() {
$listing = new ExtensionDiscovery(\Drupal::root()); $listing = new ExtensionDiscovery($this->root);
$module_list = $listing->scan('module', FALSE); $module_list = $listing->scan('module', FALSE);
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */ /** @var \Drupal\Core\Extension\ModuleHandlerInterface $module_handler */
$module_handler = $this->container->get('module_handler'); $module_handler = $this->container->get('module_handler');

View File

@ -30,7 +30,7 @@ trait FileMigrationTestTrait {
// Make sure we have a single trailing slash. // Make sure we have a single trailing slash.
$source = $migration->getSourceConfiguration(); $source = $migration->getSourceConfiguration();
$source['site_path'] = 'core/modules/simpletest'; $source['site_path'] = 'core/modules/simpletest';
$source['constants']['source_base_path'] = \Drupal::root() . '/'; $source['constants']['source_base_path'] = $this->root . '/';
$migration->set('source', $source); $migration->set('source', $source);
} }
} }

View File

@ -67,7 +67,7 @@ class ImageItemTest extends FieldKernelTestBase {
'file_extensions' => 'jpg', 'file_extensions' => 'jpg',
], ],
])->save(); ])->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create([ $this->image = File::create([
'uri' => 'public://example.jpg', 'uri' => 'public://example.jpg',
]); ]);
@ -100,7 +100,7 @@ class ImageItemTest extends FieldKernelTestBase {
$this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid()); $this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid());
// Make sure the computed entity reflects updates to the referenced file. // Make sure the computed entity reflects updates to the referenced file.
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg'); file_unmanaged_copy($this->root . '/core/misc/druplicon.png', 'public://example-2.jpg');
$image2 = File::create([ $image2 = File::create([
'uri' => 'public://example-2.jpg', 'uri' => 'public://example-2.jpg',
]); ]);

View File

@ -62,7 +62,7 @@ class ImageThemeFunctionTest extends KernelTestBase {
'field_name' => 'image_test', 'field_name' => 'image_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
])->save(); ])->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create([ $this->image = File::create([
'uri' => 'public://example.jpg', 'uri' => 'public://example.jpg',
]); ]);

View File

@ -135,7 +135,7 @@ class MediaRevisionTest extends MediaFunctionalTestBase {
$this->drupalGet('/media/add/image'); $this->drupalGet('/media/add/image');
$page = $this->getSession()->getPage(); $page = $this->getSession()->getPage();
$page->fillField('Name', 'Foobar'); $page->fillField('Name', 'Foobar');
$page->attachFileToField('Image', \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); $page->attachFileToField('Image', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
$page->pressButton('Save'); $page->pressButton('Save');
$assert->addressMatches('/^\/media\/[0-9]+$/'); $assert->addressMatches('/^\/media\/[0-9]+$/');

View File

@ -68,7 +68,7 @@ class MediaDisplayTest extends MediaJavascriptTestBase {
$this->drupalGet('media/add/image'); $this->drupalGet('media/add/image');
$image_media_name = 'Fantastic image asset!'; $image_media_name = 'Fantastic image asset!';
$page->fillField('name[0][value]', $image_media_name); $page->fillField('name[0][value]', $image_media_name);
$page->attachFileToField('files[field_media_image_0]', \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); $page->attachFileToField('files[field_media_image_0]', $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
$result = $assert_session->waitForButton('Remove'); $result = $assert_session->waitForButton('Remove');
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
$page->fillField('field_media_image[0][alt]', 'Image Alt Text 1'); $page->fillField('field_media_image[0][alt]', 'Image Alt Text 1');

View File

@ -46,7 +46,7 @@ class MediaSourceImageTest extends MediaSourceTestBase {
// Create a media item. // Create a media item.
$this->drupalGet("media/add/{$media_type_id}"); $this->drupalGet("media/add/{$media_type_id}");
$page->attachFileToField("files[{$source_field_id}_0]", \Drupal::root() . '/core/modules/media/tests/fixtures/example_1.jpeg'); $page->attachFileToField("files[{$source_field_id}_0]", $this->root . '/core/modules/media/tests/fixtures/example_1.jpeg');
$result = $assert_session->waitForButton('Remove'); $result = $assert_session->waitForButton('Remove');
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
$page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1'); $page->fillField("{$source_field_id}[0][alt]", 'Image Alt Text 1');

View File

@ -136,7 +136,7 @@ class StandardProfileTest extends BrowserTestBase {
$this->term->save(); $this->term->save();
// Create image. // Create image.
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy($this->root . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create(['uri' => 'public://example.jpg']); $this->image = File::create(['uri' => 'public://example.jpg']);
$this->image->save(); $this->image->save();

View File

@ -20,7 +20,7 @@ class SearchSimplifyTest extends SearchTestBase {
// their own lines). So the even-numbered lines should simplify to nothing, // 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 // and the odd-numbered lines we need to split into shorter chunks and
// verify that simplification doesn't lose any characters. // verify that simplification doesn't lose any characters.
$input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt'); $input = file_get_contents($this->root . '/core/modules/search/tests/UnicodeTest.txt');
$basestrings = explode(chr(10), $input); $basestrings = explode(chr(10), $input);
$strings = []; $strings = [];
foreach ($basestrings as $key => $string) { foreach ($basestrings as $key => $string) {

View File

@ -104,7 +104,7 @@ class EarlyRenderingControllerTest extends BrowserTestBase {
// The exceptions are expected. Do not interpret them as a test failure. // The exceptions are expected. Do not interpret them as a test failure.
// Not using File API; a potential error must trigger a PHP warning. // Not using File API; a potential error must trigger a PHP warning.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); unlink($this->root . '/' . $this->siteDirectory . '/error.log');
} }
} }

View File

@ -20,7 +20,7 @@ class FileTransferTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->testConnection = TestFileTransfer::factory(\Drupal::root(), ['hostname' => $this->hostname, 'username' => $this->username, 'password' => $this->password, 'port' => $this->port]); $this->testConnection = TestFileTransfer::factory($this->root, ['hostname' => $this->hostname, 'username' => $this->username, 'password' => $this->password, 'port' => $this->port]);
} }
public function _getFakeModuleFiles() { public function _getFakeModuleFiles() {
@ -82,7 +82,7 @@ class FileTransferTest extends BrowserTestBase {
$gotit = TRUE; $gotit = TRUE;
try { try {
$this->testConnection->copyDirectory($source, \Drupal::root() . '/' . PublicStream::basePath()); $this->testConnection->copyDirectory($source, $this->root . '/' . PublicStream::basePath());
} }
catch (FileTransferException $e) { catch (FileTransferException $e) {
$gotit = FALSE; $gotit = FALSE;

View File

@ -21,7 +21,7 @@ class DependencyHookInvocationTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
} }
/** /**

View File

@ -22,7 +22,7 @@ class DependencyMissingTest extends BrowserTestBase {
// Only install update_test_2.module, even though its updates have a // Only install update_test_2.module, even though its updates have a
// dependency on update_test_3.module. // dependency on update_test_3.module.
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
} }
public function testMissingUpdate() { public function testMissingUpdate() {

View File

@ -20,7 +20,7 @@ class DependencyOrderingTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
} }
/** /**

View File

@ -35,7 +35,7 @@ class InvalidUpdateHookTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = $GLOBALS['base_url'] . '/update.php'; $this->updateUrl = $GLOBALS['base_url'] . '/update.php';
$this->updateUser = $this->drupalCreateUser(['administer software updates']); $this->updateUser = $this->drupalCreateUser(['administer software updates']);

View File

@ -35,7 +35,7 @@ class UpdateSchemaTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
$this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']); $this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']);
$this->updateUrl = Url::fromRoute('system.db_update'); $this->updateUrl = Url::fromRoute('system.db_update');
} }

View File

@ -31,7 +31,7 @@ class UpdatesWith7xTest extends BrowserTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
$this->updateUrl = $GLOBALS['base_url'] . '/update.php'; $this->updateUrl = $GLOBALS['base_url'] . '/update.php';
$this->updateUser = $this->drupalCreateUser(['administer software updates']); $this->updateUser = $this->drupalCreateUser(['administer software updates']);
} }

View File

@ -33,13 +33,13 @@ class SystemListingTest extends KernelTestBase {
foreach ($expected_directories as $module => $directories) { foreach ($expected_directories as $module => $directories) {
foreach ($directories as $directory) { foreach ($directories as $directory) {
$filename = "$directory/$module/$module.info.yml"; $filename = "$directory/$module/$module.info.yml";
$this->assertTrue(file_exists(\Drupal::root() . '/' . $filename), format_string('@filename exists.', ['@filename' => $filename])); $this->assertTrue(file_exists($this->root . '/' . $filename), format_string('@filename exists.', ['@filename' => $filename]));
} }
} }
// Now scan the directories and check that the files take precedence as // Now scan the directories and check that the files take precedence as
// expected. // expected.
$listing = new ExtensionDiscovery(\Drupal::root()); $listing = new ExtensionDiscovery($this->root);
$listing->setProfileDirectories(['core/profiles/testing']); $listing->setProfileDirectories(['core/profiles/testing']);
$files = $listing->scan('module'); $files = $listing->scan('module');
foreach ($expected_directories as $module => $directories) { foreach ($expected_directories as $module => $directories) {
@ -56,7 +56,7 @@ class SystemListingTest extends KernelTestBase {
* Tests that directories matching file_scan_ignore_directories are ignored * Tests that directories matching file_scan_ignore_directories are ignored
*/ */
public function testFileScanIgnoreDirectory() { public function testFileScanIgnoreDirectory() {
$listing = new ExtensionDiscovery(\Drupal::root(), FALSE); $listing = new ExtensionDiscovery($this->root, FALSE);
$listing->setProfileDirectories(['core/profiles/testing']); $listing->setProfileDirectories(['core/profiles/testing']);
$files = $listing->scan('module'); $files = $listing->scan('module');
$this->assertArrayHasKey('drupal_system_listing_compatible_test', $files); $this->assertArrayHasKey('drupal_system_listing_compatible_test', $files);
@ -68,7 +68,7 @@ class SystemListingTest extends KernelTestBase {
$reflected_property->setValue($reflected_class, []); $reflected_property->setValue($reflected_class, []);
$this->setSetting('file_scan_ignore_directories', ['drupal_system_listing_compatible_test']); $this->setSetting('file_scan_ignore_directories', ['drupal_system_listing_compatible_test']);
$listing = new ExtensionDiscovery(\Drupal::root(), FALSE); $listing = new ExtensionDiscovery($this->root, FALSE);
$listing->setProfileDirectories(['core/profiles/testing']); $listing->setProfileDirectories(['core/profiles/testing']);
$files = $listing->scan('module'); $files = $listing->scan('module');
$this->assertArrayNotHasKey('drupal_system_listing_compatible_test', $files); $this->assertArrayNotHasKey('drupal_system_listing_compatible_test', $files);

View File

@ -164,7 +164,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// installed for testing below. // installed for testing below.
$this->vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo'); $this->vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo');
require_once \Drupal::root() . '/core/includes/install.inc'; require_once $this->root . '/core/includes/install.inc';
$this->container->get('module_installer')->uninstall(['taxonomy']); $this->container->get('module_installer')->uninstall(['taxonomy']);
$this->container->get('module_installer')->install(['taxonomy']); $this->container->get('module_installer')->install(['taxonomy']);

View File

@ -190,10 +190,10 @@ class UpdateUploadTest extends UpdateTestBase {
* Tests only an *.info.yml file are detected without supporting files. * Tests only an *.info.yml file are detected without supporting files.
*/ */
public function testUpdateDirectory() { public function testUpdateDirectory() {
$type = Updater::getUpdaterFromDirectory(\Drupal::root() . '/core/modules/update/tests/modules/aaa_update_test'); $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/modules/aaa_update_test');
$this->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module'); $this->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module');
$type = Updater::getUpdaterFromDirectory(\Drupal::root() . '/core/modules/update/tests/themes/update_test_basetheme'); $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/themes/update_test_basetheme');
$this->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.'); $this->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.');
} }

View File

@ -24,8 +24,8 @@ class UserAccountFormFieldsTest extends KernelTestBase {
* Tests the root user account form section in the "Configure site" form. * Tests the root user account form section in the "Configure site" form.
*/ */
public function testInstallConfigureForm() { public function testInstallConfigureForm() {
require_once \Drupal::root() . '/core/includes/install.core.inc'; require_once $this->root . '/core/includes/install.core.inc';
require_once \Drupal::root() . '/core/includes/install.inc'; require_once $this->root . '/core/includes/install.inc';
$install_state = install_state_defaults(); $install_state = install_state_defaults();
$form_state = new FormState(); $form_state = new FormState();
$form_state->addBuildInfo('args', [&$install_state]); $form_state->addBuildInfo('args', [&$install_state]);

View File

@ -21,8 +21,8 @@ class InstallerLanguageDirectionTest extends InstallerTestBase {
*/ */
protected function setUpLanguage() { protected function setUpLanguage() {
// Place a custom local translation in the translations directory. // Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); mkdir($this->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\""); file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.ar.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Arabic\"");
parent::setUpLanguage(); parent::setUpLanguage();
// After selecting a different language than English, all following screens // After selecting a different language than English, all following screens

View File

@ -16,8 +16,8 @@ class InstallerLanguagePageTest extends InstallerTestBase {
*/ */
protected function setUpLanguage() { protected function setUpLanguage() {
// Place a custom local translation in the translations directory. // Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
touch(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po'); touch($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po');
// Check that all predefined languages show up with their native names. // Check that all predefined languages show up with their native names.
$this->visitInstaller(); $this->visitInstaller();

View File

@ -19,7 +19,7 @@ class InstallerTest extends InstallerTestBase {
$this->assertText($this->rootUser->getUsername()); $this->assertText($this->rootUser->getUsername());
// Verify that the confirmation message appears. // Verify that the confirmation message appears.
require_once \Drupal::root() . '/core/includes/install.inc'; require_once $this->root . '/core/includes/install.inc';
$this->assertRaw(t('Congratulations, you installed @drupal!', [ $this->assertRaw(t('Congratulations, you installed @drupal!', [
'@drupal' => drupal_install_profile_distribution_name(), '@drupal' => drupal_install_profile_distribution_name(),
])); ]));

View File

@ -23,8 +23,8 @@ class InstallerTranslationQueryTest extends InstallerTestBase {
*/ */
protected function visitInstaller() { protected function visitInstaller() {
// Place a custom local translation in the translations directory. // Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de')); file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
// The unrouted URL assembler does not exist at this point, so we build the // The unrouted URL assembler does not exist at this point, so we build the
// URL ourselves. // URL ourselves.

View File

@ -24,8 +24,8 @@ class InstallerTranslationTest extends InstallerTestBase {
*/ */
protected function setUpLanguage() { protected function setUpLanguage() {
// Place a custom local translation in the translations directory. // Place a custom local translation in the translations directory.
mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de')); file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
parent::setUpLanguage(); parent::setUpLanguage();

View File

@ -193,7 +193,7 @@ abstract class UpdatePathTestBase extends BrowserTestBase {
$this->replaceUser1(); $this->replaceUser1();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
// Setup Mink. // Setup Mink.
$session = $this->initMink(); $session = $this->initMink();

View File

@ -149,7 +149,6 @@ class ResolvedLibraryDefinitionsFilesMatchTest extends KernelTestBase {
* so on. * so on.
*/ */
protected function verifyLibraryFilesExist($library_definitions) { protected function verifyLibraryFilesExist($library_definitions) {
$root = \Drupal::root();
foreach ($library_definitions as $extension => $libraries) { foreach ($library_definitions as $extension => $libraries) {
foreach ($libraries as $library_name => $library) { foreach ($libraries as $library_name => $library) {
if (in_array("$extension/$library_name", $this->librariesToSkip)) { if (in_array("$extension/$library_name", $this->librariesToSkip)) {
@ -160,7 +159,7 @@ class ResolvedLibraryDefinitionsFilesMatchTest extends KernelTestBase {
foreach (['css', 'js'] as $asset_type) { foreach (['css', 'js'] as $asset_type) {
foreach ($library[$asset_type] as $asset) { foreach ($library[$asset_type] as $asset) {
$file = $asset['data']; $file = $asset['data'];
$path = $root . '/' . $file; $path = $this->root . '/' . $file;
// Only check and assert each file path once. // Only check and assert each file path once.
if (!isset($this->pathsChecked[$path])) { if (!isset($this->pathsChecked[$path])) {
$this->assertTrue(is_file($path), "$file file referenced from the $extension/$library_name library exists."); $this->assertTrue(is_file($path), "$file file referenced from the $extension/$library_name library exists.");
@ -192,10 +191,9 @@ class ResolvedLibraryDefinitionsFilesMatchTest extends KernelTestBase {
$libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core'); $libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core');
$root = \Drupal::root();
foreach ($extensions as $extension_name => $extension) { foreach ($extensions as $extension_name => $extension) {
$library_file = $extension->getPath() . '/' . $extension_name . '.libraries.yml'; $library_file = $extension->getPath() . '/' . $extension_name . '.libraries.yml';
if (is_file($root . '/' . $library_file)) { if (is_file($this->root . '/' . $library_file)) {
$libraries[$extension_name] = $this->libraryDiscovery->getLibrariesByExtension($extension_name); $libraries[$extension_name] = $this->libraryDiscovery->getLibrariesByExtension($extension_name);
} }
} }

View File

@ -28,7 +28,7 @@ class IgnoreReplicaSubscriberTest extends KernelTestBase {
Database::addConnectionInfo('default', 'replica', $connection_info['default']); Database::addConnectionInfo('default', 'replica', $connection_info['default']);
db_ignore_replica(); db_ignore_replica();
$class_loader = require \Drupal::root() . '/autoload.php'; $class_loader = require $this->root . '/autoload.php';
$kernel = new DrupalKernel('testing', $class_loader, FALSE); $kernel = new DrupalKernel('testing', $class_loader, FALSE);
$event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST); $event = new GetResponseEvent($kernel, Request::create('http://example.com'), HttpKernelInterface::MASTER_REQUEST);
$subscriber = new ReplicaDatabaseIgnoreSubscriber(); $subscriber = new ReplicaDatabaseIgnoreSubscriber();

View File

@ -73,8 +73,8 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
], ],
]; ];
$base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $base_directory = $this->root . '/core/modules/system/tests/modules/plugin_test/src';
$base_directory2 = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test_extended/src'; $base_directory2 = $this->root . '/core/modules/system/tests/modules/plugin_test_extended/src';
$namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory, 'Drupal\plugin_test_extended' => $base_directory2]); $namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory, 'Drupal\plugin_test_extended' => $base_directory2]);
$annotation_namespaces = ['Drupal\plugin_test\Plugin\Annotation', 'Drupal\plugin_test_extended\Plugin\Annotation']; $annotation_namespaces = ['Drupal\plugin_test\Plugin\Annotation', 'Drupal\plugin_test_extended\Plugin\Annotation'];

View File

@ -30,7 +30,7 @@ class CustomAnnotationClassDiscoveryTest extends DiscoveryTestBase {
], ],
]; ];
$base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $base_directory = $this->root . '/core/modules/system/tests/modules/plugin_test/src';
$root_namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory]); $root_namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory]);
$this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');

View File

@ -80,7 +80,7 @@ class CustomDirectoryAnnotatedClassDiscoveryTest extends DiscoveryTestBase {
], ],
]; ];
$base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src'; $base_directory = $this->root . '/core/modules/system/tests/modules/plugin_test/src';
$namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory]); $namespaces = new \ArrayObject(['Drupal\plugin_test' => $base_directory]);
$this->discovery = new AnnotatedClassDiscovery('', $namespaces); $this->discovery = new AnnotatedClassDiscovery('', $namespaces);

View File

@ -42,7 +42,7 @@ abstract class PluginTestBase extends KernelTestBase {
// as derivatives and ReflectionFactory. // as derivatives and ReflectionFactory.
$this->testPluginManager = new TestPluginManager(); $this->testPluginManager = new TestPluginManager();
$this->mockBlockManager = new MockBlockManager(); $this->mockBlockManager = new MockBlockManager();
$module_handler = new ModuleHandler(\Drupal::root(), [], new MemoryBackend(), $this->container->get('event_dispatcher')); $module_handler = new ModuleHandler($this->root, [], new MemoryBackend(), $this->container->get('event_dispatcher'));
$this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler); $this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler);
// The expected plugin definitions within each manager. Several tests assert // The expected plugin definitions within each manager. Several tests assert

View File

@ -53,7 +53,7 @@ class RouteNoneTest extends KernelTestBase {
// Test request with subdir on homepage. // Test request with subdir on homepage.
$server = [ $server = [
'SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_NAME' => '/subdir/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/subdir', 'GET', [], [], [], $server); $request = Request::create('/subdir', 'GET', [], [], [], $server);
@ -70,7 +70,7 @@ class RouteNoneTest extends KernelTestBase {
// Test request with subdir on other page. // Test request with subdir on other page.
$server = [ $server = [
'SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_NAME' => '/subdir/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/subdir/node/add', 'GET', [], [], [], $server); $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
@ -87,7 +87,7 @@ class RouteNoneTest extends KernelTestBase {
// Test request without subdir on the homepage. // Test request without subdir on the homepage.
$server = [ $server = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/', 'GET', [], [], [], $server); $request = Request::create('/', 'GET', [], [], [], $server);
@ -104,7 +104,7 @@ class RouteNoneTest extends KernelTestBase {
// Test request without subdir on other page. // Test request without subdir on other page.
$server = [ $server = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/node/add', 'GET', [], [], [], $server); $request = Request::create('/node/add', 'GET', [], [], [], $server);

View File

@ -54,7 +54,7 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
// Test request with subdir on homepage. // Test request with subdir on homepage.
$server = [ $server = [
'SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_NAME' => '/subdir/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/subdir/', 'GET', [], [], [], $server); $request = Request::create('/subdir/', 'GET', [], [], [], $server);
@ -69,7 +69,7 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
// Test request with subdir on other page. // Test request with subdir on other page.
$server = [ $server = [
'SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_NAME' => '/subdir/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/subdir/node/add', 'GET', [], [], [], $server); $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
@ -84,7 +84,7 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
// Test request without subdir on the homepage. // Test request without subdir on the homepage.
$server = [ $server = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/', 'GET', [], [], [], $server); $request = Request::create('/', 'GET', [], [], [], $server);
@ -99,7 +99,7 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
// Test request without subdir on other page. // Test request without subdir on other page.
$server = [ $server = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/node/add', 'GET', [], [], [], $server); $request = Request::create('/node/add', 'GET', [], [], [], $server);
@ -115,7 +115,7 @@ class RouteProcessorCurrentIntegrationTest extends KernelTestBase {
// not found exception page. // not found exception page.
$server = [ $server = [
'SCRIPT_NAME' => '/index.php', 'SCRIPT_NAME' => '/index.php',
'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SCRIPT_FILENAME' => $this->root . '/index.php',
'SERVER_NAME' => 'http://www.example.com', 'SERVER_NAME' => 'http://www.example.com',
]; ];
$request = Request::create('/invalid-path', 'GET', [], [], [], $server); $request = Request::create('/invalid-path', 'GET', [], [], [], $server);

View File

@ -16,7 +16,7 @@ class SettingsRewriteTest extends KernelTestBase {
* Tests the drupal_rewrite_settings() function. * Tests the drupal_rewrite_settings() function.
*/ */
public function testDrupalRewriteSettings() { public function testDrupalRewriteSettings() {
include_once \Drupal::root() . '/core/includes/install.inc'; include_once $this->root . '/core/includes/install.inc';
$site_path = $this->container->get('site.path'); $site_path = $this->container->get('site.path');
$tests = [ $tests = [
[ [

View File

@ -69,11 +69,11 @@ class RegistryTest extends KernelTestBase {
$theme_handler = \Drupal::service('theme_handler'); $theme_handler = \Drupal::service('theme_handler');
$theme_handler->install(['test_basetheme', 'test_subtheme', 'test_subsubtheme']); $theme_handler->install(['test_basetheme', 'test_subtheme', 'test_subsubtheme']);
$registry_subsub_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subsubtheme'); $registry_subsub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subsubtheme');
$registry_subsub_theme->setThemeManager(\Drupal::theme()); $registry_subsub_theme->setThemeManager(\Drupal::theme());
$registry_sub_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subtheme'); $registry_sub_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_subtheme');
$registry_sub_theme->setThemeManager(\Drupal::theme()); $registry_sub_theme->setThemeManager(\Drupal::theme());
$registry_base_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_basetheme'); $registry_base_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_basetheme');
$registry_base_theme->setThemeManager(\Drupal::theme()); $registry_base_theme->setThemeManager(\Drupal::theme());
$preprocess_functions = $registry_subsub_theme->get()['theme_test_template_test']['preprocess functions']; $preprocess_functions = $registry_subsub_theme->get()['theme_test_template_test']['preprocess functions'];
@ -111,7 +111,7 @@ class RegistryTest extends KernelTestBase {
$theme_handler = \Drupal::service('theme_handler'); $theme_handler = \Drupal::service('theme_handler');
$theme_handler->install(['test_theme']); $theme_handler->install(['test_theme']);
$registry_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme'); $registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
$registry_theme->setThemeManager(\Drupal::theme()); $registry_theme->setThemeManager(\Drupal::theme());
$suggestions = ['__kitten', '__flamingo']; $suggestions = ['__kitten', '__flamingo'];
@ -154,7 +154,7 @@ class RegistryTest extends KernelTestBase {
$theme_handler->install(['test_theme']); $theme_handler->install(['test_theme']);
$this->config('system.theme')->set('default', 'test_theme')->save(); $this->config('system.theme')->set('default', 'test_theme')->save();
$registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme'); $registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
$registry->setThemeManager(\Drupal::theme()); $registry->setThemeManager(\Drupal::theme());
$this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']); $this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']);
} }
@ -199,7 +199,7 @@ class RegistryTest extends KernelTestBase {
$theme_handler = \Drupal::service('theme_handler'); $theme_handler = \Drupal::service('theme_handler');
$theme_handler->install(['test_theme']); $theme_handler->install(['test_theme']);
$registry_theme = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme'); $registry_theme = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
$registry_theme->setThemeManager(\Drupal::theme()); $registry_theme->setThemeManager(\Drupal::theme());
$expected = [ $expected = [

View File

@ -94,7 +94,6 @@ class StableLibraryOverrideTest extends KernelTestBase {
$libraries_after = $this->getAllLibraries(); $libraries_after = $this->getAllLibraries();
$libraries_after = $this->removeVendorAssets($libraries_after); $libraries_after = $this->removeVendorAssets($libraries_after);
$root = \Drupal::root();
foreach ($libraries_before as $extension => $libraries) { foreach ($libraries_before as $extension => $libraries) {
foreach ($libraries as $library_name => $library) { foreach ($libraries as $library_name => $library) {
// Allow skipping libraries. // Allow skipping libraries.
@ -173,10 +172,9 @@ class StableLibraryOverrideTest extends KernelTestBase {
$libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core'); $libraries['core'] = $this->libraryDiscovery->getLibrariesByExtension('core');
$root = \Drupal::root();
foreach ($modules as $module_name => $module) { foreach ($modules as $module_name => $module) {
$library_file = $module->getPath() . '/' . $module_name . '.libraries.yml'; $library_file = $module->getPath() . '/' . $module_name . '.libraries.yml';
if (is_file($root . '/' . $library_file)) { if (is_file($this->root . '/' . $library_file)) {
$libraries[$module_name] = $this->libraryDiscovery->getLibrariesByExtension($module_name); $libraries[$module_name] = $this->libraryDiscovery->getLibrariesByExtension($module_name);
} }
} }

View File

@ -82,7 +82,7 @@ class StableTemplateOverrideTest extends KernelTestBase {
* Ensures that Stable overrides all relevant core templates. * Ensures that Stable overrides all relevant core templates.
*/ */
public function testStableTemplateOverrides() { public function testStableTemplateOverrides() {
$registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable'); $registry = new Registry($this->root, \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
$registry->setThemeManager(\Drupal::theme()); $registry->setThemeManager(\Drupal::theme());
$registry_full = $registry->get(); $registry_full = $registry->get();

View File

@ -33,7 +33,7 @@ class ThemeSettingsTest extends KernelTestBase {
$this->installConfig(['system']); $this->installConfig(['system']);
if (!isset($this->availableThemes)) { if (!isset($this->availableThemes)) {
$discovery = new ExtensionDiscovery(\Drupal::root()); $discovery = new ExtensionDiscovery($this->root);
$this->availableThemes = $discovery->scan('theme'); $this->availableThemes = $discovery->scan('theme');
} }
} }

View File

@ -250,7 +250,7 @@ class TypedDataTest extends KernelTestBase {
$files = []; $files = [];
for ($i = 0; $i < 3; $i++) { for ($i = 0; $i < 3; $i++) {
$path = "public://example_$i.png"; $path = "public://example_$i.png";
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', $path); file_unmanaged_copy($this->root . '/core/misc/druplicon.png', $path);
$image = File::create(['uri' => $path]); $image = File::create(['uri' => $path]);
$image->save(); $image->save();
$files[] = $image; $files[] = $image;

View File

@ -18,7 +18,7 @@ class CompatibilityFixTest extends KernelTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc'; require_once $this->root . '/core/includes/update.inc';
} }
public function testFixCompatibility() { public function testFixCompatibility() {

View File

@ -24,7 +24,7 @@ class UpdaterTest extends KernelTestBase {
public function testGetProjectTitleWithChild() { public function testGetProjectTitleWithChild() {
// Get the project title from its directory. If it can't find the title // Get the project title from its directory. If it can't find the title
// it will choose the first project title in the directory. // it will choose the first project title in the directory.
$directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple'; $directory = $this->root . '/core/modules/system/tests/modules/module_handler_test_multiple';
$title = Updater::getProjectTitle($directory); $title = Updater::getProjectTitle($directory);
$this->assertEqual('module handler test multiple', $title); $this->assertEqual('module handler test multiple', $title);
} }

View File

@ -812,7 +812,7 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
// profile that is not the current profile, and we don't yet have a cached // profile that is not the current profile, and we don't yet have a cached
// way to receive inactive profile information. // way to receive inactive profile information.
// @todo Remove as part of https://www.drupal.org/node/2186491 // @todo Remove as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root()); $listing = new ExtensionDiscovery($this->root);
$module_list = $listing->scan('module'); $module_list = $listing->scan('module');
// In ModuleHandlerTest we pass in a profile as if it were a module. // In ModuleHandlerTest we pass in a profile as if it were a module.
$module_list += $listing->scan('profile'); $module_list += $listing->scan('profile');