class NoPreExistingSchemaUpdateTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest
- 10 core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest
- 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest
Tries to update a module which has no pre-existing schema.
@group Update
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\UpdateSystem\NoPreExistingSchemaUpdateTest uses \Drupal\Tests\RequirementsPageTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NoPreExistingSchemaUpdateTest
File
-
core/
modules/ system/ tests/ src/ Functional/ UpdateSystem/ NoPreExistingSchemaUpdateTest.php, line 15
Namespace
Drupal\Tests\system\Functional\UpdateSystemView source
class NoPreExistingSchemaUpdateTest extends BrowserTestBase {
use RequirementsPageTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$connection = Database::getConnection();
// Enable the update_test_no_preexisting module by altering the
// core.extension configuration directly, so that the schema version
// information is missing.
$extensions = $connection->select('config')
->fields('config', [
'data',
])
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$connection->update('config')
->fields([
'data' => serialize(array_merge_recursive($extensions, [
'module' => [
'update_test_no_preexisting' => 0,
],
])),
])
->condition('name', 'core.extension')
->execute();
}
/**
* Tests the system module updates with no dependencies installed.
*/
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().');
$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));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.