diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 1b603ab..780491c 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -138,7 +138,7 @@ function simpletest_run_tests($test_list) { unset($test_list['phpunit']); } - $test_id = \Drupal::database()->insert('simpletest_test_id') + $test_id = Database::getConnection()->insert('simpletest_test_id') ->useDefaults(['test_id']) ->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php index 841dfca..ec12d05 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php @@ -76,7 +76,7 @@ public function testConcatWsFields() { * Tests escaping of LIKE wildcards. */ public function testLikeEscape() { - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields([ 'name' => 'Ring_', ]) @@ -102,7 +102,7 @@ public function testLikeEscape() { * Tests a LIKE query containing a backslash. */ public function testLikeBackslash() { - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields(['name']) ->values([ 'name' => 'abcde\f', diff --git a/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php b/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php index 6205793..1a2e900 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/CaseSensitivityTest.php @@ -15,7 +15,7 @@ class CaseSensitivityTest extends DatabaseTestBase { public function testCaseSensitiveInsert() { $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields([ // A record already exists with name 'John'. 'name' => 'john', diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php index e526675..13ef94e 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php @@ -15,7 +15,7 @@ class InsertDefaultsTest extends DatabaseTestBase { * Tests that we can run a query that uses default values for everything. */ public function testDefaultInsert() { - $query = \Drupal::database()->insert('test')->useDefaults(['job']); + $query = $this->connection->insert('test')->useDefaults(['job']); $id = $query->execute(); $schema = drupal_get_module_schema('database_test', 'test'); @@ -31,7 +31,7 @@ public function testDefaultEmptyInsert() { $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); try { - \Drupal::database()->insert('test')->execute(); + $this->connection->insert('test')->execute(); // This is only executed if no exception has been thrown. $this->fail('Expected exception NoFieldsException has not been thrown.'); } @@ -47,7 +47,7 @@ public function testDefaultEmptyInsert() { * Tests that we can insert fields with values and defaults in the same query. */ public function testDefaultInsertWithFields() { - $query = \Drupal::database()->insert('test') + $query = $this->connection->insert('test') ->fields(['name' => 'Bob']) ->useDefaults(['job']); $id = $query->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php index 6ca6f3b..1098438 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertLobTest.php @@ -15,7 +15,7 @@ class InsertLobTest extends DatabaseTestBase { public function testInsertOneBlob() { $data = "This is\000a test."; $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.'); - $id = \Drupal::database()->insert('test_one_blob') + $id = $this->connection->insert('test_one_blob') ->fields(['blob1' => $data]) ->execute(); $r = db_query('SELECT * FROM {test_one_blob} WHERE id = :id', [':id' => $id])->fetchAssoc(); @@ -26,7 +26,7 @@ public function testInsertOneBlob() { * Tests that we can insert multiple blob fields in the same query. */ public function testInsertMultipleBlob() { - $id = \Drupal::database()->insert('test_two_blobs') + $id = $this->connection->insert('test_two_blobs') ->fields([ 'blob1' => 'This is', 'blob2' => 'a test', diff --git a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php index 5b3b218..cbc5c9d 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertTest.php @@ -15,7 +15,7 @@ class InsertTest extends DatabaseTestBase { public function testSimpleInsert() { $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); - $query = \Drupal::database()->insert('test'); + $query = $this->connection->insert('test'); $query->fields([ 'name' => 'Yoko', 'age' => '29', @@ -37,7 +37,7 @@ public function testSimpleInsert() { public function testMultiInsert() { $num_records_before = (int) db_query('SELECT COUNT(*) FROM {test}')->fetchField(); - $query = \Drupal::database()->insert('test'); + $query = $this->connection->insert('test'); $query->fields([ 'name' => 'Larry', 'age' => '30', @@ -76,7 +76,7 @@ public function testMultiInsert() { public function testRepeatedInsert() { $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); - $query = \Drupal::database()->insert('test'); + $query = $this->connection->insert('test'); $query->fields([ 'name' => 'Larry', @@ -119,7 +119,7 @@ public function testRepeatedInsert() { public function testInsertFieldOnlyDefinition() { // This is useful for importers, when we want to create a query and define // its fields once, then loop over a multi-insert execution. - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields(['name', 'age']) ->values(['Larry', '30']) ->values(['Curly', '31']) @@ -137,7 +137,7 @@ public function testInsertFieldOnlyDefinition() { * Tests that inserts return the proper auto-increment ID. */ public function testInsertLastInsertID() { - $id = \Drupal::database()->insert('test') + $id = $this->connection->insert('test') ->fields([ 'name' => 'Larry', 'age' => '30', @@ -165,7 +165,7 @@ public function testInsertSelectFields() { // SELECT tp.age AS age, tp.name AS name, tp.job AS job // FROM test_people tp // WHERE tp.name = 'Meredith' - \Drupal::database()->insert('test') + $this->connection->insert('test') ->from($query) ->execute(); @@ -186,7 +186,7 @@ public function testInsertSelectAll() { // SELECT * // FROM test_people tp // WHERE tp.name = 'Meredith' - \Drupal::database()->insert('test_people_copy') + $this->connection->insert('test_people_copy') ->from($query) ->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php b/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php index 12d5661..f088514 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/InvalidDataTest.php @@ -18,7 +18,7 @@ class InvalidDataTest extends DatabaseTestBase { public function testInsertDuplicateData() { // Try to insert multiple records where at least one has bad data. try { - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields(['name', 'age', 'job']) ->values([ 'name' => 'Elvis', @@ -75,7 +75,7 @@ public function testInsertDuplicateDataFromSelect() { // Insert multiple records in 'test_people' where one has bad data // (duplicate key). A 'Meredith' record has already been inserted // in ::setUp. - \Drupal::database()->insert('test_people') + $this->connection->insert('test_people') ->fields(['name', 'age', 'job']) ->values([ 'name' => 'Elvis', @@ -109,7 +109,7 @@ public function testInsertDuplicateDataFromSelect() { ->orderBy('name'); // Try inserting from the subselect. - \Drupal::database()->insert('test') + $this->connection->insert('test') ->from($query) ->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php b/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php index 6aee10e..bfe60b6 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/QueryTest.php @@ -100,7 +100,7 @@ public function testConditionOperatorArgumentsSQLInjection() { // Attempt SQLi via union query with no unsafe characters. $this->enableModules(['user']); $this->installEntitySchema('user'); - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields(['name' => '123456']) ->execute(); $injection = "= 1 UNION ALL SELECT password FROM user WHERE uid ="; @@ -117,7 +117,7 @@ public function testConditionOperatorArgumentsSQLInjection() { } // Attempt SQLi via union query - uppercase tablename. - \Drupal::database()->insert('TEST_UPPERCASE') + $this->connection->insert('TEST_UPPERCASE') ->fields(['name' => 'secrets']) ->execute(); $injection = "IS NOT NULL) UNION ALL SELECT name FROM {TEST_UPPERCASE} -- "; diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php index 5ec1ad1..e4cc868 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php @@ -24,7 +24,7 @@ class RegressionTest extends DatabaseTestBase { public function testRegression_310447() { // That's a 255 character UTF-8 string. $job = str_repeat("é", 255); - \Drupal::database()->insert('test') + db_insert('test') ->fields([ 'name' => $this->randomMachineName(), 'age' => 20, diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php index 298b0e1..c035d35 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectSubqueryTest.php @@ -209,7 +209,7 @@ public function testJoinSubquerySelect() { */ public function testExistsSubquerySelect() { // Put George into {test_people}. - \Drupal::database()->insert('test_people') + $this->connection->insert('test_people') ->fields([ 'name' => 'George', 'age' => 27, @@ -239,7 +239,7 @@ public function testExistsSubquerySelect() { */ public function testNotExistsSubquerySelect() { // Put George into {test_people}. - \Drupal::database()->insert('test_people') + $this->connection->insert('test_people') ->fields([ 'name' => 'George', 'age' => 27, diff --git a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php index e632757..a0ac960 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php @@ -402,7 +402,7 @@ public function testRandomOrder() { // after shuffling it (in other words, nearly impossible). $number_of_items = 52; while (db_query("SELECT MAX(id) FROM {test}")->fetchField() < $number_of_items) { - \Drupal::database()->insert('test')->fields(['name' => $this->randomMachineName()])->execute(); + $this->connection->insert('test')->fields(['name' => $this->randomMachineName()])->execute(); } // First select the items in order and make sure we get an ordered list. diff --git a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php index 098e542..7ef25bf 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/TransactionTest.php @@ -57,7 +57,7 @@ protected function transactionOuterLayer($suffix, $rollback = FALSE, $ddl_statem $txn = db_transaction(); // Insert a single row into the testing table. - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields([ 'name' => 'David' . $suffix, 'age' => '24', @@ -107,7 +107,7 @@ protected function transactionInnerLayer($suffix, $rollback = FALSE, $ddl_statem $this->assertTrue($depth < $depth2, 'Transaction depth is has increased with new transaction.'); // Insert a single row into the testing table. - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields([ 'name' => 'Daniel' . $suffix, 'age' => '19', @@ -310,7 +310,7 @@ public function testTransactionWithDdlStatement() { * Inserts a single row into the testing table. */ protected function insertRow($name) { - \Drupal::database()->insert('test') + $this->connection->insert('test') ->fields([ 'name' => $name, ]) diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php index 4cf76ea..c9f142e 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php @@ -15,7 +15,7 @@ class UpdateLobTest extends DatabaseTestBase { public function testUpdateOneBlob() { $data = "This is\000a test."; $this->assertTrue(strlen($data) === 15, 'Test data contains a NULL.'); - $id = \Drupal::database()->insert('test_one_blob') + $id = $this->connection->insert('test_one_blob') ->fields(['blob1' => $data]) ->execute(); @@ -33,7 +33,7 @@ public function testUpdateOneBlob() { * Confirms that we can update two blob columns in the same table. */ public function testUpdateMultipleBlob() { - $id = \Drupal::database()->insert('test_two_blobs') + $id = $this->connection->insert('test_two_blobs') ->fields([ 'blob1' => 'This is', 'blob2' => 'a test', diff --git a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php index 2f51516..d8fc633 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/FieldSqlStorageTest.php @@ -123,7 +123,7 @@ public function testFieldLoad() { // Generate values and insert them directly in the storage tables. $values = []; - $query = \Drupal::database()->insert($this->revisionTable)->fields($columns); + $query = Database::getConnection()->insert($this->revisionTable)->fields($columns); foreach ($revision_ids as $revision_id) { // Put one value too many. for ($delta = 0; $delta <= $this->fieldCardinality; $delta++) { @@ -133,7 +133,7 @@ public function testFieldLoad() { } $query->execute(); } - $query = \Drupal::database()->insert($this->table)->fields($columns); + $query = Database::getConnection()->insert($this->table)->fields($columns); foreach ($values[$revision_id] as $delta => $value) { $query->values([$bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->getId(), $value]); } @@ -167,8 +167,8 @@ public function testFieldLoad() { // loaded. $unavailable_langcode = 'xx'; $values = [$bundle, 0, $entity->id(), $entity->getRevisionId(), 0, $unavailable_langcode, mt_rand(1, 127)]; - \Drupal::database()->insert($this->table)->fields($columns)->values($values)->execute(); - \Drupal::database()->insert($this->revisionTable)->fields($columns)->values($values)->execute(); + Database::getConnection()->insert($this->table)->fields($columns)->values($values)->execute(); + Database::getConnection()->insert($this->revisionTable)->fields($columns)->values($values)->execute(); $entity = $storage->load($entity->id()); $this->assertFalse(array_key_exists($unavailable_langcode, $entity->{$this->fieldName})); }