NoPreExistingSchemaUpdateTest.php in Drupal 8
File
core/modules/system/tests/src/Functional/UpdateSystem/NoPreExistingSchemaUpdateTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\UpdateSystem;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;
class NoPreExistingSchemaUpdateTest extends BrowserTestBase {
use RequirementsPageTrait;
protected function setUp() {
parent::setUp();
$connection = Database::getConnection();
$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();
}
public function testNoPreExistingSchema() {
$schema = \Drupal::keyValue('system.schema')
->getAll();
$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';
$this
->writeSettings([
'settings' => [
'update_free_access' => (object) [
'value' => TRUE,
'required' => TRUE,
],
],
]);
$this
->drupalGet($update_url);
$this
->updateRequirementsProblem();
$schema = \Drupal::keyValue('system.schema')
->getAll();
$this
->assertArrayHasKey('update_test_no_preexisting', $schema);
$this
->assertEquals('8001', $schema['update_test_no_preexisting']);
$this
->assertFalse(\Drupal::state()
->get('update_test_no_preexisting_update_8001', FALSE));
$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().');
}
}