/**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $settingKeys = array_keys($this->settings->getAll());
     $io->newLine();
     $io->info($this->trans('commands.config.settings.debug.messages.current'));
     $io->newLine();
     foreach ($settingKeys as $settingKey) {
         $io->comment($settingKey, false);
         $io->simple(Yaml::encode($this->settings->get($settingKey)));
     }
     $io->newLine();
 }
Example #2
0
 /**
  * Tests inline templates.
  */
 public function testInlineTemplate()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     /** @var \Drupal\Core\Template\TwigEnvironment $environment */
     $environment = \Drupal::service('twig');
     $this->assertEqual($environment->renderInline('test-no-context'), 'test-no-context');
     $this->assertEqual($environment->renderInline('test-with-context {{ llama }}', array('llama' => 'muuh')), 'test-with-context muuh');
     $element = array();
     $unsafe_string = '<script>alert(\'Danger! High voltage!\');</script>';
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context <label>{{ unsafe_content }}</label>', '#context' => array('unsafe_content' => $unsafe_string));
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . SafeMarkup::checkPlain($unsafe_string) . '</label>');
     // Enable twig_auto_reload and twig_debug.
     $settings = Settings::getAll();
     $settings['twig_debug'] = TRUE;
     $settings['twig_auto_reload'] = TRUE;
     new Settings($settings);
     $this->container = $this->kernel->rebuildContainer();
     \Drupal::setContainer($this->container);
     $element = array();
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context {{ llama }}', '#context' => array('llama' => 'muuh'));
     $element_copy = $element;
     // Render it twice so that twig caching is triggered.
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh');
     $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh');
 }
 /**
  * Tests writable files remain writable when directory hardening is disabled.
  */
 public function testSitesDirectoryHardeningConfig()
 {
     $site_path = $this->kernel->getSitePath();
     $settings_file = $this->settingsFile($site_path);
     // Disable permissions enforcement.
     $settings = Settings::getAll();
     $settings['skip_permissions_hardening'] = TRUE;
     new Settings($settings);
     $this->assertTrue(Settings::get('skip_permissions_hardening'), 'Able to set hardening to true');
     $this->makeWritable($site_path);
     // Manually trigger the requirements check.
     $requirements = $this->checkSystemRequirements();
     $this->assertEqual(REQUIREMENT_WARNING, $requirements['configuration_files']['severity'], 'Warning severity is properly set.');
     $this->assertEqual($this->t('Protection disabled'), (string) $requirements['configuration_files']['description']['#context']['configuration_error_list']['#items'][0], 'Description is properly set.');
     $this->assertTrue(is_writable($site_path), 'Site directory remains writable when automatically fixing permissions is disabled.');
     $this->assertTrue(is_writable($settings_file), 'settings.php remains writable when automatically fixing permissions is disabled.');
     // Re-enable permissions enforcement.
     $settings = Settings::getAll();
     $settings['skip_permissions_hardening'] = FALSE;
     new Settings($settings);
     // Manually trigger the requirements check.
     $this->checkSystemRequirements();
     $this->assertFalse(is_writable($site_path), 'Site directory is protected when automatically fixing permissions is enabled.');
     $this->assertFalse(is_writable($settings_file), 'settings.php is protected when automatically fixing permissions is enabled.');
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Empty the PHP storage settings, as KernelTestBase sets it by default.
     $settings = Settings::getAll();
     unset($settings['php_storage']);
     new Settings($settings);
 }
 function setUp()
 {
     // Add file_private_path setting.
     $settings = Settings::getAll();
     $request = Request::create('/');
     $site_path = DrupalKernel::findSitePath($request);
     $settings['file_private_path'] = $site_path . '/private';
     new Settings($settings + Settings::getAll());
     parent::setUp();
 }
 /**
  * Tests behaviour if a string is translated to become an empty string.
  */
 public function testEmptyTranslation()
 {
     $settings = Settings::getAll();
     $settings['locale_custom_strings_en'] = ['' => ['test' => '']];
     // Recreate the settings static.
     new Settings($settings);
     $variable = new TranslatableMarkup('test');
     $this->assertEquals('', $this->renderObjectWithTwig($variable));
     $variable = new TranslatableMarkup('test', [], ['langcode' => 'de']);
     $this->assertEquals('<span>test</span>', $this->renderObjectWithTwig($variable));
 }
Example #7
0
 /**
  * Reboots the kernel to set custom translations in Settings.
  */
 protected function rebootAndPrepareSettings()
 {
     // Reboot the container so that different services are injected and the new
     // settings are picked.
     $kernel = $this->container->get('kernel');
     $kernel->shutdown();
     $kernel->boot();
     $settings = Settings::getAll();
     $settings['locale_custom_strings_de'] = ['' => ['Example @number' => 'Example @number translated']];
     // Recreate the settings static.
     new Settings($settings);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     // Ensure that required Settings exist.
     if (!Settings::getAll()) {
         new Settings(array('hash_salt' => 'run-tests'));
     }
     // Remove Drupal's error/exception handlers; they are designed for HTML
     // and there is no storage nor a (watchdog) logger here.
     restore_error_handler();
     restore_exception_handler();
     // In addition, ensure that PHP errors are not hidden away in logs.
     ini_set('display_errors', TRUE);
     parent::boot();
     $this->getContainer()->get('module_handler')->loadAll();
     simpletest_classloader_register();
 }
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     // Ensure that required Settings exist.
     if (!Settings::getAll()) {
         new Settings(array('hash_salt' => 'run-tests', 'file_public_path' => 'sites/default/files'));
     }
     // Remove Drupal's error/exception handlers; they are designed for HTML
     // and there is no storage nor a (watchdog) logger here.
     restore_error_handler();
     restore_exception_handler();
     // In addition, ensure that PHP errors are not hidden away in logs.
     ini_set('display_errors', TRUE);
     parent::boot();
     $this->getContainer()->get('module_handler')->loadAll();
     simpletest_classloader_register();
     // Create the build/artifacts directory if necessary.
     if (!is_dir('public://simpletest')) {
         mkdir('public://simpletest', 0777, TRUE);
     }
 }
 /**
  * Tests inline templates.
  */
 public function testInlineTemplate()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     /** @var \Drupal\Core\Template\TwigEnvironment $environment */
     $environment = \Drupal::service('twig');
     $this->assertEqual($environment->renderInline('test-no-context'), 'test-no-context');
     $this->assertEqual($environment->renderInline('test-with-context {{ llama }}', array('llama' => 'muuh')), 'test-with-context muuh');
     $element = array();
     $unsafe_string = '<script>alert(\'Danger! High voltage!\');</script>';
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context <label>{{ unsafe_content }}</label>', '#context' => array('unsafe_content' => $unsafe_string));
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context <label>' . Html::escape($unsafe_string) . '</label>');
     // Enable twig_auto_reload and twig_debug.
     $settings = Settings::getAll();
     $settings['twig_debug'] = TRUE;
     $settings['twig_auto_reload'] = TRUE;
     new Settings($settings);
     $this->container = $this->kernel->rebuildContainer();
     \Drupal::setContainer($this->container);
     $element = array();
     $element['test'] = array('#type' => 'inline_template', '#template' => 'test-with-context {{ llama }}', '#context' => array('llama' => 'muuh'));
     $element_copy = $element;
     // Render it twice so that twig caching is triggered.
     $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh');
     $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh');
     // Tests caching of inline templates with long content to ensure the
     // generated cache key can be used as a filename.
     $element = [];
     $element['test'] = ['#type' => 'inline_template', '#template' => 'Llamas sometimes spit and wrestle with their {{ llama }}. Kittens are soft and fuzzy and they sometimes say {{ kitten }}. Flamingos have long legs and they are usually {{ flamingo }}. Pandas eat bamboo and they are {{ panda }}. Giraffes have long necks and long tongues and they eat {{ giraffe }}.', '#context' => ['llama' => 'necks', 'kitten' => 'meow', 'flamingo' => 'pink', 'panda' => 'bears', 'giraffe' => 'leaves']];
     $expected = 'Llamas sometimes spit and wrestle with their necks. Kittens are soft and fuzzy and they sometimes say meow. Flamingos have long legs and they are usually pink. Pandas eat bamboo and they are bears. Giraffes have long necks and long tongues and they eat leaves.';
     $element_copy = $element;
     // Render it twice so that twig caching is triggered.
     $this->assertEqual($renderer->renderRoot($element), $expected);
     $this->assertEqual($renderer->renderRoot($element_copy), $expected);
     $name = '{# inline_template_start #}' . $element['test']['#template'];
     $hash = $this->container->getParameter('twig_extension_hash');
     $cache = $environment->getCache();
     $class = $environment->getTemplateClass($name);
     $expected = $hash . '_inline-template' . '_' . hash('sha256', $class);
     $this->assertEqual($expected, $cache->generateKey($name, $class));
 }
 /**
  * Tests the revision of paragraphs.
  */
 public function testParagraphsRevisions()
 {
     // Create the paragraph type.
     $paragraph_type = ParagraphsType::create(array('label' => 'test_text', 'id' => 'test_text'));
     $paragraph_type->save();
     $paragraph_type_nested = ParagraphsType::create(array('label' => 'test_nested', 'id' => 'test_nested'));
     $paragraph_type_nested->save();
     // Add a paragraph field to the article.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'nested_paragraph_field', 'entity_type' => 'paragraph', 'type' => 'entity_reference_revisions', 'cardinality' => '-1', 'settings' => array('target_type' => 'paragraph')));
     $field_storage->save();
     $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'test_nested'));
     $field->save();
     // Add a paragraph field to the article.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'node_paragraph_field', 'entity_type' => 'node', 'type' => 'entity_reference_revisions', 'cardinality' => '-1', 'settings' => array('target_type' => 'paragraph')));
     $field_storage->save();
     $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'article'));
     $field->save();
     // Add a paragraph field to the user.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'user_paragraph_field', 'entity_type' => 'user', 'type' => 'entity_reference_revisions', 'settings' => array('target_type' => 'paragraph')));
     $field_storage->save();
     $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'user'));
     $field->save();
     // Create a paragraph.
     $paragraph1 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph1->save();
     // Create another paragraph.
     $paragraph2 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph2->save();
     // Create another paragraph.
     $paragraph3 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph3->save();
     // Create another paragraph.
     $paragraph_nested_children1 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph_nested_children1->save();
     // Create another paragraph.
     $paragraph_nested_children2 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph_nested_children2->save();
     // Create another paragraph.
     $paragraph4_nested_parent = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_nested', 'nested_paragraph_field' => [$paragraph_nested_children1, $paragraph_nested_children2]]);
     $paragraph4_nested_parent->save();
     // Create another paragraph.
     $paragraph_user_1 = Paragraph::create(['title' => 'Paragraph', 'type' => 'test_text']);
     $paragraph_user_1->save();
     // Create a node with two paragraphs.
     $node = Node::create(['title' => $this->randomMachineName(), 'type' => 'article', 'node_paragraph_field' => array($paragraph1, $paragraph2, $paragraph3, $paragraph4_nested_parent)]);
     $node->save();
     // Create an user with a paragraph.
     $user = User::create(['name' => 'test', 'user_paragraph_field' => $paragraph_user_1]);
     $user->save();
     $settings = Settings::getAll();
     $settings['paragraph_limit'] = 1;
     new Settings($settings);
     // Unset the parent field name, type and id of paragraph1.
     /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
     $paragraph = Paragraph::load($paragraph1->id());
     $paragraph->set('parent_field_name', NULL);
     $paragraph->set('parent_type', NULL);
     $paragraph->set('parent_id', NULL);
     $paragraph->setNewRevision(FALSE);
     $paragraph->save();
     // Unset the parent field name, type and id of paragraph2.
     $paragraph = Paragraph::load($paragraph2->id());
     $paragraph->set('parent_field_name', NULL);
     $paragraph->set('parent_type', NULL);
     $paragraph->set('parent_id', NULL);
     $paragraph->setNewRevision(FALSE);
     $paragraph->save();
     // Unset the parent field name, type and id of $paragraph_nested_parent.
     $paragraph = Paragraph::load($paragraph4_nested_parent->id());
     $paragraph->set('parent_field_name', NULL);
     $paragraph->set('parent_type', NULL);
     $paragraph->set('parent_id', NULL);
     $paragraph->setNewRevision(FALSE);
     $paragraph->save();
     // Unset the parent field name, type and id of $paragraph_nested_children1.
     $paragraph = Paragraph::load($paragraph_nested_children1->id());
     $paragraph->set('parent_field_name', NULL);
     $paragraph->set('parent_type', NULL);
     $paragraph->set('parent_id', NULL);
     $paragraph->setNewRevision(FALSE);
     $paragraph->save();
     // Unset the parent field name, type and id of paragraph_user_1.
     /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
     $paragraph = Paragraph::load($paragraph_user_1->id());
     $paragraph->set('parent_field_name', NULL);
     $paragraph->set('parent_type', NULL);
     $paragraph->set('parent_id', NULL);
     $paragraph->setNewRevision(FALSE);
     $paragraph->save();
     // Create a revision for node.
     /** @var \Drupal\node\Entity\Node $node_revision1 */
     $node_revision1 = Node::load($node->id());
     /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph1_revision1 */
     $paragraph1_revision1 = Paragraph::load($paragraph1->id());
     $paragraph1_revision1->setNewRevision(TRUE);
     $paragraph1_revision1->save();
     /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph2_revision1 */
     $paragraph2_revision1 = Paragraph::load($paragraph2->id());
     $paragraph2_revision1->setNewRevision(TRUE);
     $paragraph2_revision1->save();
     $node_revision1->set('node_paragraph_field', [$paragraph1_revision1, $paragraph2_revision1]);
     $node_revision1->setNewRevision(TRUE);
     $node_revision1->save();
     // Unset the parent field name, type and id of paragraph2_revision1.
     $paragraph2_revision1 = Paragraph::load($paragraph2_revision1->id());
     $paragraph2_revision1->set('parent_field_name', NULL);
     $paragraph2_revision1->set('parent_type', NULL);
     $paragraph2_revision1->set('parent_id', NULL);
     $paragraph2_revision1->setNewRevision(FALSE);
     $paragraph2_revision1->save();
     // Create another revision for node.
     /** @var \Drupal\node\Entity\Node $node_revision2 */
     $node_revision2 = Node::load($node->id());
     /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph1_revision2 */
     $paragraph1_revision2 = Paragraph::load($paragraph1->id());
     $paragraph1_revision2->setNewRevision(TRUE);
     $paragraph1_revision2->save();
     $node_revision2->set('node_paragraph_field', [$paragraph1_revision2]);
     $node_revision2->setNewRevision(TRUE);
     $node_revision2->save();
     // Deletion of referenced paragraphs should not break updates.
     $paragraph3->delete();
     \Drupal::moduleHandler()->loadInclude('paragraphs', 'post_update.php');
     // Run update function and check #finished.
     $sandbox = [];
     do {
         paragraphs_post_update_set_paragraphs_parent_fields($sandbox);
     } while ($sandbox['#finished'] < 1);
     $node_paragraph1 = Paragraph::load($paragraph1->id())->toArray();
     // Check if the fields are properly set.
     self::assertEquals($node_paragraph1['parent_id'][0]['value'], $node->id());
     self::assertEquals($node_paragraph1['parent_type'][0]['value'], $node->getEntityTypeId());
     self::assertEquals($node_paragraph1['parent_field_name'][0]['value'], 'node_paragraph_field');
     $paragraph1_revision1 = \Drupal::entityTypeManager()->getStorage('paragraph')->loadRevision($paragraph1_revision1->getRevisionId())->toArray();
     self::assertEquals($paragraph1_revision1['parent_id'][0]['value'], $node->id());
     self::assertEquals($paragraph1_revision1['parent_type'][0]['value'], $node->getEntityTypeId());
     self::assertEquals($paragraph1_revision1['parent_field_name'][0]['value'], 'node_paragraph_field');
     $paragraph1_revision2 = \Drupal::entityTypeManager()->getStorage('paragraph')->loadRevision($paragraph1_revision2->getRevisionId())->toArray();
     self::assertEquals($paragraph1_revision2['parent_id'][0]['value'], $node->id());
     self::assertEquals($paragraph1_revision2['parent_type'][0]['value'], $node->getEntityTypeId());
     self::assertEquals($paragraph1_revision2['parent_field_name'][0]['value'], 'node_paragraph_field');
     $node_paragraph2 = Paragraph::load($paragraph2->id())->toArray();
     // Check if the fields are properly set.
     self::assertEquals($node_paragraph2['parent_id'][0]['value'], $node->id());
     self::assertEquals($node_paragraph2['parent_type'][0]['value'], $node->getEntityTypeId());
     self::assertEquals($node_paragraph2['parent_field_name'][0]['value'], 'node_paragraph_field');
     $user_paragraph = Paragraph::load($paragraph_user_1->id())->toArray();
     // Check if the fields are properly set.
     self::assertEquals($user_paragraph['parent_id'][0]['value'], $user->id());
     self::assertEquals($user_paragraph['parent_type'][0]['value'], $user->getEntityTypeId());
     self::assertEquals($user_paragraph['parent_field_name'][0]['value'], 'user_paragraph_field');
     $nested_paragraph_parent = Paragraph::load($paragraph4_nested_parent->id())->toArray();
     // Check if the fields are properly set.
     self::assertEquals($nested_paragraph_parent['parent_id'][0]['value'], $node->id());
     self::assertEquals($nested_paragraph_parent['parent_type'][0]['value'], $node->getEntityTypeId());
     self::assertEquals($nested_paragraph_parent['parent_field_name'][0]['value'], 'node_paragraph_field');
     $nested_paragraph_children = Paragraph::load($paragraph_nested_children1->id())->toArray();
     // Check if the fields are properly set.
     self::assertEquals($nested_paragraph_children['parent_id'][0]['value'], $paragraph4_nested_parent->id());
     self::assertEquals($nested_paragraph_children['parent_type'][0]['value'], $paragraph4_nested_parent->getEntityTypeId());
     self::assertEquals($nested_paragraph_children['parent_field_name'][0]['value'], 'nested_paragraph_field');
 }
Example #12
0
    /**
     * {@inheritdoc}
     */
    protected function setUp()
    {
        $this->keyValueFactory = new KeyValueMemoryFactory();
        // Back up settings from TestBase::prepareEnvironment().
        $settings = Settings::getAll();
        // Allow for test-specific overrides.
        $directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
        $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
        $container_yamls = [];
        if (file_exists($settings_services_file)) {
            // Copy the testing-specific service overrides in place.
            $testing_services_file = $directory . '/services.yml';
            copy($settings_services_file, $testing_services_file);
            $container_yamls[] = $testing_services_file;
        }
        $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
        if (file_exists($settings_testing_file)) {
            // Copy the testing-specific settings.php overrides in place.
            copy($settings_testing_file, $directory . '/settings.testing.php');
        }
        if (file_exists($directory . '/settings.testing.php')) {
            // Add the name of the testing class to settings.php and include the
            // testing specific overrides
            $hash_salt = Settings::getHashSalt();
            $test_class = get_class($this);
            $container_yamls_export = Variable::export($container_yamls);
            $php = <<<EOD
<?php

\$settings['hash_salt'] = '{$hash_salt}';
\$settings['container_yamls'] = {$container_yamls_export};

\$test_class = '{$test_class}';
include DRUPAL_ROOT . '/' . \$site_path . '/settings.testing.php';
EOD;
            file_put_contents($directory . '/settings.php', $php);
        }
        // Add this test class as a service provider.
        // @todo Remove the indirection; implement ServiceProviderInterface instead.
        $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\\simpletest\\TestServiceProvider';
        // Bootstrap a new kernel.
        $class_loader = (require DRUPAL_ROOT . '/autoload.php');
        $this->kernel = new DrupalKernel('testing', $class_loader, FALSE);
        $request = Request::create('/');
        $site_path = DrupalKernel::findSitePath($request);
        $this->kernel->setSitePath($site_path);
        if (file_exists($directory . '/settings.testing.php')) {
            Settings::initialize(DRUPAL_ROOT, $site_path, $class_loader);
        }
        $this->kernel->boot();
        // Ensure database install tasks have been run.
        require_once __DIR__ . '/../../../includes/install.inc';
        $connection = Database::getConnection();
        $errors = db_installer_object($connection->driver())->runTasks();
        if (!empty($errors)) {
            $this->fail('Failed to run installer database tasks: ' . implode(', ', $errors));
        }
        // Reboot the kernel because the container might contain a connection to the
        // database that has been closed during the database install tasks. This
        // prevents any services created during the first boot from having stale
        // database connections, for example, \Drupal\Core\Config\DatabaseStorage.
        $this->kernel->shutdown();
        $this->kernel->boot();
        // Save the original site directory path, so that extensions in the
        // site-specific directory can still be discovered in the test site
        // environment.
        // @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
        $settings['test_parent_site'] = $this->originalSite;
        // Restore and merge settings.
        // DrupalKernel::boot() initializes new Settings, and the containerBuild()
        // method sets additional settings.
        new Settings($settings + Settings::getAll());
        // Create and set new configuration directories.
        $this->prepareConfigDirectories();
        // Set the request scope.
        $this->container = $this->kernel->getContainer();
        $this->container->get('request_stack')->push($request);
        // Re-inject extension file listings into state, unless the key/value
        // service was overridden (in which case its storage does not exist yet).
        if ($this->container->get('keyvalue') instanceof KeyValueMemoryFactory) {
            $this->container->get('state')->set('system.module.files', $this->moduleFiles);
            $this->container->get('state')->set('system.theme.files', $this->themeFiles);
        }
        // Create a minimal core.extension configuration object so that the list of
        // enabled modules can be maintained allowing
        // \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() to work.
        // Write directly to active storage to avoid early instantiation of
        // the event dispatcher which can prevent modules from registering events.
        \Drupal::service('config.storage')->write('core.extension', array('module' => array(), 'theme' => array()));
        // Collect and set a fixed module list.
        $class = get_class($this);
        $modules = array();
        while ($class) {
            if (property_exists($class, 'modules')) {
                // Only add the modules, if the $modules property was not inherited.
                $rp = new \ReflectionProperty($class, 'modules');
                if ($rp->class == $class) {
                    $modules[$class] = $class::$modules;
                }
            }
            $class = get_parent_class($class);
        }
        // Modules have been collected in reverse class hierarchy order; modules
        // defined by base classes should be sorted first. Then, merge the results
        // together.
        $modules = array_reverse($modules);
        $modules = call_user_func_array('array_merge_recursive', $modules);
        if ($modules) {
            $this->enableModules($modules);
        }
        // Tests based on this class are entitled to use Drupal's File and
        // StreamWrapper APIs.
        // @todo Move StreamWrapper management into DrupalKernel.
        // @see https://www.drupal.org/node/2028109
        file_prepare_directory($this->publicFilesDirectory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
        $this->settingsSet('file_public_path', $this->publicFilesDirectory);
        $this->streamWrappers = array();
        $this->registerStreamWrapper('public', 'Drupal\\Core\\StreamWrapper\\PublicStream');
        // The temporary stream wrapper is able to operate both with and without
        // configuration.
        $this->registerStreamWrapper('temporary', 'Drupal\\Core\\StreamWrapper\\TemporaryStream');
    }
Example #13
0
 /**
  * Changes in memory settings.
  *
  * @param $name
  *   The name of the setting to return.
  * @param $value
  *   The value of the setting.
  *
  * @see \Drupal\Core\Site\Settings::get()
  */
 protected function settingsSet($name, $value)
 {
     $settings = Settings::getAll();
     $settings[$name] = $value;
     new Settings($settings);
 }
Example #14
0
 /**
  * @covers ::getAll
  */
 public function testGetAll()
 {
     $this->assertEquals($this->config, Settings::getAll());
 }
Example #15
0
<?php

$copy = \Drupal\Core\Site\Settings::getAll();
$copy['php_storage']['twig']['class'] = "Drupal\\Component\\PhpStorage\\FileStorage";
$foo = new \Drupal\Core\Site\Settings($copy);
require_once "core/themes/engines/twig/twig.engine";
while ($f = trim(fgets(STDIN))) {
    if (stripos($f, 'tests') === FALSE) {
        twig_render_template(substr($f, 2), []);
    }
}
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->keyValueFactory = new KeyValueMemoryFactory();
     // Allow for test-specific overrides.
     $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
     if (file_exists($settings_services_file)) {
         // Copy the testing-specific service overrides in place.
         copy($settings_services_file, DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml');
     }
     // Create and set new configuration directories.
     $this->prepareConfigDirectories();
     // Add this test class as a service provider.
     // @todo Remove the indirection; implement ServiceProviderInterface instead.
     $GLOBALS['conf']['container_service_providers']['TestServiceProvider'] = 'Drupal\\simpletest\\TestServiceProvider';
     // Back up settings from TestBase::prepareEnvironment().
     $settings = Settings::getAll();
     // Bootstrap a new kernel. Don't use createFromRequest so we don't mess with settings.
     $class_loader = (require DRUPAL_ROOT . '/core/vendor/autoload.php');
     $this->kernel = new DrupalKernel('testing', $class_loader, FALSE);
     $request = Request::create('/');
     $this->kernel->setSitePath(DrupalKernel::findSitePath($request));
     $this->kernel->boot();
     // Restore and merge settings.
     // DrupalKernel::boot() initializes new Settings, and the containerBuild()
     // method sets additional settings.
     new Settings($settings + Settings::getAll());
     // Set the request scope.
     $this->container = $this->kernel->getContainer();
     $this->container->get('request_stack')->push($request);
     // Re-inject extension file listings into state, unless the key/value
     // service was overridden (in which case its storage does not exist yet).
     if ($this->container->get('keyvalue') instanceof KeyValueMemoryFactory) {
         $this->container->get('state')->set('system.module.files', $this->moduleFiles);
         $this->container->get('state')->set('system.theme.files', $this->themeFiles);
     }
     // Create a minimal core.extension configuration object so that the list of
     // enabled modules can be maintained allowing
     // \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() to work.
     // Write directly to active storage to avoid early instantiation of
     // the event dispatcher which can prevent modules from registering events.
     \Drupal::service('config.storage')->write('core.extension', array('module' => array(), 'theme' => array()));
     // Collect and set a fixed module list.
     $class = get_class($this);
     $modules = array();
     while ($class) {
         if (property_exists($class, 'modules')) {
             // Only add the modules, if the $modules property was not inherited.
             $rp = new \ReflectionProperty($class, 'modules');
             if ($rp->class == $class) {
                 $modules[$class] = $class::$modules;
             }
         }
         $class = get_parent_class($class);
     }
     // Modules have been collected in reverse class hierarchy order; modules
     // defined by base classes should be sorted first. Then, merge the results
     // together.
     $modules = array_reverse($modules);
     $modules = call_user_func_array('array_merge_recursive', $modules);
     if ($modules) {
         $this->enableModules($modules);
     }
     // In order to use theme functions default theme config needs to exist.
     \Drupal::config('system.theme')->set('default', 'stark');
     // Tests based on this class are entitled to use Drupal's File and
     // StreamWrapper APIs.
     // @todo Move StreamWrapper management into DrupalKernel.
     // @see https://drupal.org/node/2028109
     file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
     $this->settingsSet('file_public_path', $this->public_files_directory);
     $this->streamWrappers = array();
     $this->registerStreamWrapper('public', 'Drupal\\Core\\StreamWrapper\\PublicStream');
     // The temporary stream wrapper is able to operate both with and without
     // configuration.
     $this->registerStreamWrapper('temporary', 'Drupal\\Core\\StreamWrapper\\TemporaryStream');
 }
Example #17
0
 /**
  * Sets an in-memory Settings variable.
  *
  * @param string $name
  *   The name of the setting to set.
  * @param bool|string|int|array|null $value
  *   The value to set. Note that array values are replaced entirely; use
  *   \Drupal\Core\Site\Settings::get() to perform custom merges.
  */
 protected function setSetting($name, $value)
 {
     $settings = Settings::getInstance() ? Settings::getAll() : [];
     $settings[$name] = $value;
     new Settings($settings);
 }