Merge pull request #4906 from eileenmcnaughton/minor-tidies
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionSoftTest.php
index cbf093dc3131074d7730528470438c722244ca4f..2bc8cf5dd99d8be89f71bbb8615aa679a9d4acdb 100644 (file)
@@ -30,10 +30,9 @@ require_once 'CiviTest/CiviUnitTestCase.php';
 /**
  *  Test APIv3 civicrm_contribute_* functions
  *
- *  @package CiviCRM_APIv3
- *  @subpackage API_ContributionSoft
+ * @package CiviCRM_APIv3
+ * @subpackage API_ContributionSoft
  */
-
 class api_v3_ContributionSoftTest extends CiviUnitTestCase {
 
   /**
@@ -50,8 +49,9 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
   protected $_params;
 
 
-  function setUp() {
+  public function setUp() {
     parent::setUp();
+    $this->useTransaction(TRUE);
 
     $this->_individualId = $this->individualCreate();
     $this->_softIndividual1Id = $this->individualCreate();
@@ -63,7 +63,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
       'contact_id' => $this->_individualId,
       'receive_date' => '20120511',
       'total_amount' => 100.00,
-      'financial_type_id'   => $this->_financialTypeId,
+      'financial_type_id' => $this->_financialTypeId,
       'non_deductible_amount' => 10.00,
       'fee_amount' => 5.00,
       'net_amount' => 95.00,
@@ -83,27 +83,11 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     );
   }
 
-  function tearDown() {
-    $this->quickCleanup(array(
-      'civicrm_contribution',
-      'civicrm_event',
-      'civicrm_contribution_page',
-      'civicrm_participant',
-      'civicrm_participant_payment',
-      'civicrm_line_item',
-      'civicrm_financial_trxn',
-      'civicrm_financial_item',
-      'civicrm_entity_financial_trxn',
-      'civicrm_contact',
-      'civicrm_contribution_soft'
-    ));
-  }
-
   /**
    * Test get methods
    * @todo - this might be better broken down into more smaller tests
    */
-  function testGetContributionSoft() {
+  public function testGetContributionSoft() {
     //We don't test for PCP fields because there's no PCP API, so we can't create campaigns.
     $p = array(
       'contribution_id' => $this->_contributionId,
@@ -127,30 +111,31 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
 
     //create a second soft contribution on the same hard contribution - we are testing that 'id' gets the right soft contribution id (not the contribution id)
     $p['contact_id'] = $this->_softIndividual2Id;
-    $this->_softcontribution2 =  $this->callAPISuccess('contribution_soft', 'create', $p);
+    $this->_softcontribution2 = $this->callAPISuccess('contribution_soft', 'create', $p);
 
     // now we have 2 - test getcount
-    $softcontribution =  $this->callAPISuccess('contribution_soft', 'getcount', array());
+    $softcontribution = $this->callAPISuccess('contribution_soft', 'getcount', array());
     $this->assertEquals(2, $softcontribution);
 
     //check first contribution
-    $result =  $this->callAPISuccess('contribution_soft', 'get', array(
+    $result = $this->callAPISuccess('contribution_soft', 'get', array(
       'id' => $this->_softcontribution['id'],
     ));
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->assertEquals($this->_softcontribution['id'], $result['id']);
-    $this->assertEquals($this->_softcontribution['id'], $result['id'], print_r($softcontribution,true));
+    $this->assertEquals($this->_softcontribution['id'], $result['id'], print_r($softcontribution, TRUE));
 
     //test id only format - second soft credit
-    $resultID2 =  $this->callAPISuccess('contribution_soft', 'get', array(
+    $resultID2 = $this->callAPISuccess('contribution_soft', 'get', array(
       'id' => $this->_softcontribution2['id'],
       'format.only_id' => 1,
     ));
     $this->assertEquals($this->_softcontribution2['id'], $resultID2);
 
     //test get by contact id works
-    $result =  $this->callAPISuccess('contribution_soft', 'get', array(
-      'contact_id' => $this->_softIndividual2Id)
+    $result = $this->callAPISuccess('contribution_soft', 'get', array(
+        'contact_id' => $this->_softIndividual2Id
+      )
     );
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
 
@@ -162,28 +147,28 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     $this->callAPISuccess('contribution_soft', 'getcount', array(), $expectedCount);
 
     //check id is same as 2
-    $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', array('return' => 'id' )));
+    $this->assertEquals($this->_softcontribution2['id'], $this->callAPISuccess('contribution_soft', 'getvalue', array('return' => 'id')));
 
     $this->callAPISuccess('ContributionSoft', 'Delete', array(
       'id' => $this->_softcontribution2['id'],
-     ));
+    ));
   }
 
 
   ///////////////// civicrm_contribution_soft
-  function testCreateEmptyParamsContributionSoft() {
+  public function testCreateEmptyParamsContributionSoft() {
     $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(),
       'Mandatory key(s) missing from params array: contribution_id, amount, contact_id'
     );
   }
 
-  function testCreateParamsWithoutRequiredKeysContributionSoft() {
+  public function testCreateParamsWithoutRequiredKeysContributionSoft() {
     $softcontribution = $this->callAPIFailure('contribution_soft', 'create', array(),
       'Mandatory key(s) missing from params array: contribution_id, amount, contact_id'
     );
   }
 
-  function testCreateContributionSoftInvalidContact() {
+  public function testCreateContributionSoftInvalidContact() {
 
     $params = array(
       'contact_id' => 999,
@@ -197,7 +182,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     );
   }
 
-  function testCreateContributionSoftInvalidContributionId() {
+  public function testCreateContributionSoftInvalidContributionId() {
 
     $params = array(
       'contribution_id' => 999999,
@@ -211,10 +196,10 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     );
   }
 
-  /*
+  /**
    * Function tests that additional financial records are created when fee amount is recorded
    */
-  function testCreateContributionSoft() {
+  public function testCreateContributionSoft() {
     $params = array(
       'contribution_id' => $this->_contributionId,
       'contact_id' => $this->_softIndividual1Id,
@@ -232,7 +217,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
   }
 
   //To Update Soft Contribution
-  function testCreateUpdateContributionSoft() {
+  public function testCreateUpdateContributionSoft() {
     //create a soft credit
     $params = array(
       'contribution_id' => $this->_contributionId,
@@ -263,7 +248,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     $this->assertEquals($old_contact_id, $this->_softIndividual1Id, 'In line ' . __LINE__);
     $this->assertEquals($old_amount, 10.00, 'In line ' . __LINE__);
     $this->assertEquals($old_currency, 'USD', 'In line ' . __LINE__);
-    $this->assertEquals($old_soft_credit_type_id, 6 , 'In line ' . __LINE__);
+    $this->assertEquals($old_soft_credit_type_id, 6, 'In line ' . __LINE__);
     $params = array(
       'id' => $softcontributionID,
       'contribution_id' => $this->_contributionId,
@@ -293,19 +278,19 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
   }
 
   ///////////////// civicrm_contribution_soft_delete methods
-  function testDeleteEmptyParamsContributionSoft() {
+  public function testDeleteEmptyParamsContributionSoft() {
     $params = array();
     $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params);
   }
 
-  function testDeleteWrongParamContributionSoft() {
+  public function testDeleteWrongParamContributionSoft() {
     $params = array(
       'contribution_source' => 'SSF',
     );
     $softcontribution = $this->callAPIFailure('contribution_soft', 'delete', $params);
   }
 
-  function testDeleteContributionSoft() {
+  public function testDeleteContributionSoft() {
     //create a soft credit
     $params = array(
       'contribution_id' => $this->_contributionId,
@@ -328,7 +313,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
    *  Test civicrm_contribution_search with empty params.
    *  All available contributions expected.
    */
-  function testSearchEmptyParams() {
+  public function testSearchEmptyParams() {
     $p = array(
       'contribution_id' => $this->_contributionId,
       'contact_id' => $this->_softIndividual1Id,
@@ -350,7 +335,7 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
   /**
    *  Test civicrm_contribution_soft_search. Success expected.
    */
-  function testSearch() {
+  public function testSearch() {
     $p1 = array(
       'contribution_id' => $this->_contributionId,
       'contact_id' => $this->_softIndividual1Id,
@@ -376,7 +361,6 @@ class api_v3_ContributionSoftTest extends CiviUnitTestCase {
     $this->assertEquals($p2['contribution_id'], $res['contribution_id'], 'In line ' . __LINE__);
     $this->assertEquals($p2['contact_id'], $res['contact_id'], 'In line ' . __LINE__);
     $this->assertEquals($p2['amount'], $res['amount'], 'In line ' . __LINE__);
-    $this->assertEquals($p2['currency'], $res['currency'], 'In line ' . __LINE__ );
+    $this->assertEquals($p2['currency'], $res['currency'], 'In line ' . __LINE__);
   }
 }
-