UpdatePathTestInstallHelper.php in Style Switcher 8.2
File
tests/src/Functional/Update/UpdatePathTestInstallHelper.php
View source
<?php
namespace Drupal\Tests\styleswitcher\Functional\Update;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Database;
use Drupal\Core\Serialization\Yaml;
class UpdatePathTestInstallHelper {
protected static $connection;
protected static function getConnection() : Connection {
if (!isset(static::$connection)) {
static::$connection = Database::getConnection();
}
return static::$connection;
}
public static function enableExtension(string $name, int $weight = 0, string $type = 'module') {
$extensions = static::getConnection()
->select('config')
->fields('config', [
'data',
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute()
->fetchField();
$extensions = unserialize($extensions);
$extensions[$type][$name] = $weight;
$extensions = serialize($extensions);
static::getConnection()
->update('config')
->fields([
'data' => $extensions,
])
->condition('collection', '')
->condition('name', 'core.extension')
->execute();
}
public static function setSchemaVersion(string $name, int $version) {
static::getConnection()
->merge('key_value')
->condition('collection', 'system.schema')
->condition('name', $name)
->fields([
'collection' => 'system.schema',
'name' => $name,
'value' => serialize($version),
])
->execute();
}
public static function addConfigYml(string $name, string $filename) {
$config = Yaml::decode(file_get_contents($filename));
static::getConnection()
->insert('config')
->fields([
'collection' => '',
'name' => $name,
'data' => serialize($config),
])
->execute();
}
}