protected $params;
protected $id = 0;
protected $contactIds = [];
- protected $_entity = 'contribution_page';
+ protected $_entity = 'ContributionPage';
protected $contribution_result = NULL;
protected $_priceSetParams = [];
protected $_membershipBlockAmount = 2;
*/
protected $_ids = [];
- public $DBResetRequired = TRUE;
-
/**
* Setup for test.
*
* Tear down after test.
*
* @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
*/
public function tearDown() {
foreach ($this->contactIds as $id) {
* @throws \CRM_Core_Exception
*/
public function testCreateContributionPage($version) {
- $this->_apiversion = $version;
- $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
- $this->assertEquals(1, $result['count']);
- $this->assertNotNull($result['values'][$result['id']]['id']);
- $this->getAndCheck($this->params, $result['id'], $this->_entity);
+ $this->basicCreateTest($version);
}
/**
* @throws \CRM_Core_Exception
*/
public function testDeleteContributionPage($version) {
- $this->_apiversion = $version;
- $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = ['id' => $createResult['id']];
- $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
- $this->assertEquals(0, $checkDeleted['count']);
+ $this->basicDeleteTest($version);
}
/**
/**
* Test form submission with basic price set.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitZeroDollar() {
$this->setUpContributionPage();
/**
* Test form submission with billing first & last name where the contact does
* otherwise have one and should not be overwritten.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitNewBillingNameDoNotOverwrite() {
$this->setUpContributionPage();
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', []);
$this->assertTrue(in_array($membershipPayment['contribution_id'], array_keys($contributions['values'])));
$membership = $this->callAPISuccessGetSingle('membership', ['id' => $membershipPayment['membership_id']]);
- $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', [
- 'return' => ["id"],
- 'name' => "Pending",
- ]);
+ $pendingStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['return' => ['id'], 'name' => 'Pending']);
$this->assertEquals($membership['status_id'], $pendingStatus['id']);
$this->assertEquals($membership['contact_id'], $contributions['values'][$membershipPayment['contribution_id']]['contact_id']);
}
* processor (IATS style - denoted by returning trxn_id)
* - the first creates a new membership, completed contribution, in progress recurring. Check these
* - create another - end date should be extended
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentMonth() {
$this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'month', 'recur_frequency_unit' => 'month']);
$dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
$dummyPP->setDoDirectPaymentResult(['payment_status_id' => 1, 'trxn_id' => 'create_first_success']);
- //Sumbit payment with recur disabled.
+ //Submit payment with recur disabled.
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
$this->assertEquals(100.00, $contribution['total_amount']);
$pledgePayment = $this->callAPISuccess('pledge_payment', 'get', $params);
- $this->assertEquals($pledgePayment['values'][2]['status_id'], 1, "This pledge payment should have been completed");
+ $this->assertEquals($pledgePayment['values'][2]['status_id'], 1, 'This pledge payment should have been completed');
$this->assertEquals($pledgePayment['values'][2]['contribution_id'], $contribution['id']);
}
$this->assertEquals(3, $lineItems['count']);
$totalLineAmount = 0;
foreach ($lineItems['values'] as $lineItem) {
- $totalLineAmount = $totalLineAmount + $lineItem['line_total'];
+ $totalLineAmount += $lineItem['line_total'];
}
$this->assertEquals(80, $totalLineAmount);
}
$financialType = $this->createFinancialType();
$financialTypeId = $financialType['id'];
// This function sets the Tax Rate at 10% - it currently has no way to pass Tax Rate into it - so let's work with 10%
- $this->relationForFinancialTypeWithFinancialAccount($financialType['id'], 5);
+ $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
$this->setUpContributionPage();
$submitParams = [
'label' => 'Printing Rights',
'html_type' => 'Text',
]);
- $priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
+ $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Printing Rights',
*
* For example Paypal Checkout will replace the confirm button with it's own but we are able to validate
* before paypal launches it's modal. In this case the $_REQUEST is post but we need validation to succeed.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testValidatePost() {
$_SERVER['REQUEST_METHOD'] = 'POST';
/**
* Test that an error is generated if required fields are not submitted.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testValidateOutputOnMissingRecurFields() {
$this->params['is_recur_interval'] = 1;
protected function getBasicSubmitParams() {
$priceFieldID = reset($this->_ids['price_field']);
$priceFieldValueID = reset($this->_ids['price_field_value']);
- $submitParams = [
+ return [
'price_' . $priceFieldID => $priceFieldValueID,
'id' => (int) $this->_ids['contribution_page'],
'amount' => 10,
'priceSetId' => $this->_ids['price_set'][0],
'payment_processor_id' => 0,
];
- return $submitParams;
}
}
* @group headless
*/
class api_v3_ContributionRecurTest extends CiviUnitTestCase {
- protected $_apiversion = 3;
protected $params;
- protected $ids = [];
- protected $_entity = 'contribution_recur';
+ protected $_entity = 'ContributionRecur';
public $DBResetRequired = FALSE;
+ /**
+ * @throws \CRM_Core_Exception
+ */
public function setUp() {
parent::setUp();
- $this->useTransaction(TRUE);
+ $this->useTransaction();
$this->ids['contact'][0] = $this->individualCreate();
$this->params = [
'contact_id' => $this->ids['contact'][0],
];
}
- public function testCreateContributionRecur() {
- $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params, __FUNCTION__, __FILE__);
- $this->assertEquals(1, $result['count']);
- $this->assertNotNull($result['values'][$result['id']]['id']);
- $this->getAndCheck($this->params, $result['id'], $this->_entity);
+ /**
+ * Basic create test.
+ *
+ * @dataProvider versionThreeAndFour
+ *
+ * @param int $version
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testCreateContributionRecur($version) {
+ $this->basicCreateTest($version);
}
- public function testGetContributionRecur() {
+ /**
+ * Basic get test.
+ *
+ * @dataProvider versionThreeAndFour
+ *
+ * @param int $version
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testGetContributionRecur($version) {
+ $this->_apiversion = $version;
$this->callAPISuccess($this->_entity, 'create', $this->params);
- $getParams = [
- 'amount' => '500',
- ];
+ $getParams = ['amount' => '500'];
$result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
}
+ /**
+ * @dataProvider versionThreeAndFour
+ *
+ * @throws \CRM_Core_Exception
+ */
public function testCreateContributionRecurWithToken() {
// create token
$this->createLoggedInUser();
$this->getAndCheck($this->params, $result['id'], $this->_entity);
}
- public function testDeleteContributionRecur() {
- $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
- $deleteParams = ['id' => $result['id']];
- $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
- $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []);
- $this->assertEquals(0, $checkDeleted['count']);
+ /**
+ * @dataProvider versionThreeAndFour
+ *
+ * @param $version
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testDeleteContributionRecur($version) {
+ $this->basicDeleteTest($version);
}
+ /**
+ * Test expected apiv3 outputs.
+ *
+ * @throws \CRM_Core_Exception
+ */
public function testGetFieldsContributionRecur() {
$result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(12, $result['values']['start_date']['type']);
/**
* Test that we can cancel a contribution and add a cancel_reason via the api.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testContributionRecurCancel() {
$result = $this->callAPISuccess($this->_entity, 'create', $this->params);