本文整理汇总了PHP中Drupal::root方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::root方法的具体用法?PHP Drupal::root怎么用?PHP Drupal::root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::root方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSimpleAjaxFormValue
/**
* Submits forms with select and checkbox elements via Ajax.
*/
function testSimpleAjaxFormValue()
{
// Verify form values of a select element.
foreach (array('red', 'green', 'blue') as $item) {
$edit = array('select' => $item);
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'select');
$expected = new DataCommand('#ajax_selected_color', 'form_state_value_select', $item);
$this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a selectbox issued with a correct value.');
}
// Verify form values of a checkbox element.
foreach (array(FALSE, TRUE) as $item) {
$edit = array('checkbox' => $item);
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'checkbox');
$expected = new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $item);
$this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a checkbox issued with a correct value.');
}
// Verify that AJAX elements with invalid callbacks return error code 500.
// Ensure the test error log is empty before these tests.
$this->assertNoErrorsLogged();
// We don't need to check for the X-Drupal-Ajax-Token header with these
// invalid requests.
$this->assertAjaxHeader = FALSE;
foreach (array('null', 'empty', 'nonexistent') as $key) {
$element_name = 'select_' . $key . '_callback';
$edit = array($element_name => 'red');
$commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, $element_name);
$this->assertResponse(500);
}
// Switch this back to the default.
$this->assertAjaxHeader = TRUE;
// 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');
}
示例2: visitInstaller
/**
* {@inheritdoc}
*/
protected function visitInstaller()
{
// 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', $this->getPo('de'));
file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr'));
// Pass a different language code than the one set in the distribution
// profile. This distribution language should still be used.
// The unrouted URL assembler does not exist at this point, so we build the
// URL ourselves.
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
// The language should have been automatically detected, all following
// screens should be translated already.
$elements = $this->xpath('//input[@type="submit"]/@value');
$this->assertEqual((string) current($elements), 'Save and continue de');
$this->translations['Save and continue'] = 'Save and continue de';
// Check the language direction.
$direction = (string) current($this->xpath('/html/@dir'));
$this->assertEqual($direction, 'ltr');
// Verify that the distribution name appears.
$this->assertRaw($this->info['distribution']['name']);
// Verify that the requested theme is used.
$this->assertRaw($this->info['distribution']['install']['theme']);
// Verify that the "Choose profile" step does not appear.
$this->assertNoText('profile');
}
示例3: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
require_once \Drupal::root() . '/core/includes/update.inc';
$this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']);
$this->updateUrl = Url::fromRoute('system.db_update');
}
示例4: testDrupalRewriteSettings
/**
* Tests the drupal_rewrite_settings() function.
*/
function testDrupalRewriteSettings()
{
include_once \Drupal::root() . '/core/includes/install.inc';
$site_path = $this->container->get('site.path');
$tests = array(array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_scalar' => (object) array('value' => FALSE, 'comment' => 'comment')), 'expected' => '$no_index_value_scalar = false; // comment'), array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_foo' => array('foo' => array('value' => (object) array('value' => NULL, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$no_index_value_scalar = TRUE;
$no_index_value_foo['foo']['value'] = NULL; // comment
EXPECTED
), array('original' => '$no_index_value_array = array("old" => "value");', 'settings' => array('no_index_value_array' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')), 'expected' => '$no_index_value_array = array("old" => "value");
$no_index_value_array = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = NULL;', 'settings' => array('has_index_value_scalar' => array('foo' => array('bar' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => '$has_index_value_scalar["foo"]["bar"] = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = "foo";', 'settings' => array('has_index_value_scalar' => array('foo' => array('value' => (object) array('value' => array('value' => 2), 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$has_index_value_scalar["foo"]["bar"] = "foo";
$has_index_value_scalar['foo']['value'] = array (
'value' => 2,
); // comment
EXPECTED
));
foreach ($tests as $test) {
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "<?php\n" . $test['original'] . "\n");
drupal_rewrite_settings($test['settings'], $filename);
$this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
}
// Test that <?php gets added to the start of an empty settings file.
// Set the array of settings that will be written to the file.
$test = array('settings' => array('no_index' => (object) array('value' => TRUE, 'required' => TRUE)), 'expected' => '$no_index = true;');
// Make an empty file.
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "");
// Write the setting to the file.
drupal_rewrite_settings($test['settings'], $filename);
// Check that the result is just the php opening tag and the settings.
$this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
}
示例5: testWithBrokenRouting
/**
* Tests running update.php with some form of broken routing.
*/
public function testWithBrokenRouting()
{
// Make sure we can get to the front page.
$this->drupalGet('<front>');
$this->assertResponse(200);
// Simulate a broken router, and make sure the front page is
// inaccessible.
\Drupal::state()->set('update_script_test_broken_inbound', TRUE);
\Drupal::service('cache_tags.invalidator')->invalidateTags(['route_match', 'rendered']);
$this->drupalGet('<front>');
$this->assertResponse(500);
// 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');
foreach ($this->assertions as $key => $assertion) {
if (strpos($assertion['message'], 'core/modules/system/tests/modules/update_script_test/src/PathProcessor/BrokenInboundPathProcessor.php') !== FALSE) {
unset($this->assertions[$key]);
$this->deleteAssert($assertion['message_id']);
}
}
$this->runUpdates();
// Remove the simulation of the broken router, and make sure we can get to
// the front page again.
\Drupal::state()->set('update_script_test_broken_inbound', FALSE);
$this->drupalGet('<front>');
$this->assertResponse(200);
}
示例6: getDatabaseConnection
/**
* Parse input options decide on a database.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* Input object.
* @return \Drupal\Core\Database\Connection
*/
protected function getDatabaseConnection(InputInterface $input)
{
// Load connection from a url.
if ($input->getOption('database-url')) {
// @todo this could probably be refactored to not use a global connection.
// Ensure database connection isn't set.
if (Database::getConnectionInfo('db-tools')) {
throw new \RuntimeException('Database "db-tools" is already defined. Cannot define database provided.');
}
$info = Database::convertDbUrlToConnectionInfo($input->getOption('database-url'), \Drupal::root());
Database::addConnectionInfo('db-tools', 'default', $info);
$key = 'db-tools';
} else {
$key = $input->getOption('database');
}
// If they supplied a prefix, replace it in the connection information.
$prefix = $input->getOption('prefix');
if ($prefix) {
$info = Database::getConnectionInfo($key)['default'];
$info['prefix']['default'] = $prefix;
Database::removeConnection($key);
Database::addConnectionInfo($key, 'default', $info);
}
return Database::getConnection('default', $key);
}
示例7: setUp
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';
}
示例8: setUp
protected function setUp()
{
parent::setUp();
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'));
}
示例9: testDirectoryPrecedence
/**
* Tests that files in different directories take precedence as expected.
*/
function testDirectoryPrecedence()
{
// Define the module files we will search for, and the directory precedence
// we expect.
$expected_directories = array('drupal_system_listing_compatible_test' => array('core/profiles/testing/modules', 'core/modules/system/tests/modules'));
// This test relies on two versions of the same module existing in
// different places in the filesystem. Without that, the test has no
// meaning, so assert their presence first.
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)));
}
}
// Now scan the directories and check that the files take precedence as
// expected.
$listing = new ExtensionDiscovery(\Drupal::root());
$listing->setProfileDirectories(array('core/profiles/testing'));
$files = $listing->scan('module');
foreach ($expected_directories as $module => $directories) {
$expected_directory = array_shift($directories);
$expected_uri = "{$expected_directory}/{$module}/{$module}.info.yml";
$this->assertEqual($files[$module]->getPathname(), $expected_uri, format_string('Module @actual was found at @expected.', array('@actual' => $files[$module]->getPathname(), '@expected' => $expected_uri)));
}
}
示例10: testInstaller
/**
* Ensures that the user page is available after installation.
*/
public function testInstaller()
{
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getUsername());
// @todo hmmm this message is wrong!
// Verify that the confirmation message appears.
require_once \Drupal::root() . '/core/includes/install.inc';
$this->assertRaw(t('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())));
// Ensure that all modules, profile and themes have been installed and have
// expected weights.
$sync = \Drupal::service('config.storage.sync');
$sync_core_extension = $sync->read('core.extension');
$this->assertIdentical($sync_core_extension, \Drupal::config('core.extension')->get());
// Ensure that the correct install profile has been written to settings.php.
$listing = new ExtensionDiscovery(\Drupal::root());
$listing->setProfileDirectories([]);
$profiles = array_intersect_key($listing->scan('profile'), $sync_core_extension['module']);
$current_profile = Settings::get('install_profile');
$this->assertFalse(empty($current_profile), 'The $install_profile setting exists');
$this->assertEqual($current_profile, key($profiles));
// Test that any configuration entities in sync have been created.
// @todo
}
示例11: tearDown
protected function tearDown()
{
// This test intentionally throws an exception in a PHP shutdown function.
// Prevent it from being interpreted as an actual test failure.
// Not using File API; a potential error must trigger a PHP warning.
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
parent::tearDown();
}
示例12: testGetProjectTitleWithChild
/**
* Tests project and child project showing correct title.
*
* @see https://drupal.org/node/2409515
*/
public function testGetProjectTitleWithChild()
{
// Get the project title from it's directory. If it can't find the title
// it will choose the first project title in the directory.
$directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple';
$title = Updater::getProjectTitle($directory);
$this->assertEqual('module handler test multiple', $title);
}
示例13: setUp
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
// Set the path of the module dynamically.
$module_path = str_replace(\Drupal::root(), '', __DIR__);
$module_path = str_replace('tests/src/Unit/Menu', '', $module_path);
$module_path = trim($module_path, '/');
$this->directoryList = array('search_api' => $module_path);
}
示例14: getForm
public function getForm(array &$form, array &$form_state, \Payment $payment)
{
$form['holder'] = array('#type' => 'textfield', '#title' => t('Account holder'));
include_once \Drupal::root() . '/includes/locale.inc';
$form['ibanbic'] = array('#type' => 'container');
$form['ibanbic']['iban'] = array('#type' => 'textfield', '#title' => t('IBAN'), '#required' => FALSE, '#default_value' => NULL, '#size' => 48, '#maxlength' => 48);
$form['ibanbic']['bic'] = array('#type' => 'textfield', '#title' => t('BIC'), '#required' => FALSE, '#default_value' => NULL, '#size' => 16, '#maxlength' => 16);
return $form;
}
示例15: getAllFolders
/**
* {@inheritdoc}
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$listing = new ExtensionDiscovery(\Drupal::root());
$modules = $listing->scan('module');
$this->folders = $this->getComponentNames(array('behat_test' => $modules['behat_test']));
}
return $this->folders;
}