From fd542660fede6c89ad660d643a9a510e64ea0605 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Mon, 8 Feb 2016 20:29:59 +0530 Subject: [PATCH] --CRM-16617, added unit test --- tests/phpunit/CRM/Core/DAOTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index 9fae687224..9e9b66b76c 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -224,4 +224,28 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { $this->assertTrue($exception_thrown); } + /** + * requireValidDBName() method (to check valid database name) + */ + public function testRequireValidDBName() { + $databases = array( + 'testdb' => TRUE, + 'test_db' => TRUE, + 'TEST_db' => TRUE, + '123testdb' => TRUE, + 'test12db34' => TRUE, + 'test_12_db34' => TRUE, + 'test-db' => FALSE, + 'test;db' => FALSE, + 'test*&db' => FALSE, + 'testdb;Delete test' => FALSE, + '123456' => FALSE, + 'test#$%^&*' => FALSE, + ); + $testDetails = array(); + foreach ($databases as $database => $val) { + $this->assertEquals(CRM_Core_DAO::requireValidDBName($database, $testDetails), $val); + } + } + } -- 2.25.1