class DatabaseLegacyTest in Drupal 8
Deprecation tests cases for the database layer.
@group legacy
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses AssertContentTrait, AssertLegacyTrait, AssertHelperTrait, ConfigTestTrait, PhpunitCompatibilityTrait, RandomGeneratorTrait, TestRequirementsTrait
- class \Drupal\KernelTests\Core\Database\DatabaseTestBase
- class \Drupal\KernelTests\Core\Database\DatabaseLegacyTest
- class \Drupal\KernelTests\Core\Database\DatabaseTestBase
Expanded class hierarchy of DatabaseLegacyTest
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ DatabaseLegacyTest.php, line 22
Namespace
Drupal\KernelTests\Core\DatabaseView source
class DatabaseLegacyTest extends DatabaseTestBase {
/**
* The modules to enable.
*
* @var array
*/
public static $modules = [
'database_test',
'system',
];
/**
* Tests deprecation of the db_and() function.
*
* @expectedDeprecation db_and() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an AND conjunction: new Condition('AND'), instead. See https://www.drupal.org/node/2993033
*/
public function testDbAnd() {
$this
->assertInstanceOf(Condition::class, db_and());
}
/**
* Tests deprecation of the db_condition() function.
*
* @expectedDeprecation db_condition() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying the desired conjunction: new Condition($conjunction), instead. See https://www.drupal.org/node/2993033
*/
public function testDbCondition() {
$this
->assertInstanceOf(Condition::class, db_condition('AND'));
}
/**
* Tests deprecation of the db_or() function.
*
* @expectedDeprecation db_or() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an OR conjunction: new Condition('OR'), instead. See https://www.drupal.org/node/2993033
*/
public function testDbOr() {
$this
->assertInstanceOf(Condition::class, db_or());
}
/**
* Tests deprecation of the db_xor() function.
*
* @expectedDeprecation db_xor() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying a XOR conjunction: new Condition('XOR'), instead. See https://www.drupal.org/node/2993033
*/
public function testDbXor() {
$this
->assertInstanceOf(Condition::class, db_xor());
}
/**
* Tests the db_table_exists() function.
*
* @expectedDeprecation db_table_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2993033
*/
public function testDbTableExists() {
$this
->assertTrue(db_table_exists('test'));
}
/**
* Tests the db_find_tables() function.
*
* @expectedDeprecation db_find_tables() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use $injected_database->schema()->findTables($table_expression) instead. See https://www.drupal.org/node/2993033
*/
public function testDbFindTables() {
$expected = [
'test_people' => 'test_people',
'test_people_copy' => 'test_people_copy',
];
$this
->assertEquals($expected, db_find_tables('test_people%'));
}
/**
* Tests the db_set_active() function.
*
* @expectedDeprecation db_set_active() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2993033
*/
public function testDbSetActive() {
$get_active_db = $this->connection
->getKey();
$this
->assert(db_set_active($get_active_db), 'Database connection is active');
}
/**
* Tests the db_drop_table() function.
*
* @expectedDeprecation db_drop_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2993033
*/
public function testDbDropTable() {
$this
->assertFalse(db_drop_table('temp_test_table'));
}
/**
* Tests deprecation of the db_next_id() function.
*
* @expectedDeprecation db_next_id() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call nextId() on it. For example, $injected_database->nextId($existing_id). See https://www.drupal.org/node/2993033
*/
public function testDbNextId() {
$this
->installSchema('system', 'sequences');
$this
->assertEquals(1001, db_next_id(1000));
}
/**
* Tests the db_change_field() function is deprecated.
*
* @expectedDeprecation db_change_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbChangeField() {
$spec = [
'description' => "A new person's name",
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'binary' => TRUE,
];
db_change_field('test', 'name', 'nosuchcolumn', $spec);
}
/**
* Tests deprecation of the db_field_set_default() function.
*
* @expectedDeprecation db_field_set_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @expectedDeprecation fieldSetDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
* @doesNotPerformAssertions
*/
public function testDbFieldSetDefault() {
db_field_set_default('test', 'job', 'baz');
}
/**
* Tests deprecation of the db_field_set_no_default() function.
*
* @expectedDeprecation db_field_set_no_default() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033
* @expectedDeprecation fieldSetNoDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
* @doesNotPerformAssertions
*/
public function testDbFieldSetNoDefault() {
db_field_set_no_default('test_null', 'age');
}
/**
* Tests Schema::fieldSetDefault and Schema::fieldSetNoDefault.
*
* @expectedDeprecation fieldSetDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
* @expectedDeprecation fieldSetNoDefault() is deprecated in drupal:8.7.0 and will be removed before drupal:9.0.0. Instead, call ::changeField() passing a full field specification. See https://www.drupal.org/node/2999035
*/
public function testSchemaFieldDefaultChange() {
// Create a table.
$table_specification = [
'description' => 'Schema table description.',
'fields' => [
'id' => [
'type' => 'int',
'default' => NULL,
],
'test_field' => [
'type' => 'int',
'not null' => TRUE,
'description' => 'Test field',
],
],
];
$this->connection
->schema()
->createTable('test_table', $table_specification);
// An insert without a value for the column 'test_field' should fail.
try {
$this->connection
->insert('test_table')
->fields([
'id' => 1,
])
->execute();
$this
->fail('Expected DatabaseException, none was thrown.');
} catch (DatabaseException $e) {
$this
->assertEquals(0, $this->connection
->select('test_table')
->countQuery()
->execute()
->fetchField());
}
// Add a default value to the column.
$this->connection
->schema()
->fieldSetDefault('test_table', 'test_field', 0);
// The insert should now succeed.
$this->connection
->insert('test_table')
->fields([
'id' => 1,
])
->execute();
$this
->assertEquals(1, $this->connection
->select('test_table')
->countQuery()
->execute()
->fetchField());
// Remove the default.
$this->connection
->schema()
->fieldSetNoDefault('test_table', 'test_field');
// The insert should fail again.
try {
$this->connection
->insert('test_table')
->fields([
'id' => 2,
])
->execute();
$this
->fail('Expected DatabaseException, none was thrown.');
} catch (DatabaseException $e) {
$this
->assertEquals(1, $this->connection
->select('test_table')
->countQuery()
->execute()
->fetchField());
}
}
/**
* Tests deprecation of the db_transaction() function.
*
* @expectedDeprecation db_transaction is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call startTransaction() on it. For example, $injected_database->startTransaction($name). See https://www.drupal.org/node/2993033
*/
public function testDbTransaction() {
$this
->assertInstanceOf(Transaction::class, db_transaction());
}
/**
* Tests the db_close() function.
*
* @expectedDeprecation db_close() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\Database::closeConnection() instead. See https://www.drupal.org/node/2993033
*/
public function testDbClose() {
$this
->assertTrue(Database::isActiveConnection(), 'Database connection is active');
db_close();
$this
->assertFalse(Database::isActiveConnection(), 'Database connection is not active');
}
/**
* Tests deprecation of the db_add_field() function.
*
* @expectedDeprecation db_add_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033
*/
public function testDbAddField() {
$this
->assertFalse($this->connection
->schema()
->fieldExists('test', 'anint'));
db_add_field('test', 'anint', [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Added int column.',
]);
$this
->assertTrue($this->connection
->schema()
->fieldExists('test', 'anint'));
}
/**
* Tests deprecation of the db_drop_field() function.
*
* @expectedDeprecation db_drop_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropField() on it. For example, $injected_database->schema()->dropField($table, $field). See https://www.drupal.org/node/2993033
*/
public function testDbDropField() {
$this
->assertTrue($this->connection
->schema()
->fieldExists('test', 'age'));
$this
->assertTrue(db_drop_field('test', 'age'));
$this
->assertFalse($this->connection
->schema()
->fieldExists('test', 'age'));
}
/**
* Tests deprecation of the db_field_exists() function.
*
* @expectedDeprecation db_field_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033
*/
public function testDbFieldExists() {
$this
->assertTrue(db_field_exists('test', 'age'));
}
/**
* Tests deprecation of the db_field_names() function.
*
* @expectedDeprecation db_field_names() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldNames() on it. For example, $injected_database->schema()->fieldNames($fields). See https://www.drupal.org/node/2993033
*/
public function testDbFieldNames() {
$this
->assertSame([
'test_field',
], db_field_names([
'test_field',
]));
}
/**
* Tests deprecation of the db_create_table() function.
*
* @expectedDeprecation db_create_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033
*/
public function testDbCreateTable() {
$name = 'test_create_table';
$table = [
'fields' => [
'id' => [
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
'primary key' => [
'id',
],
];
db_create_table($name, $table);
$this
->assertTrue($this->connection
->schema()
->tableExists($name));
}
/**
* Tests deprecation of the db_merge() function.
*
* @expectedDeprecation db_merge() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call merge() on it. For example, $injected_database->merge($table, $options). See https://www.drupal.org/node/2993033
*/
public function testDbMerge() {
$this
->assertInstanceOf(Merge::class, db_merge('test'));
}
/**
* Tests deprecation of the db_driver() function.
*
* @expectedDeprecation db_driver() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call driver() on it. For example, $injected_database->driver($string). See https://www.drupal.org/node/2993033
*/
public function testDbDriver() {
$this
->assertNotNull(db_driver());
}
/**
* Tests deprecation of the db_escape_field() function.
*
* @expectedDeprecation db_escape_field() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeField() on it. For example, $injected_database->escapeField($field). See https://www.drupal.org/node/2993033
*/
public function testDbEscapeField() {
$this
->assertNotNull(db_escape_field('test'));
}
/**
* Tests deprecation of the db_like() function.
*
* @expectedDeprecation db_like() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeLike() on it. For example, $injected_database->escapeLike($string). See https://www.drupal.org/node/2993033
*/
public function testDbLike() {
$this
->assertSame('test\\%', db_like('test%'));
}
/**
* Tests deprecation of the db_escape_table() function.
*
* @expectedDeprecation db_escape_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call escapeTable() on it. For example, $injected_database->escapeTable($table). See https://www.drupal.org/node/2993033
*/
public function testDbEscapeTable() {
$this
->assertNotNull(db_escape_table('test'));
}
/**
* Tests deprecation of the db_rename_table() function.
*
* @expectedDeprecation db_rename_table() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call renameTable() on it. For example, $injected_database->schema()->renameTable($table, $new_name). See https://www.drupal.org/node/2993033
*/
public function testDbRenameTable() {
$this
->assertTrue($this->connection
->schema()
->tableExists('test'));
db_rename_table('test', 'test_rename');
$this
->assertTrue($this->connection
->schema()
->tableExists('test_rename'));
}
/**
* Tests deprecation of the db_drop_index() function.
*
* @expectedDeprecation db_drop_index() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropIndex() on it. For example, $injected_database->schema()->dropIndex($table, $name). See https://www.drupal.org/node/2993033
*/
public function testDbDropIndex() {
$this
->assertFalse(db_drop_index('test', 'no_such_index'));
}
/**
* Tests deprecation of the db_index_exists() function.
*
* @expectedDeprecation db_index_exists() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call indexExists() on it. For example, $injected_database->schema()->indexExists($table, $name). See https://www.drupal.org/node/2993033
*/
public function testDbIndexExists() {
$this
->assertFalse(db_index_exists('test', 'no_such_index'));
}
/**
* Tests deprecation of the db_drop_unique_key() function.
*
* @expectedDeprecation db_drop_unique_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropUniqueKey() on it. For example, $injected_database->schema()->dropUniqueKey($table, $name). See https://www.drupal.org/node/2993033
*/
public function testDbDropUniqueKey() {
$this
->assertTrue(db_drop_unique_key('test', 'name'));
}
/**
* Tests deprecation of the db_add_unique_key() function.
*
* @expectedDeprecation db_add_unique_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbAddUniqueKey() {
db_add_unique_key('test', 'age', [
'age',
]);
}
/**
* Tests deprecation of the db_drop_primary_key() function.
*
* @expectedDeprecation db_drop_primary_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropPrimaryKey() on it. For example, $injected_database->schema()->dropPrimaryKey($table). See https://www.drupal.org/node/2993033
*/
public function testDbDropPrimaryKey() {
$this
->assertTrue(db_drop_primary_key('test_people'));
}
/**
* Tests deprecation of the db_add_primary_key() function.
*
* @expectedDeprecation db_add_primary_key() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields). See https://www.drupal.org/node/2993033
* @doesNotPerformAssertions
*/
public function testDbAddPrimaryKey() {
$this->connection
->schema()
->dropPrimaryKey('test_people');
db_add_primary_key('test_people', [
'job',
]);
}
/**
* Tests the db_update() function.
*
* @expectedDeprecation db_update() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call call update() on it. For example, $injected_database->update($table, $options). See https://www.drupal.org/node/2993033
*/
public function testDbUpdate() {
$this
->assertInstanceOf(Update::class, db_update('test'));
}
/**
* Tests the db_query() function.
*
* @expectedDeprecation db_query() is deprecated in drupal:8.0.0. It will be removed before drupal:9.0.0. Instead, get a database connection injected into your service from the container and call query() on it. For example, $injected_database->query($query, $args, $options). See https://www.drupal.org/node/2993033
*/
public function testDbQuery() {
$this
->assertInstanceOf(StatementInterface::class, db_query('SELECT name FROM {test} WHERE name = :name', [
':name' => "John",
]));
}
/**
* Tests deprecation of the db_delete() function.
*
* @expectedDeprecation db_delete is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call delete() on it. For example, $injected_database->delete($table, $options). See https://www.drupal.org/node/2993033
*/
public function testDbDelete() {
$this
->assertInstanceOf(Delete::class, db_delete('test'));
}
/**
* Tests deprecation of the db_truncate() function.
*
* @expectedDeprecation db_truncate() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call truncate() on it. For example, $injected_database->truncate($table, $options). See https://www.drupal.org/node/2993033
*/
public function testDbTruncate() {
$this
->assertInstanceOf(Truncate::class, db_truncate('test'));
}
/**
* Tests deprecation of the $options 'target' key in Connection::query.
*
* @expectedDeprecation Passing a 'target' key to \Drupal\Core\Database\Connection::query $options argument is deprecated in drupal:8.0.x and will be removed before drupal:9.0.0. Instead, use \Drupal\Core\Database\Database::getConnection($target)->query(). See https://www.drupal.org/node/2993033
*/
public function testDbOptionsTarget() {
$this
->assertNotNull($this->connection
->query('SELECT * FROM {test}', [], [
'target' => 'bar',
]));
}
/**
* Tests deprecation of the $options 'target' key in Select.
*
* @expectedDeprecation Passing a 'target' key to \Drupal\Core\Database\Connection::query $options argument is deprecated in drupal:8.0.x and will be removed before drupal:9.0.0. Instead, use \Drupal\Core\Database\Database::getConnection($target)->query(). See https://www.drupal.org/node/2993033
*/
public function testDbOptionsTargetInSelect() {
$this
->assertNotNull($this->connection
->select('test', 't', [
'target' => 'bar',
])
->fields('t')
->execute());
}
/**
* Tests deprecation of the db_query_temporary() function.
*
* @expectedDeprecation db_query_temporary() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call queryTemporary() on it. For example, $injected_database->queryTemporary($query, $args, $options). See https://www.drupal.org/node/2993033
*/
public function testDbQueryTemporary() {
$expected = $this->connection
->select('test')
->countQuery()
->execute()
->fetchField();
$name = db_query_temporary('SELECT name FROM {test}');
$count = $this->connection
->select($name)
->countQuery()
->execute()
->fetchField();
$this
->assertSame($expected, $count);
}
/**
* Tests deprecation of the db_query_range() function.
*
* @expectedDeprecation db_query_range() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call queryRange() on it. For example, $injected_database->queryRange($query, $from, $count, $args, $options). See https://www.drupal.org/node/2993033
*/
public function testDbQueryRange() {
$count = count(db_query_range('SELECT name FROM {test}', 1, 3)
->fetchAll());
$this
->assertSame(3, $count);
}
/**
* Tests deprecation of the db_add_index() function.
*
* @expectedDeprecation db_add_index() is deprecated in drupal:8.0.x and will be removed in drupal:9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033
*/
public function testDbAddIndex() {
$table_specification = [
'fields' => [
'age' => [
'description' => "The person's age",
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
],
];
$this
->assertNull(db_add_index('test', 'test', [
'age',
], $table_specification));
}
/**
* Tests the db_insert() function.
*
* @expectedDeprecation db_insert() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call insert() on it. For example, $injected_database->insert($table, $options). See https://www.drupal.org/node/2993033
*/
public function testDbInsert() {
$this
->assertInstanceOf(Insert::class, db_insert('test'));
}
/**
* Tests the db_select() function.
*
* @expectedDeprecation db_select() is deprecated in drupal:8.0.0. It will be removed from drupal:9.0.0. Instead, get a database connection injected into your service from the container and call select() on it. For example, $injected_database->db_select($table, $alias, $options). See https://www.drupal.org/node/2993033
*/
public function testDbSelect() {
$this
->assertInstanceOf(Select::class, db_select('test'));
}
/**
* Tests the db_ignore_replica() function.
*
* @expectedDeprecation db_ignore_replica() is deprecated in drupal:8.7.0. It will be removed from drupal:9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger() instead. See https://www.drupal.org/node/2997500
*/
public function testDbIgnoreReplica() {
$connection = Database::getConnectionInfo('default');
Database::addConnectionInfo('default', 'replica', $connection['default']);
db_ignore_replica();
/** @var \Symfony\Component\HttpFoundation\Session\SessionInterface $session */
$session = \Drupal::service('session');
$this
->assertTrue($session
->has('ignore_replica_server'));
}
/**
* Tests the _db_get_target() function.
*
* @expectedDeprecation _db_get_target() is deprecated in drupal:8.8.0. Will be removed before drupal:9.0.0. See https://www.drupal.org/node/2993033
*/
public function testDbGetTarget() {
$op1 = $op2 = [
'target' => 'replica',
];
$this
->assertEquals('replica', _db_get_target($op1));
$this
->assertEquals('default', _db_get_target($op2, FALSE));
$this
->assertEmpty($op1);
$this
->assertEmpty($op2);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertContentTrait:: |
protected | property | The current raw content. | |
AssertContentTrait:: |
protected | property | The drupalSettings value from the current raw $content. | |
AssertContentTrait:: |
protected | property | The XML structure parsed from the current raw $content. | 1 |
AssertContentTrait:: |
protected | property | The plain-text content of raw $content (text nodes). | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertContentTrait:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href is not found in the main region. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page does not exist. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text is NOT found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | |
AssertContentTrait:: |
protected | function | Pass if the page title is not the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | |
AssertContentTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertContentTrait:: |
protected | function | Asserts that a Perl regex pattern is found in the plain-text content. | |
AssertContentTrait:: |
protected | function | Asserts themed output. | |
AssertContentTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
AssertContentTrait:: |
protected | function | Builds an XPath query. | |
AssertContentTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertContentTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
AssertContentTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertContentTrait:: |
protected | function | Gets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Gets the current raw content. | |
AssertContentTrait:: |
protected | function | Get the selected value from a select field. | |
AssertContentTrait:: |
protected | function | Retrieves the plain-text content from the current raw content. | |
AssertContentTrait:: |
protected | function | Get the current URL from the cURL handler. | 1 |
AssertContentTrait:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
AssertContentTrait:: |
protected | function | Removes all white-space between HTML tags from the raw content. | |
AssertContentTrait:: |
protected | function | Sets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Sets the raw content (e.g. HTML). | |
AssertContentTrait:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
ConfigTestTrait:: |
protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait:: |
protected | function | Copies configuration objects from source storage to target storage. | |
DatabaseLegacyTest:: |
public static | property |
The modules to enable. Overrides DatabaseTestBase:: |
|
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_add_field() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_add_index() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_add_primary_key() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_add_unique_key() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_and() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_change_field() function is deprecated. | |
DatabaseLegacyTest:: |
public | function | Tests the db_close() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_condition() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_create_table() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_delete() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_driver() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_drop_field() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_drop_index() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_drop_primary_key() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_drop_table() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_drop_unique_key() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_escape_field() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_escape_table() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_field_exists() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_field_names() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_field_set_default() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_field_set_no_default() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_find_tables() function. | |
DatabaseLegacyTest:: |
public | function | Tests the _db_get_target() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_ignore_replica() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_index_exists() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_insert() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_like() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_merge() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_next_id() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the $options 'target' key in Connection::query. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the $options 'target' key in Select. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_or() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_query() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_query_range() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_query_temporary() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_rename_table() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_select() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_set_active() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_table_exists() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_transaction() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_truncate() function. | |
DatabaseLegacyTest:: |
public | function | Tests the db_update() function. | |
DatabaseLegacyTest:: |
public | function | Tests deprecation of the db_xor() function. | |
DatabaseLegacyTest:: |
public | function | Tests Schema::fieldSetDefault and Schema::fieldSetNoDefault. | |
DatabaseTestBase:: |
protected | property | The database connection for testing. | |
DatabaseTestBase:: |
public static | function | Sets up our sample data. | |
DatabaseTestBase:: |
public | function | Sets up tables for NULL handling. | |
DatabaseTestBase:: |
protected | function |
Overrides KernelTestBase:: |
1 |
KernelTestBase:: |
protected | property | Back up and restore any global variables that may be changed by tests. | |
KernelTestBase:: |
protected | property | Back up and restore static class properties that may be changed by tests. | |
KernelTestBase:: |
protected | property | Contains a few static class properties for performance. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | @todo Move into Config test base class. | 7 |
KernelTestBase:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Do not forward any global state from the parent process to the processes that run the actual tests. | |
KernelTestBase:: |
protected | property | The app root. | |
KernelTestBase:: |
protected | property | Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Set to TRUE to strict check all configuration saved. | 6 |
KernelTestBase:: |
protected | property | The virtual filesystem root directory. | |
KernelTestBase:: |
protected | function | 1 | |
KernelTestBase:: |
protected | function | Bootstraps a basic test environment. | |
KernelTestBase:: |
private | function | Bootstraps a kernel for a test. | |
KernelTestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
KernelTestBase:: |
protected | function | Disables modules for this test. | |
KernelTestBase:: |
protected | function | Enables modules for this test. | |
KernelTestBase:: |
protected | function | Gets the config schema exclusions for this test. | |
KernelTestBase:: |
protected | function | Returns the Database connection info to be used for this test. | 1 |
KernelTestBase:: |
public | function | ||
KernelTestBase:: |
private | function | Returns Extension objects for $modules to enable. | |
KernelTestBase:: |
private static | function | Returns the modules to enable for this test. | |
KernelTestBase:: |
protected | function | Initializes the FileCache component. | |
KernelTestBase:: |
protected | function | Installs default configuration for a given list of modules. | |
KernelTestBase:: |
protected | function | Installs the storage schema for a specific entity type. | |
KernelTestBase:: |
protected | function | Installs database tables from a module schema definition. | |
KernelTestBase:: |
protected | function | Returns whether the current test method is running in a separate process. | |
KernelTestBase:: |
protected | function | ||
KernelTestBase:: |
public | function |
Registers test-specific services. Overrides ServiceProviderInterface:: |
26 |
KernelTestBase:: |
protected | function | Renders a render array. | 1 |
KernelTestBase:: |
protected | function | Sets the install profile and rebuilds the container to update it. | |
KernelTestBase:: |
protected | function | Sets an in-memory Settings variable. | |
KernelTestBase:: |
public static | function | 1 | |
KernelTestBase:: |
protected | function | Sets up the filesystem, so things like the file directory. | 2 |
KernelTestBase:: |
protected | function | Stops test execution. | |
KernelTestBase:: |
protected | function | 6 | |
KernelTestBase:: |
public | function | @after | |
KernelTestBase:: |
protected | function | Dumps the current state of the virtual filesystem to STDOUT. | |
KernelTestBase:: |
public | function | BC: Automatically resolve former KernelTestBase class properties. | |
KernelTestBase:: |
public | function | Prevents serializing any properties. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. | |
TestRequirementsTrait:: |
private | function | Checks missing module requirements. | |
TestRequirementsTrait:: |
protected | function | Check module requirements for the Drupal use case. | 1 |
TestRequirementsTrait:: |
protected static | function | Returns the Drupal root directory. |