Fix up Tests and add in return statements
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 1 Jul 2016 02:44:56 +0000 (12:44 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Mon, 11 Jul 2016 04:02:20 +0000 (04:02 +0000)
CRM/Core/BAO/SchemaHandler.php
tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php

index c5ddefba107440b94c5542538acdd174845c754a..107c945d6dcf4edf4885c16b5b55ab59726b48db 100644 (file)
@@ -630,8 +630,9 @@ MODIFY      {$columnName} varchar( $length )
 
     if ($dao->fetch()) {
       CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", array());
+      return TRUE;
     }
-
+    return FALSE;
   }
 
 }
index 90089fb1ca10a6693d7ec5e60ad76c3a04c9ec42..93f43130a2bfb8c10fc4225732648253f361193e 100644 (file)
@@ -148,19 +148,27 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * @return array
+   */
+  public function foreignKeyTests() {
+    $keys = array();
+    $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id');
+    $keys[] = array('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_id');
+    return $keys;
+  }
+
   /**
    * Test to see if we can drop foreign key
    *
+   * @dataProvider foreignKeyTests
    */
-  public function testSafeDropForeignKey() {
-    $tests = array('FK_civicrm_mailing_recipients_email_id', 'FK_civicrm_mailing_recipients_id');
-    foreach ($tests as $test) {
-      if ($test == 'FK_civicrm_mailing_recipients_id') {
-        $this->assertFalse(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $test));
-      }
-      else {
-        $this->assertTrue(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $test));
-      }
+  public function testSafeDropForeignKey($tableName, $key) {
+    if ($key == 'FK_civicrm_mailing_recipients_id') {
+      $this->assertFalse(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $key));
+    }
+    else {
+      $this->assertTrue(CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', $key));
     }
   }