View source
<?php
namespace Drupal\FunctionalTests\Update;
use Drupal\Component\Utility\Html;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
class UpdatePathTestBaseTest extends UpdatePathTestBase {
protected static $modules = [
'update_test_schema',
];
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles[] = __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.8.0.bare.standard.php.gz';
$this->databaseDumpFiles[] = __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-schema-enabled.php';
$this->databaseDumpFiles[] = __DIR__ . '/../../../../modules/system/tests/fixtures/update/drupal-8.update-test-semver-update-n-enabled.php';
}
public function testDatabaseLoaded() {
\Drupal::service('cache.default')
->set(__CLASS__, 'Test');
foreach ([
'user' => 8100,
'node' => 8700,
'system' => 8805,
'update_test_schema' => 8000,
] as $module => $schema) {
$this
->assertEqual(drupal_get_installed_schema_version($module), $schema, new FormattableMarkup('Module @module schema is @schema', [
'@module' => $module,
'@schema' => $schema,
]));
}
$result = \Drupal::database()
->query("SELECT name, route from {router}")
->fetchAllKeyed(0, 1);
set_error_handler(function ($severity, $message, $filename, $lineno) {
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
});
foreach ($result as $route_name => $route) {
try {
unserialize($route);
} catch (\Exception $e) {
$this
->fail(sprintf('Error "%s" while unserializing route %s', $e
->getMessage(), Html::escape($route_name)));
}
}
restore_error_handler();
$this
->runUpdates();
$this
->assertEquals('standard', \Drupal::config('core.extension')
->get('profile'));
$this
->assertEqual(\Drupal::config('system.site')
->get('name'), 'Site-Install');
$this
->drupalGet('<front>');
$this
->assertText('Site-Install');
$database = $this->container
->get('database');
if ($database
->driver() == 'pgsql') {
$this
->assertEqual('on', $database
->query("SHOW standard_conforming_strings")
->fetchField());
$this
->assertEqual('escape', $database
->query("SHOW bytea_output")
->fetchField());
}
$this
->assertFalse(\Drupal::service('cache.default')
->get(__CLASS__));
}
public function testUpdateHookN() {
$connection = Database::getConnection();
\Drupal::state()
->set('update_test_schema_version', 8001);
$this
->runUpdates();
$select = $connection
->select('watchdog');
$select
->orderBy('wid', 'DESC');
$select
->range(0, 5);
$select
->fields('watchdog', [
'message',
]);
$container_cannot_be_saved_messages = array_filter(iterator_to_array($select
->execute()), function ($row) {
return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
});
$this
->assertEqual([], $container_cannot_be_saved_messages);
$this
->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
$this
->assertEqual(drupal_get_installed_schema_version('update_test_semver_update_n', TRUE), 8001);
$this
->assertTrue($connection
->schema()
->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
$this
->assertEquals(\Drupal::state()
->get('update_test_semver_update_n_update_8001'), 'Yes, I was run. Thanks for testing!');
}
public function testPathAliasProcessing() {
$values = [
'path' => '/admin/structure',
'alias' => '/admin-structure-alias',
'langcode' => 'und',
'status' => 1,
];
$database = \Drupal::database();
$id = $database
->insert('path_alias')
->fields($values + [
'uuid' => \Drupal::service('uuid')
->generate(),
])
->execute();
$revision_id = $database
->insert('path_alias_revision')
->fields($values + [
'id' => $id,
'revision_default' => 1,
])
->execute();
$database
->update('path_alias')
->fields([
'revision_id' => $revision_id,
])
->condition('id', $id)
->execute();
\Drupal::state()
->set('update_test_schema_version', 8002);
$this
->runUpdates();
$this
->assertSession()
->linkByHrefExists('/admin/structure');
$this
->assertSession()
->linkByHrefNotExists('/admin-structure-alias');
$account = $this
->createUser([
'administer site configuration',
'access administration pages',
'access site reports',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/reports/status');
$this
->assertSession()
->linkByHrefNotExists('/admin/structure');
$this
->assertSession()
->linkByHrefExists('/admin-structure-alias');
}
public function testModuleListChange() {
\Drupal::service('cache.default')
->set(__CLASS__, 'Test');
$extension_config = $this
->config('core.extension')
->get();
$this
->assertArrayHasKey('page_cache', $extension_config['module']);
$this
->assertArrayNotHasKey('module_test', $extension_config['module']);
$module_list = \Drupal::moduleHandler()
->getModuleList();
$this
->assertArrayHasKey('page_cache', $module_list);
$this
->assertArrayNotHasKey('module_test', $module_list);
$namespaces = \Drupal::getContainer()
->getParameter('container.namespaces');
$this
->assertArrayHasKey('Drupal\\page_cache', $namespaces);
$this
->assertArrayNotHasKey('Drupal\\module_test', $namespaces);
\Drupal::state()
->set('update_test_schema_version', 8003);
$this
->runUpdates();
$extension_config = $this
->config('core.extension')
->get();
$this
->assertArrayNotHasKey('page_cache', $extension_config['module']);
$this
->assertArrayHasKey('module_test', $extension_config['module']);
$module_list = \Drupal::moduleHandler()
->getModuleList();
$this
->assertArrayNotHasKey('page_cache', $module_list);
$this
->assertArrayHasKey('module_test', $module_list);
$namespaces = \Drupal::getContainer()
->getParameter('container.namespaces');
$this
->assertArrayNotHasKey('Drupal\\page_cache', $namespaces);
$this
->assertArrayHasKey('Drupal\\module_test', $namespaces);
$this
->assertFalse(\Drupal::service('cache.default')
->get(__CLASS__));
}
public function testSchemaChecking() {
$this
->config('config_schema_test.noschema')
->set('foo', 'bar')
->save();
$this
->runUpdates();
$this
->assertSame('bar', $this
->config('config_schema_test.noschema')
->get('foo'));
}
public function testFixturesSetup() {
$this
->assertCount(3, $this->databaseDumpFiles);
}
}