From 3f44f5bbcb4ae3188954e8c91e66b1b41fa99c51 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 15 Aug 2018 22:39:37 +0100 Subject: [PATCH] Issue #2991542 by mondrake, voleger: Introduce a DatabaseLegacyTest class for deprecation testing --- .../Core/Database/DatabaseLegacyTest.php | 40 +++++++++++++++++++ .../Core/Database/RegressionTest.php | 33 +-------------- 2 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php diff --git a/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php new file mode 100644 index 00000000000..5c24c08be12 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php @@ -0,0 +1,40 @@ +schema()->tableExists($table) instead. See https://www.drupal.org/node/2947929. + */ + public function testDbTableExists() { + $this->assertTrue(db_table_exists('test')); + } + + /** + * Tests the db_set_active() function. + * + * @expectedDeprecation db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084. + */ + 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.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737 + */ + public function testDbDropTable() { + $this->assertFalse(db_drop_table('temp_test_table')); + } + +} diff --git a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php index 88d50f2ea83..0cd44d73809 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php @@ -2,8 +2,6 @@ namespace Drupal\KernelTests\Core\Database; -use Drupal\Core\Database\Database; - /** * Regression tests cases for the database layer. * @@ -37,14 +35,10 @@ class RegressionTest extends DatabaseTestBase { /** * Tests the db_table_exists() function. - * - * @group legacy - * - * @expectedDeprecation db_table_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2947929. */ public function testDBTableExists() { - $this->assertSame(TRUE, db_table_exists('test'), 'Returns true for existent table.'); - $this->assertSame(FALSE, db_table_exists('nosuchtable'), 'Returns false for nonexistent table.'); + $this->assertSame(TRUE, $this->connection->schema()->tableExists('test'), 'Returns true for existent table.'); + $this->assertSame(FALSE, $this->connection->schema()->tableExists('nosuchtable'), 'Returns false for nonexistent table.'); } /** @@ -63,27 +57,4 @@ class RegressionTest extends DatabaseTestBase { $this->assertSame(FALSE, db_index_exists('test', 'nosuchindex'), 'Returns false for nonexistent index.'); } - /** - * Tests the db_set_active() function. - * - * @group legacy - * - * @expectedDeprecation db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084. - */ - public function testDBIsActive() { - $get_active_db = Database::getConnection()->getKey(); - $this->assert(db_set_active($get_active_db), 'Database connection is active'); - } - - /** - * Tests the db_drop_table() function. - * - * @group legacy - * - * @expectedDeprecation db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737 - */ - public function testDbDropTable() { - $this->assertFalse(db_drop_table('temp_test_table')); - } - }