--CRM-16617, added unit test
authorPradeep Nayak <pradpnayak@gmail.com>
Mon, 8 Feb 2016 14:59:59 +0000 (20:29 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Sat, 13 Feb 2016 14:43:32 +0000 (20:13 +0530)
tests/phpunit/CRM/Core/DAOTest.php

index fd4cce327c0610a3d446ac9578247942a33e541e..6d8c0614163b4ebfbad17d656160d9c2a12c45f0 100644 (file)
@@ -223,4 +223,29 @@ 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);
+    }
+  }
+
 }