tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / CRM / Core / DAOTest.php
index de909cd39cdb0f6cbc5e4bad57314d5b9954b073..9fae687224bf05397c0a614507b5812f36f216c7 100644 (file)
@@ -1,23 +1,11 @@
 <?php
 
-require_once 'CiviTest/CiviUnitTestCase.php';
-
 /**
  * Class CRM_Core_DAOTest
  */
 class CRM_Core_DAOTest extends CiviUnitTestCase {
-  /**
-   * @return array
-   */
-  function get_info() {
-    return array(
-      'name'    => 'DAO',
-      'description' => 'Test core DAO functions',
-      'group'     => 'Core',
-    );
-  }
 
-  function testGetReferenceColumns() {
+  public function testGetReferenceColumns() {
     // choose CRM_Core_DAO_Email as an arbitrary example
     $emailRefs = CRM_Core_DAO_Email::getReferenceColumns();
     $refsByTarget = array();
@@ -31,7 +19,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase {
     $this->assertEquals('CRM_Core_Reference_Basic', get_class($contactRef));
   }
 
-  function testGetReferencesToTable() {
+  public function testGetReferencesToTable() {
     $refs = CRM_Core_DAO::getReferencesToTable(CRM_Financial_DAO_FinancialType::getTableName());
     $refsBySource = array();
     foreach ($refs as $refSpec) {
@@ -45,7 +33,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase {
     $this->assertEquals('CRM_Core_Reference_Dynamic', get_class($genericRef));
   }
 
-  function testFindReferences() {
+  public function testFindReferences() {
     $params = array(
       'first_name' => 'Testy',
       'last_name' => 'McScallion',
@@ -79,7 +67,7 @@ class CRM_Core_DAOTest extends CiviUnitTestCase {
   /**
    * @return array
    */
-  function composeQueryExamples() {
+  public function composeQueryExamples() {
     $cases = array();
     // $cases[] = array('Input-SQL', 'Input-Params', 'Expected-SQL');
 
@@ -143,20 +131,25 @@ class CRM_Core_DAOTest extends CiviUnitTestCase {
 
   /**
    * @dataProvider composeQueryExamples
+   * @param $inputSql
+   * @param $inputParams
+   * @param $expectSql
    */
-  function testComposeQuery($inputSql, $inputParams, $expectSql) {
+  public function testComposeQuery($inputSql, $inputParams, $expectSql) {
     $actualSql = CRM_Core_DAO::composeQuery($inputSql, $inputParams);
     $this->assertEquals($expectSql, $actualSql);
   }
 
-  // CASE: Two params where the %2 is already present in the query
-  // NOTE: This case should rightly FAIL, as using strstr in the replace mechanism will turn
-  // the query into: SELECT * FROM whatever WHERE name = 'Alice' AND title = 'Bob' AND year LIKE ''Bob'012'
-  // So, to avoid such ERROR, the query should be framed like:
-  // 'SELECT * FROM whatever WHERE name = %1 AND title = %3 AND year LIKE '%2012'
-  // $params[3] = array('Bob', 'String');
-  // i.e. the place holder should be unique and should not contain in any other operational use in query
-  function testComposeQueryFailure() {
+  /**
+   * CASE: Two params where the %2 is already present in the query
+   * NOTE: This case should rightly FAIL, as using strstr in the replace mechanism will turn
+   * the query into: SELECT * FROM whatever WHERE name = 'Alice' AND title = 'Bob' AND year LIKE ''Bob'012'
+   * So, to avoid such ERROR, the query should be framed like:
+   * 'SELECT * FROM whatever WHERE name = %1 AND title = %3 AND year LIKE '%2012'
+   * $params[3] = array('Bob', 'String');
+   * i.e. the place holder should be unique and should not contain in any other operational use in query
+   */
+  public function testComposeQueryFailure() {
     $cases[] = array(
       'SELECT * FROM whatever WHERE name = %1 AND title = %2 AND year LIKE \'%2012\' ',
       array(
@@ -173,23 +166,62 @@ class CRM_Core_DAOTest extends CiviUnitTestCase {
   /**
    * @return array
    */
-  function sqlNameDataProvider() {
+  public function sqlNameDataProvider() {
     return array(
       array('this is a long string', 30, FALSE, 'this is a long string'),
-
-      array('this is an even longer string which is exactly 60 character', 60, FALSE, 'this is an even longer string which is exactly 60 character'),
-      array('this is an even longer string which is exactly 60 character', 60, TRUE , 'this is an even longer string which is exactly 60 character'),
-
-      array('this is an even longer string which is a bit more than 60 character', 60, FALSE, 'this is an even longer string which is a bit more than 60 ch'),
-      array('this is an even longer string which is a bit more than 60 character', 60, TRUE , 'this is an even longer string which is a bit more th_c1cbd519'),
+      array(
+        'this is an even longer string which is exactly 60 character',
+        60,
+        FALSE,
+        'this is an even longer string which is exactly 60 character',
+      ),
+      array(
+        'this is an even longer string which is exactly 60 character',
+        60,
+        TRUE,
+        'this is an even longer string which is exactly 60 character',
+      ),
+      array(
+        'this is an even longer string which is a bit more than 60 character',
+        60,
+        FALSE,
+        'this is an even longer string which is a bit more than 60 ch',
+      ),
+      array(
+        'this is an even longer string which is a bit more than 60 character',
+        60,
+        TRUE,
+        'this is an even longer string which is a bit more th_c1cbd519',
+      ),
     );
   }
 
   /**
    * @dataProvider sqlNameDataProvider
+   * @param $inputData
+   * @param $length
+   * @param $makeRandom
+   * @param $expectedResult
    */
-  function testShortenSQLName($inputData, $length, $makeRandom, $expectedResult) {
+  public function testShortenSQLName($inputData, $length, $makeRandom, $expectedResult) {
     $this->assertEquals($expectedResult, CRM_Core_DAO::shortenSQLName($inputData, $length, $makeRandom));
   }
 
+  public function testFindById() {
+    $params = $this->sampleContact('Individual', 4);
+    $existing_contact = CRM_Contact_BAO_Contact::add($params);
+    $contact = CRM_Contact_BAO_Contact::findById($existing_contact->id);
+    $this->assertEquals($existing_contact->id, $contact->id);
+    $deleted_contact_id = $existing_contact->id;
+    CRM_Contact_BAO_Contact::deleteContact($contact->id, FALSE, TRUE);
+    $exception_thrown = FALSE;
+    try {
+      $deleted_contact = CRM_Contact_BAO_Contact::findById($deleted_contact_id);
+    }
+    catch (Exception $e) {
+      $exception_thrown = TRUE;
+    }
+    $this->assertTrue($exception_thrown);
+  }
+
 }