+--------------------------------------------------------------------+
*/
-require_once 'CiviTest/Contact.php';
-require_once 'CiviTest/Custom.php';
-
/**
* Class CRM_Contribute_BAO_ContributionTest
* @group headless
class CRM_Contribute_BAO_ContributionTest extends CiviUnitTestCase {
/**
- * Create() method (create and update modes).
+ * Clean up after tests.
+ */
+ public function tearDown() {
+ $this->quickCleanUpFinancialEntities();
+ $this->quickCleanUpFinancialEntities(array('civicrm_event'));
+ parent::tearDown();
+ }
+
+ /**
+ * Test create method (create and update modes).
*/
public function testCreate() {
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
- $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
+ $this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transaction id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
//update contribution amount
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id .');
$this->assertEquals($params['net_amount'], $contribution->net_amount, 'Check for Amount updation.');
-
- //Delete Contribution
- $this->contributionDelete($contribution->id);
-
- //Delete Contact
- $this->contactDelete($contactId);
}
/**
* Create() method with custom data.
*/
public function testCreateWithCustomData() {
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
//create custom data
- $customGroup = Custom::createGroup(array(), 'Contribution');
+ $customGroup = $this->customGroupCreate(array('extends' => 'Contribution'));
+ $customGroupID = $customGroup['id'];
+ $customGroup = $customGroup['values'][$customGroupID];
+
$fields = array(
'label' => 'testFld',
'data_type' => 'String',
'html_type' => 'Text',
'is_active' => 1,
- 'custom_group_id' => $customGroup->id,
+ 'custom_group_id' => $customGroupID,
);
$customField = CRM_Core_BAO_CustomField::create($fields);
'value' => 'Test custom value',
'type' => 'String',
'custom_field_id' => $customField->id,
- 'custom_group_id' => $customGroup->id,
- 'table_name' => $customGroup->table_name,
+ 'custom_group_id' => $customGroupID,
+ 'table_name' => $customGroup['table_name'],
'column_name' => $customField->column_name,
'file_id' => NULL,
),
),
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
// Check that the custom field value is saved
$customValueParams = array(
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id for Conribution.');
-
- $this->contributionDelete($contribution->id);
- Custom::deleteField($customField);
- Custom::deleteGroup($customGroup);
- $this->contactDelete($contactId);
}
/**
* DeleteContribution() method
*/
public function testDeleteContribution() {
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
- $contributiondelete = CRM_Contribute_BAO_Contribution::deleteContribution($contribution->id);
+ CRM_Contribute_BAO_Contribution::deleteContribution($contribution->id);
$this->assertDBNull('CRM_Contribute_DAO_Contribution', $contribution->trxn_id,
'id', 'trxn_id', 'Database check for deleted Contribution.'
);
- $this->contactDelete($contactId);
}
/**
- * Create honor-contact method
+ * Create honor-contact method.
*/
- public function testcreateAndGetHonorContact() {
+ public function testCreateAndGetHonorContact() {
$firstName = 'John_' . substr(sha1(rand()), 0, 7);
$lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
$email = "{$firstName}.{$lastName}@example.com";
);
//create contribution on behalf of honary.
- $contactId = Contact::createIndividual();
- $softParam['contact_id'] = $honoreeContactId;
+ $contactId = $this->individualCreate(array('first_name' => 'John', 'last_name' => 'Doe'));
- $ids = array('contribution' => NULL);
$param = array(
'contact_id' => $contactId,
'currency' => 'USD',
'total_amount' => 66,
);
- $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($param);
$id = $contribution->id;
+ $softParam['contact_id'] = $honoreeContactId;
$softParam['contribution_id'] = $id;
$softParam['currency'] = $contribution->currency;
$softParam['amount'] = $contribution->total_amount;
$this->assertEquals(array(
$id => array(
'honor_type' => 'In Honor of',
- 'honorId' => $id,
- 'display_name' => 'John Doe',
+ 'honorId' => $contactId,
+ 'display_name' => 'Mr. John Doe II',
'type' => 'Event Fee',
'type_id' => '4',
'amount' => '$ 66.00',
$this->assertDBCompareValue('CRM_Contribute_DAO_Contribution', $id, 'total_amount',
'id', ltrim($annual[2], $currencySymbol), 'Check DB for total amount of the contribution'
);
-
- //Delete honor contact
- $this->contactDelete($honoreeContactId);
-
- //Delete Contribution record
- $this->contributionDelete($contribution->id);
-
- //Delete contributor contact
- $this->contactDelete($contactId);
}
/**
$sortName = CRM_Contribute_BAO_Contribution::sortName($contribution->id);
$this->assertEquals('Whatson, Shane', $sortName, 'Check for sort name.');
-
- //Delete Contribution
- $this->contributionDelete($contribution->id);
- //Delete Contact
- $this->contactDelete($contactId);
}
/**
* AddPremium();
*/
public function testAddPremium() {
- $contactId = Contact::createIndividual();
+ $contactId = $this->individualCreate();
$ids = array(
'premium' => NULL,
$this->assertDBNull('CRM_Contribute_DAO_Product', $premium->name,
'id', 'name', 'Database check for deleted Product.'
);
-
- //Delete Contribution
- $this->contributionDelete($contribution->id);
- //Delete Contact
- $this->contactDelete($contactId);
}
/**
* checkDuplicateIds();
*/
public function testcheckDuplicateIds() {
- $contactId = Contact::createIndividual();
-
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$param = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($param);
$this->assertEquals($param['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
);
$contributionID = CRM_Contribute_BAO_Contribution::checkDuplicateIds($data);
$this->assertEquals($contributionID, $contribution->id, 'Check for duplicate transcation id .');
-
- // Delete Contribution
- $this->contributionDelete($contribution->id);
- // Delete Contact
- $this->contactDelete($contactId);
}
/**
* createCreditNoteId();
*/
public function testCreateCreditNoteId() {
- $contactId = Contact::createIndividual();
-
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$param = array(
'contact_id' => $contactId,
);
$creditNoteId = CRM_Contribute_BAO_Contribution::createCreditNoteId();
- $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($param);
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
$this->assertEquals($creditNoteId, $contribution->creditnote_id, 'Check if credit note id is created correctly.');
-
- // Delete Contribution
- $this->contributionDelete($contribution->id);
- // Delete Contact
- $this->contactDelete($contactId);
}
/**
* Create() method (create and update modes).
*/
public function testIsPaymentFlag() {
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
$trxnArray['is_payment'] = 0;
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(NULL, $financialTrxn, 'Mismatch count for is payment flag.');
-
- //Delete Contribution
- $this->contributionDelete($contribution->id);
-
- //Delete Contact
- $this->contactDelete($contactId);
}
/**
* Create() method (create and update modes).
*/
public function testIsPaymentFlagForPending() {
- $contactId = Contact::createIndividual();
- $ids = array('contribution' => NULL);
+ $contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'thankyou_date' => '20080522',
);
- $contribution = CRM_Contribute_BAO_Contribution::create($params, $ids);
+ $contribution = CRM_Contribute_BAO_Contribution::create($params);
$this->assertEquals($params['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id creation.');
$trxnArray['is_payment'] = 0;
$financialTrxn = CRM_Core_BAO_FinancialTrxn::retrieve($trxnArray, $defaults);
$this->assertEquals(2, $financialTrxn->N, 'Mismatch count for is payment flag.');
-
- //Delete Contribution
- $this->contributionDelete($contribution->id);
-
- //Delete Contact
- $this->contactDelete($contactId);
}
/**
public function checkItemValues($contribution) {
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType(4, $relationTypeId);
- $query = "SELECT eft1.entity_id, ft.total_amount, eft1.amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution')
+ $query = "SELECT eft1.entity_id, ft.total_amount, eft1.amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution')
INNER JOIN civicrm_entity_financial_trxn eft1 ON (eft1.financial_trxn_id = eft.financial_trxn_id AND eft1.entity_table = 'civicrm_financial_item')
WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
$this->assertEquals(150.00, $dao->total_amount, 'Mismatch of total amount paid.');
$this->assertEquals($dao->amount, array_pop($amounts), 'Mismatch of amount proportionally assigned to financial item');
}
-
- $this->contactDelete($this->_contactId);
- Event::delete($this->_eventId);
}
/**
*/
public function addParticipantWithContribution() {
// creating price set, price field
- require_once 'CiviTest/Event.php';
- $this->_contactId = Contact::createIndividual();
- $this->_eventId = Event::create($this->_contactId);
+ $this->_contactId = $this->individualCreate();
+ $event = $this->eventCreate();
+ $this->_eventId = $event['id'];
$paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
$paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
$paramsSet['is_active'] = TRUE;
),
);
try {
- $error = CRM_Contribute_BAO_Contribution::checkLineItems($params);
+ CRM_Contribute_BAO_Contribution::checkLineItems($params);
$this->fail("Missed expected exception");
}
catch (Exception $e) {