Skip to content

Commit

Permalink
Merge pull request #21846 from eileenmcnaughton/nfc
Browse files Browse the repository at this point in the history
Preparatory cleanup in test class
  • Loading branch information
eileenmcnaughton authored Oct 17, 2021
2 parents f159e8a + 96ff106 commit 4189204
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions tests/phpunit/CRM/Pledge/BAO/PledgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase {

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @throws \CiviCRM_API3_Exception
* Sets up the test data.
*/
protected function setUp(): void {
parent::setUp();
Expand All @@ -45,8 +42,6 @@ protected function setUp(): void {

/**
* Test for Add/Update Pledge.
*
* @throws \CRM_Core_Exception
*/
public function testAdd(): void {
//do test for normal add.
Expand All @@ -63,11 +58,9 @@ public function testAdd(): void {
/**
* Test Pledge Payment Status with 1 installment
* and not passing status id.
*
* @throws \CRM_Core_Exception
*/
public function testPledgePaymentStatus(): void {
$scheduledDate = date('Ymd', mktime(0, 0, 0, date("m"), date("d") + 2, date("y")));
$scheduledDate = date('Ymd', mktime(0, 0, 0, date('m'), date('d') + 2, date('y')));
$this->_params['installments'] = 1;
$this->_params['scheduled_date'] = $scheduledDate;

Expand All @@ -78,15 +71,13 @@ public function testPledgePaymentStatus(): void {
$this->assertCount(1, $pledgePayment);
$payment = array_pop($pledgePayment);
// Assert that we actually have no pledge Payments
$this->assertEquals(0, CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($pledge['id'], array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))));
$this->assertEquals(0, CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($pledge['id'], array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'), TRUE)));
$this->assertEquals('Pending', $payment['status']);
$this->assertEquals($payment['scheduled_date'], date('Y-m-d 00:00:00', strtotime($scheduledDate)));
}

/**
* Test that payment retrieve wrks based on known pledge id.
*
* @throws \CRM_Core_Exception
* Test that payment retrieve works based on known pledge id.
*/
public function testRetrieveKnownPledgeID(): void {
$params = [
Expand All @@ -112,13 +103,13 @@ public function testRetrieveKnownPledgeID(): void {

$pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults);

$this->assertEquals(1, $pledgeId->N, "Pledge was retrieved");
$this->assertEquals(1, $pledgeId->N, 'Pledge was retrieved');
}

/**
* Test build recur params.
*/
public function testGetPledgeStartDate() {
public function testGetPledgeStartDate(): void {
$startDate = json_encode(['calendar_month' => 6]);

$params = [
Expand All @@ -131,7 +122,7 @@ public function testGetPledgeStartDate() {
$date = CRM_Pledge_BAO_Pledge::getPledgeStartDate(6, $params);
$paymentDate = CRM_Pledge_BAO_Pledge::getPaymentDate(6);

$this->assertEquals(date('m/d/Y', strtotime($date)), $paymentDate, "The two dates do not match");
$this->assertEquals(date('m/d/Y', strtotime($date)), $paymentDate, 'The two dates do not match');

// Try with fixed date
$date = NULL;
Expand All @@ -141,7 +132,7 @@ public function testGetPledgeStartDate() {
];

$date = CRM_Pledge_BAO_Pledge::getPledgeStartDate($date, $params);
$this->assertEquals(date('m/d/Y', strtotime($date)), '06/10/2016', "The two dates do not match");
$this->assertEquals('06/10/2016', date('m/d/Y', strtotime($date)), 'The two dates do not match');
}

}

0 comments on commit 4189204

Please sign in to comment.