runUpdates example

__DIR__ . '/../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz',
    ];
  }

  /** * Tests that, after update 10101, the 'wid' column can be a 64-bit integer. */
  public function testLogEntryWithBigId() {
    if (PHP_INT_SIZE < 8) {
      $this->markTestSkipped('This test can only be run on a system that supports 64-bit integers (i.e., PHP_INT_SIZE is 8).');
    }
    $this->runUpdates();

    global $base_root;

    $connection = Database::getConnection();
    // Insert a row with a big value for wid.     $insert = $connection->insert('watchdog');
    $insert->fields([
      'wid'         => 2147483647000,
      'message'     => 'Dblog test log message with big WID',
      'type'        => 'test',
      'variables'   => '',
      
->getConfiguration();
        $filter_html_config['settings']['allowed_html'] = str_replace('data-foo', '', $filter_html_config['settings']['allowed_html']);
        $format->setFilterConfig('filter_html', $filter_html_config);
      }
    }
    $format->trustData()->save();
    $editor->trustData()->save();

    // Run update path; snapshot the Text Format and Editor before and after.     $editor_before = Editor::load('test_format_image');
    $filter_format_before = $editor->getFilterFormat();
    $this->runUpdates();
    $editor_after = Editor::load('test_format_image');
    $filter_format_after = $editor->getFilterFormat();

    // 1. Toolbar item: `uploadImage` -> `drupalInsertImage`, position must be     // unchanged.     $this->assertContains('uploadImage', $editor_before->getSettings()['toolbar']['items']);
    $this->assertNotContains('drupalInsertImage', $editor_before->getSettings()['toolbar']['items']);
    $this->assertNotContains('uploadImage', $editor_after->getSettings()['toolbar']['items']);
    $this->assertContains('drupalInsertImage', $editor_after->getSettings()['toolbar']['items']);
    $this->assertSame(
      array_search('uploadImage', $editor_before->getSettings()['toolbar']['items']),
      

  }

  /** * Tests system_post_update_linkset_settings(). */
  public function testSystemPostUpdateLinksetSettings() {
    // Ensure config is not present.     $config = $this->config('system.feature_flags');
    $this->assertTrue($config->isNew());

    $this->runUpdates();

    // Confirm that config was created and the endpoint is disabled.     $updated_config = $this->config('system.feature_flags');
    $this->assertFalse($updated_config->isNew());
    $this->assertFalse($updated_config->get('linkset_endpoint'));
  }

}

  }

  /** * Ensure settings for CKEditor 5 plugins are sorted by plugin key. */
  public function testUpdatePluginSettingsSortPostUpdate(): void {
    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_before = array_keys($settings['plugins']);

    $this->runUpdates();

    $editor = Editor::load('basic_html');
    $settings = $editor->getSettings();
    $plugin_settings_after = array_keys($settings['plugins']);

    // Different sort before and after, but the same values.     $this->assertNotSame($plugin_settings_before$plugin_settings_after);
    sort($plugin_settings_before);
    $this->assertSame($plugin_settings_before$plugin_settings_after);
  }

  
$this->assertSession()->elementNotExists('xpath', '//main//a[contains(@href, "update.php")]');
    $this->clickLink('Administration pages');
    $this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests update.php after performing a successful update. */
  public function testSuccessfulUpdateFunctionality() {
    $initial_maintenance_mode = $this->container->get('state')->get('system.maintenance_mode');
    $this->assertNull($initial_maintenance_mode, 'Site is not in maintenance mode.');
    $this->runUpdates($initial_maintenance_mode);
    $final_maintenance_mode = $this->container->get('state')->get('system.maintenance_mode');
    $this->assertEquals($initial_maintenance_mode$final_maintenance_mode, 'Maintenance mode should not have changed after database updates.');

    // Reset the static cache to ensure we have the most current setting.     $this->resetAll();
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $schema_version = $update_registry->getInstalledVersion('update_script_test');
    $this->assertEquals(8001, $schema_version, 'update_script_test schema version is 8001 after updating.');

    // Set the installed schema version to one less than the current update.
protected function setDatabaseDumpFiles() {
    parent::setDatabaseDumpFiles();
    $this->databaseDumpFiles[0] = __DIR__ . '/../../../../tests/fixtures/update/drupal-9.4.0.filled.standard.php.gz';
  }

  /** * Tests that the content and configuration were properly updated. */
  public function testUpdatedSite() {
    $assert_session = $this->assertSession();

    $this->runUpdates();

    $spanish = \Drupal::languageManager()->getLanguage('es');

    $expected_node_data = [
      [1, 'article', 'en', 'Test Article - New title'],
      [2, 'book', 'en', 'Book page'],
      [4, 'page', 'en', 'Test page'],
      [8, 'test_content_type', 'en', 'Test title'],
    ];
    foreach ($expected_node_data as $node_data) {
      $id = $node_data[0];
      

  public function testUpdate(): void {
    $mappings = ResponsiveImageStyle::load('responsive_image_style')->getImageStyleMappings();
    $this->assertEquals('1.5x', $mappings[0]['multiplier']);
    $this->assertEquals('2x', $mappings[1]['multiplier']);
    $this->assertEquals('1x', $mappings[2]['multiplier']);

    $this->runUpdates();

    $mappings = ResponsiveImageStyle::load('responsive_image_style')->getImageStyleMappings();
    $this->assertEquals('1x', $mappings[0]['multiplier']);
    $this->assertEquals('1.5x', $mappings[1]['multiplier']);
    $this->assertEquals('2x', $mappings[2]['multiplier']);
  }

  /** * Test ResponsiveImageStyle::preSave correctly orders by multiplier weight. * * @covers ::orderMultipliersNumerically */
$connection->update('key_value')
      ->fields(['value' => serialize($schema)])
      ->condition('collection', 'entity.storage_schema.sql')
      ->condition('name', 'entity_test_update.field_schema_data.name')
      ->execute();
  }

  /** * Tests that a pre-existing initial key in the field schema is not a change. */
  public function testInitialIsIgnored() {
    $this->runUpdates();
  }

}


  /** * Tests upgrading filter settings. * * @see editor_post_update_image_lazy_load() */
  public function testUpdateLazyImageLoad(): void {
    $config = $this->config('filter.format.full_html');
    $this->assertArrayNotHasKey('filter_image_lazy_load', $config->get('filters'));

    $this->runUpdates();

    $config = $this->config('filter.format.full_html');
    $filters = $config->get('filters');
    $this->assertArrayHasKey('filter_image_lazy_load', $filters);
    $this->assertEquals($filters['editor_file_reference']['weight'] + 1, $filters['filter_image_lazy_load']['weight']);
  }

}
$this->assertArrayHasKey('field_test-revision_id_1', $fields);
    $this->assertEquals('field_test-revision_id_1', $fields['field_test-revision_id_1']['id']);
    $this->assertEquals('field_test-revision_id', $fields['field_test-revision_id_1']['field']);
    $this->assertEquals('Replace: {{ field_test-revision_id_1 }}', $fields['field_test-revision_id_1']['alter']['text']);

    $this->assertArrayHasKey('field_test-revision_id_2', $fields);
    $this->assertEquals('field_test-revision_id_2', $fields['field_test-revision_id_2']['id']);
    $this->assertEquals('field_test-revision_id', $fields['field_test-revision_id_2']['field']);
    $this->assertEquals('field_test-revision_id_2: {{ field_test-revision_id_2 }}', $fields['field_test-revision_id_2']['alter']['text']);

    $this->runUpdates();

    $view = View::load('test_fix_revision_id_update');
    $data = $view->toArray();
    $fields = $data['display']['default']['display_options']['fields'];

    $this->assertArrayNotHasKey('field_test-revision_id_1', $fields);
    $this->assertArrayHasKey('field_test__revision_id_1', $fields);
    $this->assertEquals('field_test__revision_id_1', $fields['field_test__revision_id_1']['id']);
    $this->assertEquals('field_test__revision_id', $fields['field_test__revision_id_1']['field']);
    $this->assertEquals('Replace: {{ field_test__revision_id_1 }}', $fields['field_test__revision_id_1']['alter']['text']);

    

  }

  /** * Ensure default configuration for the CKEditor 5 codeBlock plugin is added. */
  public function testUpdateCodeBlockConfigurationPostUpdate(): void {
    $editor = Editor::load('full_html');
    $settings = $editor->getSettings();
    $this->assertArrayNotHasKey('ckeditor5_codeBlock', $settings['plugins']);

    $this->runUpdates();

    $editor = Editor::load('full_html');
    $settings = $editor->getSettings();
    $this->assertArrayHasKey('ckeditor5_codeBlock', $settings['plugins']);
    // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\CodeBlock::defaultConfiguration()     $this->assertSame([
      'languages' => [
        ['label' => 'Plain text', 'language' => 'plaintext'],
        ['label' => 'C', 'language' => 'c'],
        ['label' => 'C#', 'language' => 'cs'],
        ['label' => 'C++', 'language' => 'cpp'],
        [

  protected function doSelectionTest() {
    // Ensure that normal and post_update updates are merged together on the     // selection page.     $this->assertSession()->responseContains('<ul><li>8001 - Normal update_N() function.</li><li>First update.</li><li>Second update.</li><li>Test0 update.</li><li>Test1 update.</li><li>Testing batch processing in post updates update.</li></ul>');
  }

  /** * Tests hook_post_update_NAME(). */
  public function testPostUpdate() {
    $this->runUpdates();

    $this->assertSession()->responseContains('<h3>Update first</h3>');
    $this->assertSession()->pageTextContains('First update');
    $this->assertSession()->responseContains('<h3>Update second</h3>');
    $this->assertSession()->pageTextContains('Second update');
    $this->assertSession()->responseContains('<h3>Update test1</h3>');
    $this->assertSession()->pageTextContains('Test1 update');
    $this->assertSession()->responseContains('<h3>Update test0</h3>');
    $this->assertSession()->pageTextContains('Test0 update');
    $this->assertSession()->responseContains('<h3>Update test_batch</h3>');
    $this->assertSession()->pageTextContains('Test post update batches');

    
/** * Tests that there is no active workspace during database updates. */
  public function testActiveWorkspaceDuringUpdate() {
    /** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
    $workspace_manager = \Drupal::service('workspaces.manager');

    // Check that we have an active workspace before running the updates.     $this->assertTrue($workspace_manager->hasActiveWorkspace());
    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());

    $this->runUpdates();

    // Check that we didn't have an active workspace while running the updates.     // @see workspace_update_test_post_update_check_active_workspace()     $this->assertFalse(\Drupal::state()->get('workspace_update_test.has_active_workspace'));

    // Check that we have an active workspace after running the updates.     $workspace_manager = \Drupal::service('workspaces.manager');
    $this->assertTrue($workspace_manager->hasActiveWorkspace());
    $this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
  }

}
/** * Tests adding 'delete own files' permission. */
  public function testUpdate(): void {
    $roles = Role::loadMultiple();
    $this->assertGreaterThan(2, count($roles));
    foreach ($roles as $role) {
      $permissions = $role->toArray()['permissions'];
      $this->assertNotContains('delete own files', $permissions);
    }

    $this->runUpdates();

    $role = Role::load(Role::ANONYMOUS_ID);
    $permissions = $role->toArray()['permissions'];
    $this->assertNotContains('delete own files', $permissions);

    $role = Role::load(Role::AUTHENTICATED_ID);
    $permissions = $role->toArray()['permissions'];
    $this->assertContains('delete own files', $permissions);

    // Admin roles have the permission and do not need assigned.     $role = Role::load('administrator');
    

  public function testUpdate(): void {
    $this->expectDeprecation('The oEmbed loading attribute update for view display "media.remote_video.default" is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Profile, module and theme provided configuration should be updated to accommodate the changes described at https://www.drupal.org/node/3275103.');
    $data = EntityViewDisplay::load('media.remote_video.default')->toArray();
    $this->assertArrayNotHasKey('loading', $data['content']['field_media_oembed_video']['settings']);

    $this->runUpdates();

    $data = EntityViewDisplay::load('media.remote_video.default')->toArray();
    $this->assertArrayHasKey('loading', $data['content']['field_media_oembed_video']['settings']);
    $this->assertEquals('eager', $data['content']['field_media_oembed_video']['settings']['loading']['attribute']);
  }

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