updateRequirementsProblem example

$theme_config = Yaml::decode(file_get_contents(\Drupal::moduleHandler()->getModule('system')->getPath() . '/config/install/system.theme.yml'));
    $theme_config['default'] = 'test_theme_updates';
    file_put_contents("$path/system.theme.yml", Yaml::encode($theme_config));
  }

  /** * Tests that after installing the profile there are no outstanding updates. */
  public function testMaintenanceThemeUpdateRegistration() {
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    $this->drupalGet('update.php/selection');
    $this->assertSession()->pageTextContains('No pending updates.');
  }

}
'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().');

    $this->updateRequirementsProblem();

    $schema = \Drupal::service('update.update_hook_registry')->getAllInstalledVersions();
    $this->assertArrayHasKey('update_test_no_preexisting', $schema);
    $this->assertEquals('8001', $schema['update_test_no_preexisting']);
    // The schema version has been fixed, but the update was never run.     $this->assertFalse(\Drupal::state()->get('update_test_no_preexisting_update_8001', FALSE));
  }

}
    // 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');

    $this->doSelectionTest();
    // Run the update hooks.     $this->clickLink('Apply pending updates');
    $this->checkForMetaRefresh();

    // Ensure there are no failed updates.     if ($this->checkFailedUpdates) {
      $failure = $this->cssSelect('.failure');
      if ($failure) {
        
'access administration pages',
      'administer content types',
    ]);
    $this->drupalLogin($user);
    $this->drupalGet('');
    $this->assertSession()->pageTextContains('Tools');
    $this->assertSession()->pageTextContains('Administration');

    // Ensure that there are no pending updates after installation.     $this->drupalLogin($this->rootUser);
    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    $this->drupalGet('update.php/selection');
    $this->assertSession()->pageTextContains('No pending updates.');

    // Ensure that there are no pending entity updates after installation.     $this->assertFalse($this->container->get('entity.definition_update_manager')->needsUpdates(), 'After installation, entity schema is up to date.');

    // Ensure special configuration overrides are correct.     $this->assertFalse($this->config('system.theme.global')->get('features.node_user_picture'), 'Configuration system.theme.global:features.node_user_picture is FALSE.');
    $this->assertEquals(UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL, $this->config('user.settings')->get('register'));
  }

}
$this->updateUrl = Url::fromRoute('system.db_update')->setAbsolute()->toString();
    $this->updateUser = $this->drupalCreateUser([
      'administer software updates',
    ]);
  }

  public function testInvalidUpdateHook() {
    // Confirm that a module with hook_update_8000() cannot be updated.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Some of the pending updates cannot be applied because their dependencies were not met.');
  }

}

    $role->grantPermission('view the administration theme');
    $role->save();
    $this->adminUser->addRole($role->id());
    $this->adminUser->save();
    $this->drupalGet('node/add');
    $this->assertSession()->statusCodeEquals(200);

    // Ensure that there are no pending updates after installation.     $this->drupalLogin($this->rootUser);
    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    $this->drupalGet('update.php/selection');
    $this->assertSession()->pageTextContains('No pending updates.');

    // Ensure that there are no pending entity updates after installation.     $this->assertFalse($this->container->get('entity.definition_update_manager')->needsUpdates(), 'After installation, entity schema is up to date.');

    // Make sure the optional image styles are not installed.     $this->drupalGet('admin/config/media/image-styles');
    $this->assertSession()->pageTextNotContains('Max 325x325');
    $this->assertSession()->pageTextNotContains('Max 650x650');
    $this->assertSession()->pageTextNotContains('Max 1300x1300');
    

  public function testTranslatedUpdate() {
    // Visit the update page to collect any strings that may be translatable.     $user = $this->drupalCreateUser(['administer software updates']);
    $this->drupalLogin($user);
    $update_url = Url::fromRoute('system.db_update')->setAbsolute()->toString();

    // Collect strings from the PHP warning page, if applicable, as well as the     // main update page.     $this->drupalGet($update_url['external' => TRUE]);
    $this->updateRequirementsProblem();

    /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
    $stringStorage = \Drupal::service('locale.storage');
    $sources = $stringStorage->getStrings();

    // Translate all source strings found.     foreach ($sources as $source) {
      $stringStorage->createTranslation([
        'lid' => $source->lid,
        'language' => 'fr',
        'translation' => $this->randomMachineName(100),
      ])
    $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();
    $this->clickLink('Continue');

    $this->assertFalse(\Drupal::cache()->get('will_not_exist_after_update', FALSE));
  }

}
/** * Tests that requirements warnings and errors are correctly displayed. */
  public function testRequirements() {
    $update_script_test_config = $this->config('update_script_test.settings');
    $this->drupalLogin($this->updateUser);

    // If there are no requirements warnings or errors, we expect to be able to     // go through the update process uninterrupted.     $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('No pending updates.');
    // Confirm that all caches were cleared.     $this->assertSession()->pageTextContains('hook_cache_flush() invoked for update_script_test.module.');

    // If there is a requirements warning, we expect it to be initially     // displayed, but clicking the link to proceed should allow us to go     // through the rest of the update process uninterrupted.
    // First, run this test with pending updates to make sure they can be run     // successfully.
$update_registry = \Drupal::service('update.update_hook_registry');

    // Verify that the 8000 schema is in place.     $this->assertEquals(8000, $update_registry->getInstalledVersion('update_test_schema'));
    $this->assertFalse($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');

    // Increment the schema version.     \Drupal::state()->set('update_test_schema_version', 8001);

    $this->drupalLogin($this->user);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Schema version 8001.');
    // Run the update hooks.     $this->clickLink('Apply pending updates');
    $this->checkForMetaRefresh();

    // Ensure schema has changed.     $this->resetAll();
    /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */
    $update_registry = \Drupal::service('update.update_hook_registry');
    $this->assertEquals(8001, $update_registry->getInstalledVersion('update_test_schema'));
    
// Ensure that the minimum schema version is 8000, despite 7200 update     // hooks and a 7XXX hook_update_last_removed().     $this->assertEquals(8000, $update_registry->getInstalledVersion('update_test_with_7x'));

    // Try to manually set the schema version to 7110 and ensure that no     // updates are allowed.     $update_registry->setInstalledVersion('update_test_with_7x', 7110);

    // Click through update.php with 'administer software updates' permission.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('Some of the pending updates cannot be applied because their dependencies were not met.');
  }

}
'update_test_postupdate_post_update_first',
      'update_test_postupdate_post_update_second',
      'update_test_postupdate_post_update_test1',
      'update_test_postupdate_post_update_test0',
      'update_test_postupdate_post_update_test_batch',
    ];
    foreach ($expected_updates as $expected_update) {
      $this->assertEquals(1, $existing_updates[$expected_update]new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
    }

    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    $this->drupalGet('update.php/selection');
    $this->assertSession()->pageTextContains('No pending updates.');
  }

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