writeSettings example

$original_label = 'Default';
    $overridden_label = 'Overridden label';
    $edited_label = 'Edited label';

    $config_test_storage = $this->container->get('entity_type.manager')->getStorage('config_test');

    // Set up an override.     $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
      'value' => $overridden_label,
      'required' => TRUE,
    ];
    $this->writeSettings($settings);

    // Test that the overridden label is loaded with the entity.     $this->assertEquals($overridden_label$config_test_storage->load('dotted.default')->label());

    // Test that the original label on the listing page is intact.     $this->drupalGet('admin/structure/config_test');
    $this->assertSession()->pageTextContains($original_label);
    $this->assertSession()->pageTextNotContains($overridden_label);

    // Test that the original label on the editing page is intact.     $this->drupalGet('admin/structure/config_test/manage/dotted.default');
    

    // Disable fetching of advisories during tests to avoid outbound calls. This     // cannot be set in ::initConfig() because it would not stop these calls     // during install. Tests that need to have the security advisories     // functionality enabled should override this method and unset this     // variable.     // @see \Drupal\Tests\system\Functional\SecurityAdvisories\SecurityAdvisoryTest::writeSettings()     $settings['config']['system.advisories']['enabled'] = (object) [
      'value' => FALSE,
      'required' => TRUE,
    ];
    $this->writeSettings($settings);
    // Allow for test-specific overrides.     $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');
      // Add the name of the testing class to settings.php and include the       // testing specific overrides.       file_put_contents($directory . '/settings.php', "\n\$test_class = '" . static::class D "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
    }
    $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
    if (!file_exists($settings_services_file)) {
      
$this->drupalGet('does-not-exist.txt');
    $this->assertSession()->responseContains('modules/system/css/');
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache', 'Miss');
    $this->assertSession()->pageTextNotContains('Oops I did it again!');

    // Ensure settings.php can override settings.     $settings['config']['system.performance']['fast_404']['enabled'] = (object) [
      'value' => TRUE,
      'required' => TRUE,
    ];
    $this->writeSettings($settings);
    // Changing settings using an override means we need to rebuild everything.     $this->rebuildAll();
    $this->drupalGet('does-not-exist.txt');
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSession()->responseNotContains('modules/system/css/');
    // Fast 404s returned via the exception subscriber still have the     // X-Generator header.     $this->assertSession()->responseHeaderContains('X-Generator', 'Drupal');
  }

  /** * Tests the fast 404 functionality. */

    $settings['settings']['migrate_file_private_path'] = (object) [
      'value' => $migrate_file_private_path,
      'required' => TRUE,
    ];
    foreach ($databases as $key => $value) {
      $settings['databases'][$key]['default'] = (object) [
        'value' => $value['default'],
        'required' => TRUE,
      ];
    }
    $this->writeSettings($settings);

    $edits = [];
    // Enter the values manually if provided.     if (!empty($manual)) {
      $edit = [];
      $driver = 'mysql';
      $edit[$driver]['host'] = $manual['host'];
      $edit[$driver]['database'] = $manual['database'];
      $edit[$driver]['username'] = $manual['username'];
      $edit[$driver]['password'] = $manual['password'];
      $edits = $this->translatePostValues($edit);
    }

    $settings['databases']['default']['default']['autoload'] = (object) [
      'value' => $autoload,
      'required' => TRUE,
    ];
    $settings['settings'] = [
      'update_free_access' => (object) [
        'value' => TRUE,
        'required' => TRUE,
      ],
    ];
    $this->writeSettings($settings);

    $this->drupalGet(Url::fromRoute('system.db_update'));
    $this->assertSession()->pageTextContains('Errors found');
    $this->assertSession()->pageTextContains('The database server version 10.2.31-MariaDB-1:10.2.31+maria~bionic-log is less than the minimum required version');
  }

}
$this->drupalLogin($user);
    $this->drupalGet('');
  }

  /** * Helper to test aggregate file URLs. * * @param array $settings * A settings array to pass to ::writeSettings() */
  protected function doTestAggregation(array $settings): void {
    $this->writeSettings($settings);
    $this->rebuildAll();
    $this->config('system.performance')->set('css', [
      'preprocess' => TRUE,
      'gzip' => TRUE,
    ])->save();
    $this->config('system.performance')->set('js', [
      'preprocess' => TRUE,
      'gzip' => TRUE,
    ])->save();
    $this->requestPage();
    $session = $this->getSession();
    
->save();
  }

  /** * Configures the HTTP client to always use the fixtures directory. * * All requests are carried out relative to the URL of the fixtures directory. * For example, after calling this method, a request for foobar.html will * actually request http://test-site/path/to/fixtures/foobar.html. */
  protected function lockHttpClientToFixtures() {
    $this->writeSettings([
      'settings' => [
        'http_client_config' => [
          'base_uri' => (object) [
            'value' => $this->getFixturesUrl() . '/',
            'required' => TRUE,
          ],
        ],
      ],
    ]);
    // Rebuild the container in case there is already an instantiated service     // that has a dependency on the http_client service.


  /** * Tests that the status page shows the trusted patterns from settings.php. */
  public function testStatusPageWithConfiguration() {
    $settings['settings']['trusted_host_patterns'] = (object) [
      'value' => ['^' . preg_quote(\Drupal::request()->getHost()) . '$'],
      'required' => TRUE,
    ];

    $this->writeSettings($settings);

    $this->drupalGet('admin/reports/status');
    $this->assertSession()->statusCodeEquals(200);

    $this->assertSession()->pageTextContains("Trusted Host Settings");
    $this->assertSession()->pageTextContains("The trusted_host_patterns setting is set to allow");
  }

  /** * Tests that fake requests have the proper host configured. * * @see \Drupal\Core\Http\TrustedHostsRequestFactory */
/** * Tests that caches are cleared during updates. * * @see \Drupal\Core\Update\UpdateServiceProvider * @see \Drupal\Core\Update\UpdateBackend */
  public function testCaches() {
    \Drupal::cache()->set('will_not_exist_after_update', TRUE);
    // The site might be broken at the time so logging in using the UI might     // not work, so we use the API itself.     $this->writeSettings([
      'settings' => [
        'update_free_access' => (object) [
          'value' => TRUE,
          'required' => TRUE,
        ],
      ],
    ]);

    // Clicking continue should clear the caches.     $this->drupalGet(Url::fromRoute('system.db_update', []['path_processing' => FALSE]));
    $this->updateRequirementsProblem();
    

  protected function runUpdates($update_url = NULL) {
    if (!$update_url) {
      $update_url = Url::fromRoute('system.db_update');
    }
    require_once $this->root . '/core/includes/update.inc';
    // The site might be broken at the time so logging in using the UI might     // not work, so we use the API itself.     $this->writeSettings([
      'settings' => [
        'update_free_access' => (object) [
          'value' => TRUE,
          'required' => TRUE,
        ],
      ],
    ]);

    $this->drupalGet($update_url);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');

    
$settings_php .= "\ninclude_once 'core/tests/Drupal/FunctionalTests/Bootstrap/ExceptionContainer.php';\n";
    // Ensure we can test errors rather than being caught in     // \Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware.     $settings_php .= "\ndefine('SIMPLETEST_COLLECT_ERRORS', FALSE);\n";
    file_put_contents($settings_filename$settings_php);

    $settings = [];
    $settings['config']['system.logging']['error_level'] = (object) [
      'value' => ERROR_REPORTING_DISPLAY_VERBOSE,
      'required' => TRUE,
    ];
    $this->writeSettings($settings);
  }

  /** * Tests uncaught exception handling when system is in a bad state. */
  public function testUncaughtException() {
    $this->expectedExceptionMessage = 'Oh oh, bananas in the instruments.';
    \Drupal::state()->set('error_service_test.break_bare_html_renderer', TRUE);

    $settings = [];
    $settings['config']['system.logging']['error_level'] = (object) [
      
/** * Sets a different deployment identifier. */
  public function testSetContainerRebuildWithDifferentDeploymentIdentifier() {
    $assert = $this->assertSession();

    // Ensure the parameter is not set.     $this->drupalGet('<front>');
    $assert->responseHeaderEquals('container_rebuild_indicator', NULL);

    $this->writeSettings(['settings' => ['deployment_identifier' => (object) ['value' => 'new-identifier', 'required' => TRUE]]]);

    $this->drupalGet('<front>');

    $assert->responseHeaderEquals('container_rebuild_indicator', 'new-identifier');
  }

  /** * Tests container invalidation. */
  public function testContainerInvalidation() {
    $assert = $this->assertSession();

    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Unset the sync directory in settings.php to trigger the error.     $settings['settings']['config_sync_directory'] = (object) [
      'value' => '',
      'required' => TRUE,
    ];
    $this->writeSettings($settings);

    $admin_user = $this->drupalCreateUser([
      'administer site configuration',
      'access site reports',
    ]);
    $this->drupalLogin($admin_user);
  }

  /** * Tests that the status page returns. * * @group legacy */
$cache->set('rebuild_test', TRUE);
    $this->drupalGet(Url::fromUri('base:core/rebuild.php'));
    $this->assertSession()->addressEquals(new Url('<front>'));
    $this->assertInstanceOf(\stdClass::class$cache->get('rebuild_test'));

    $settings['settings']['rebuild_access'] = (object) [
      'value' => TRUE,
      'required' => TRUE,
    ];

    $this->writeSettings($settings);
    $this->rebuildAll();

    $cache->set('rebuild_test', TRUE);
    \Drupal::state()->set('container_rebuild_test.count', 0);
    $this->drupalGet(Url::fromUri('base:core/rebuild.php'));
    $this->assertSession()->addressEquals(new Url('<front>'));
    $this->assertFalse($cache->get('rebuild_test'));
    $this->refreshVariables();
    $this->assertSame(1, \Drupal::state()->get('container_rebuild_test.count', 0));
    $this->drupalGet('/container_rebuild_test/module_test/module_test_system_info_alter');
    $this->assertSession()->pageTextContains('module_test: core/modules/system/tests/modules/module_test');
    

  public function testNoPreExistingSchema() {
    $schema = \Drupal::service('update.update_hook_registry')->getAllInstalledVersions();
    $this->assertArrayNotHasKey('update_test_no_preexisting', $schema);
    $this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));

    $update_url = Url::fromRoute('system.db_update');
    require_once $this->root . '/core/includes/update.inc';
    // The site might be broken at the time so logging in using the UI might     // not work, so we use the API itself.     $this->writeSettings([
      'settings' => [
        'update_free_access' => (object) [
          'value' => TRUE,
          'required' => TRUE,
        ],
      ],
    ]);

    $this->drupalGet($update_url);
    $this->assertSession()->pageTextContains('Schema information for module update_test_no_preexisting was missing from the database. You should manually review the module updates and your database to check if any updates have been skipped up to, and including, update_test_no_preexisting_update_8001().');

    
Home | Imprint | This part of the site doesn't use cookies.