getEditable example

/** * Tests getDefaultConfigLangcode(). */
  public function testGetDefaultConfigLangcode() {
    // Install the Language module's configuration so we can use the     // module_installer service.     $this->installConfig(['language']);
    $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'Before installing a module the locale config manager can not access the shipped configuration.');
    \Drupal::service('module_installer')->install(['locale_test_translate']);
    $this->assertEquals('en', \Drupal::service('locale.config_manager')->getDefaultConfigLangcode('locale_test_translate.settings'), 'After installing a module the locale config manager can get the shipped configuration langcode.');

    $simple_config = \Drupal::configFactory()->getEditable('locale_test_translate.simple_config_extra');
    $simple_config->set('foo', 'bar')->save();
    $this->assertNull(\Drupal::service('locale.config_manager')->getDefaultConfigLangcode($simple_config->getName()), 'Simple config created through the API is not treated as shipped configuration.');

    $block = Block::create([
      'id' => 'test_default_config',
      'theme' => 'stark',
      'status' => TRUE,
      'region' => 'content',
      'plugin' => 'local_tasks_block',
      'settings' => [
        'id' => 'local_tasks_block',
        
$this->assertSession()->linkByHrefExists('page=3', 0, '4th page link is found for keyword search.');
    $this->assertSession()->linkByHrefNotExists('page=4', '5th page link is not found for keyword search.');

    // Test that the correct number of pager links are found for exact phrase search.     $edit = ['keys' => '"love pizza"'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->linkByHrefExists('page=1', 0, '2nd page link is found for exact phrase search.');
    $this->assertSession()->linkByHrefNotExists('page=2', '3rd page link is not found for exact phrase search.');

    // Check that with post settings turned on the post information is displayed.     $node_type_config = \Drupal::configFactory()->getEditable('node.type.page');
    $node_type_config->set('display_submitted', TRUE);
    $node_type_config->save();

    $edit = ['keys' => 'Druplicon'];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $this->assertSession()->pageTextContains($user->getAccountName());
    $this->assertSession()->pageTextContains($this->container->get('date.formatter')->format($node->getChangedTime(), 'short'));

    // Check that with post settings turned off the user and changed date     // information is not displayed.

  protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->lockHttpClientToFixtures();

    \Drupal::configFactory()
      ->getEditable('media.settings')
      ->set('standalone_url', TRUE)
      ->save(TRUE);

    $this->container->get('router.builder')->rebuild();
  }

  /** * Data provider for testRender(). * * @see ::testRender() * * @return array */
      $this->drupalGet('system-test/get-destination', ['query' => ['destination' => $test_case['input']]]);
      $this->assertSame($test_case['output']$session->getPage()->getContent()$test_case['message']);
      // Test $_REQUEST['destination'].       $post_output = $http_client->request('POST', $this->buildUrl('system-test/request-destination')[
        'form_params' => ['destination' => $test_case['input']],
      ]);
      $this->assertSame($test_case['output'](string) $post_output->getBody()$test_case['message']);
    }

    // Make sure that 404 pages do not populate $_GET['destination'] with     // external URLs.     \Drupal::configFactory()->getEditable('system.site')->set('page.404', '/system-test/get-destination')->save();
    $this->drupalGet('http://example.com', ['external' => FALSE]);
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSame(Url::fromRoute('<front>')->toString()$session->getPage()->getContent(), 'External URL is not allowed on 404 pages.');
  }

}

  protected function setUp(): void {
    parent::setUp();
    $moduleHandler = $this->container->get('module_handler');
    $moduleHandler->loadInclude('locale', 'inc', 'locale.batch');
    ConfigurableLanguage::createFromLangcode('de')->save();

    // Let the translations:// stream wrapper point to a virtual file system to     // make it independent from the test environment.     $this->translationsStream = vfsStream::setup('translations');
    \Drupal::configFactory()->getEditable('locale.settings')
      ->set('translation.path', $this->translationsStream->url())
      ->save();
  }

  /** * Tests translation download from remote sources. */
  public function testUpdateImportSourceRemote() {

    // Provide remote and 'previously' downloaded translation file.     $this->setTranslationFiles();
    

    $this->drupalLogin($admin_user);

    $config = $this->config('language.types');
    $config->set('configurable', [LanguageInterface::TYPE_INTERFACE]);
    $config->set('negotiation.language_content.enabled', [
      LanguageNegotiationUrl::METHOD_ID => 1,
      LanguageNegotiationSelected::METHOD_ID => 1,
    ]);
    $config->save();

    \Drupal::configFactory()->getEditable('language.negotiation')
      ->set('url.prefixes.aa', 'aa')
      ->set('url.prefixes.bb', 'bb')
      ->set('url.prefixes.cc', 'cc')
      ->set('selected_langcode', 'dd')
      ->save();

    // Set default language code for content type page to 'dd'.     ContentLanguageSettings::loadByEntityTypeBundle('node', 'page')
      ->setDefaultLangcode('dd')
      ->setLanguageAlterable(TRUE)
      ->save();
    
'status' => TRUE,
      ])
      ->shouldBeCalled();
    $config_object->save(FALSE)->shouldBeCalled();
    $config_object->get()->willReturn([]);

    $this->cacheTagsInvalidator->invalidateTags([$this->entityTypeId . '_list'])
      ->shouldBeCalled();

    $this->configFactory->get('the_provider.the_config_prefix.foo')
      ->willReturn($immutable_config_object->reveal());
    $this->configFactory->getEditable('the_provider.the_config_prefix.foo')
      ->willReturn($config_object->reveal());

    $this->moduleHandler->invokeAll('test_entity_type_presave', [$entity])
      ->shouldBeCalled();
    $this->moduleHandler->invokeAll('entity_presave', [$entity, 'test_entity_type'])
      ->shouldBeCalled();
    $this->moduleHandler->invokeAll('test_entity_type_insert', [$entity])
      ->shouldBeCalled();
    $this->moduleHandler->invokeAll('entity_insert', [$entity, 'test_entity_type'])
      ->shouldBeCalled();

    
/** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['image_jpeg_quality'] = [
      '#type' => 'number',
      '#title' => $this->t('JPEG quality'),
      '#description' => $this->t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
      '#min' => 0,
      '#max' => 100,
      '#default_value' => $this->configFactory->getEditable('system.image.gd')->get('jpeg_quality', FALSE),
      '#field_suffix' => $this->t('%'),
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configFactory->getEditable('system.image.gd')
      ->set('jpeg_quality', $form_state->getValue(['gd', 'image_jpeg_quality']))
      

  protected function setUp($import_test_views = TRUE): void {
    parent::setUp();
  }

  /** * {@inheritdoc} */
  protected function setUpFixtures() {
    // Install the themes used for this test.     $this->container->get('theme_installer')->install(['olivero']);
    $this->container->get('config.factory')->getEditable('system.theme')->set('default', 'olivero')->save();

    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test');
    $this->installConfig(['entity_test']);

    $this->placeBlock('system_main_block', ['id' => 'test_block']);

    parent::setUpFixtures();
  }

  /** * Tests views data for entity area handlers. */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    if (empty(static::$themes)) {
      throw new \Exception('You need to set the protected static $themes property on your test class, with the first item being the default theme.');
    }
    $this->container->get('theme_installer')->install(static::$themes);
    $this->installConfig('system');

    $system_theme_config = $this->container->get('config.factory')->getEditable('system.theme');
    $system_theme_config
      ->set('default', reset(static::$themes))
      ->save();
    $this->negotiator = new ComponentNegotiator(
      \Drupal::service('theme.manager'),
      \Drupal::service('extension.list.module'),
    );
    $this->manager = \Drupal::service('plugin.manager.sdc');
  }

}
protected static $patchProtectedFieldNames = [
    'changed' => NULL,
  ];

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

    \Drupal::configFactory()
      ->getEditable('media.settings')
      ->set('standalone_url', TRUE)
      ->save(TRUE);

    // Provisioning the Media REST resource without the File REST resource does     // not make sense.     $this->resourceConfigStorage->create([
      'id' => 'entity.file',
      'granularity' => RestResourceConfigInterface::RESOURCE_GRANULARITY,
      'configuration' => [
        'methods' => ['GET'],
        'formats' => [static::$format],
        
// Verify the active configuration contains the updated value.     $actual_data = $storage->read($name);
    $this->assertSame(['value' => 'instance-update']$actual_data);

    // Verify a call to $this->config() immediately returns the updated value.     $new_config = $this->config($name);
    $this->assertSame($config->get()$new_config->get());
    $this->assertFalse($config->isNew());

    // Pollute the config factory static cache.     $config_factory->getEditable($name);

    // Delete the config object that uses a custom collection. This should not     // affect the instance returned by the config factory which depends on the     // default collection storage.     $collection_config->delete();
    $actual_config = $config_factory->get($name);
    $this->assertFalse($actual_config->isNew());
    $this->assertSame(['value' => 'instance-update']$actual_config->getRawData());

    // Delete the configuration object.     $config->delete();

    
if (method_exists($this, 'configFactory')) {
      $config_factory = $this->configFactory();
    }
    elseif (property_exists($this, 'configFactory')) {
      $config_factory = $this->configFactory;
    }
    if (!isset($config_factory) || !($config_factory instanceof ConfigFactoryInterface)) {
      throw new \LogicException('No config factory available for ConfigFormBaseTrait');
    }
    if (in_array($name$this->getEditableConfigNames())) {
      // Get a mutable object from the factory.       $config = $config_factory->getEditable($name);
    }
    else {
      $config = $config_factory->get($name);
    }
    return $config;
  }

  /** * Gets the configuration names that will be editable. * * @return array * An array of configuration object names that are editable if called in * conjunction with the trait's config() method. */

  public function testAdminTheme(): void {
    $account = $this->drupalCreateUser(['view the administration theme']);
    $this->drupalLogin($account);
    // Use distinct default and administrative themes for this test.     /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = $this->container->get('theme_installer');
    $theme_installer->install(['claro']);
    $this->container->get('config.factory')
      ->getEditable('system.theme')
      ->set('admin', 'claro')
      ->set('default', 'stable')
      ->save();
    $theme_handler->refreshInfo();
    // Check that the page has been served with the default theme.     $this->drupalGet('test_page_display_200');
    $this->assertSession()->responseNotContains('core/themes/claro/css/base/elements.css');

    $view = $this->config('views.view.test_page_display');
    $view->set('display.page_3.display_options.use_admin_theme', TRUE)->save();
    $this->container->get('router.builder')->rebuild();

    
protected $account;

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

    ViewTestData::createTestViews(static::class['views_test_config']);

    // Disable automatic live preview to make the sequence of calls clearer.     \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();

    $this->account = $this->drupalCreateUser(['administer views']);
    $this->drupalLogin($this->account);

    // Setup a node type that has the right fields for the test view.     NodeType::create([
      'type' => 'page',
    ])->save();

    FieldConfig::create([
      'entity_type' => 'node',
      
Home | Imprint | This part of the site doesn't use cookies.