<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
*/
protected $_ids = [];
-
public $DBResetRequired = TRUE;
+ /**
+ * Setup for test.
+ *
+ * @throws \CRM_Core_Exception
+ */
public function setUp() {
parent::setUp();
$this->contactIds[] = $this->individualCreate();
$this->params = [
- 'title' => "Test Contribution Page",
+ 'title' => 'Test Contribution Page',
'financial_type_id' => 1,
'currency' => 'NZD',
'goal_amount' => $this->testAmount,
];
}
+ /**
+ * Tear down after test.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
public function tearDown() {
foreach ($this->contactIds as $id) {
$this->callAPISuccess('contact', 'delete', ['id' => $id]);
}
/**
+ * Test creating a contribution page.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreateContributionPage($version) {
$this->_apiversion = $version;
}
/**
+ * Test getting a contribution page.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testGetBasicContributionPage($version) {
$this->_apiversion = $version;
$this->assertEquals(1, $getResult['count']);
}
+ /**
+ * Test get with amount as a parameter.
+ *
+ * @throws \CRM_Core_Exception
+ */
public function testGetContributionPageByAmount() {
$createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
$this->id = $createResult['id'];
}
/**
+ * Test page deletion.
+ *
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testDeleteContributionPage($version) {
$this->_apiversion = $version;
$this->assertEquals(0, $checkDeleted['count']);
}
+ /**
+ * Test getfields function.
+ *
+ * @throws \CRM_Core_Exception
+ */
public function testGetFieldsContributionPage() {
$result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
$this->assertEquals(12, $result['values']['start_date']['type']);
/**
* Test form submission with basic price set.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmit() {
$this->setUpContributionPage();
/**
* Test form submission with billing first & last name where the contact does NOT
* otherwise have one.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitNewBillingNameData() {
$this->setUpContributionPage();
* Test process with instant payment when more than one configured for the page.
*
* CRM-16923
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
public function testSubmitRecurMultiProcessorInstantPayment() {
$this->setUpContributionPage();
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockNotSeparatePayment() {
$this->setUpMembershipContributionPage();
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
-
+ 'selectMembership' => $this->_ids['membership_type'][0],
];
- $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
+ $this->callAPIAndDocument('ContributionPage', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
$contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
$membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
$this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]);
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-bridge.net',
'payment_processor_id' => $this->_paymentProcessor['id'],
'credit_card_number' => '4111111111111111',
/**
* Test submit with a membership block in place.
+ *
+ * @throws \Exception
*/
public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruffier',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-new-bridge.net',
'payment_processor_id' => $this->params['payment_processor_id'],
];
/**
* Test submit with a pay later abnd check line item in mails.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'is_pay_later' => 1,
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'email-Primary' => 'billy-goat@the-bridge.net',
];
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockIsSeparatePayment() {
$this->setUpMembershipContributionPage(TRUE);
$submitParams = [
'price_' . $this->_ids['price_field'][0] => reset($this->_ids['price_field_value']),
'id' => (int) $this->_ids['contribution_page'],
- 'amount' => 10,
'billing_first_name' => 'Billy',
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
+ 'amount' => 10,
];
- $this->callAPISuccess('contribution_page', 'submit', $submitParams);
+ $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
$contributions = $this->callAPISuccess('contribution', 'get', ['contribution_page_id' => $this->_ids['contribution_page']]);
$this->assertCount(2, $contributions['values']);
$lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1]);
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() {
$this->setUpMembershipContributionPage(TRUE);
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() {
$mut = new CiviMailUtils($this, TRUE);
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
$this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 6])];
* Test submit with a membership block in place.
*
* We are expecting a separate payment for the membership vs the contribution.
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() {
$mut = new CiviMailUtils($this, TRUE);
* @param string $thousandSeparator
* punctuation used to refer to thousands.
*
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ *
* @dataProvider getThousandSeparators
*/
public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNowChargesCorrectAmounts($thousandSeparator) {
// set custom hook
$this->hookClass->setHook('civicrm_alterPaymentProcessorParams', [$this, 'hook_civicrm_alterPaymentProcessorParams']);
- $this->callAPISuccess('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
- $contributions = $this->callAPISuccess('contribution', 'get', [
+ $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
+ $this->callAPISuccess('contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
]);
* Test that when a transaction fails the pending contribution remains.
*
* An activity should also be created. CRM-16417.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitPaymentProcessorFailure() {
$this->setUpContributionPage();
* 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 testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentYear() {
$this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'year', 'recur_frequency_unit' => 'year']);
* @param array $params
*
* @throws \CRM_Core_Exception
- * @throws \Exception
*/
public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = []) {
$this->params['is_recur'] = 1;
* 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 testSubmitMembershipComplexNonPriceSetPaymentPaymentProcessorRecurInstantPayment() {
$this->params['is_recur'] = 1;
* 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 testSubmitMembershipComplexPriceSetPaymentPaymentProcessorRecurInstantPayment() {
$this->params['is_recur'] = 1;
/**
* Extend the price set with a second organisation's membership.
+ *
+ * @throws \CRM_Core_Exception
*/
public function addSecondOrganizationMembershipToPriceSet() {
$organization2ID = $this->organizationCreate();
* 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 testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePaymentRecurInstantPayment() {
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
'frequency_unit' => 'month',
];
- $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
+ $this->callAPIAndDocument('ContributionPage', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
$contribution = $this->callAPISuccess('contribution', 'get', [
'contribution_page_id' => $this->_ids['contribution_page'],
'contribution_status_id' => 1,
* - the first creates a pending membership, pending contribution, penging recurring. Check these
* - complete the transaction
* - create another - end date should NOT be extended
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() {
$this->params['is_recur'] = 1;
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
/**
* Test non-recur contribution with membership payment
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMembershipIsSeparatePaymentNotRecur() {
//Create recur contribution page.
'billing_middle_name' => 'Goat',
'billing_last_name' => 'Gruff',
'email' => 'billy@goat.gruff',
- 'selectMembership' => $this->_ids['membership_type'],
+ 'selectMembership' => $this->_ids['membership_type'][0],
'payment_processor_id' => 1,
'credit_card_number' => '4111111111111111',
'credit_card_type' => 'Visa',
/**
* Set up membership contribution page.
+ *
* @param bool $isSeparatePayment
* @param bool $isRecur
* @param array $membershipTypeParams Parameters to pass to membershiptype.create API
+ *
+ * @throws \CRM_Core_Exception
*/
public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = []) {
$this->setUpMembershipBlockPriceSet($membershipTypeParams);
* The default data set does not include a complete default membership price set - not quite sure why.
*
* This function ensures it exists & populates $this->_ids with it's data
+ *
+ * @throws \CRM_Core_Exception
*/
public function setUpMembershipBlockPriceSet($membershipTypeParams = []) {
$this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', [
/**
* Add text field other amount to the price set.
+ *
+ * @throws \CRM_Core_Exception
*/
public function addOtherAmountFieldToMembershipPriceSet() {
$this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', [
/**
* Help function to set up contribution page with some defaults.
+ *
* @param bool $isRecur
+ *
+ * @throws \CRM_Core_Exception
*/
public function setUpContributionPage($isRecur = FALSE) {
if ($isRecur) {
/**
* Helper function to set up contribution page which can be used to purchase a
* membership type for different intervals.
+ *
+ * @throws \CRM_Core_Exception
*/
public function setUpMultiIntervalMembershipContributionPage() {
$this->setupPaymentProcessor();
'duration_unit' => 'month',
]);
- $priceSet = civicrm_api3('PriceSet', 'create', [
+ $priceSet = $this->callAPISuccess('PriceSet', 'create', [
'is_quick_config' => 0,
'extends' => 'CiviMember',
'financial_type_id' => 'Member Dues',
/**
* Test submit with a membership block in place.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitMultiIntervalMembershipContributionPage() {
$this->setUpMultiIntervalMembershipContributionPage();
// put stuff here that should happen before all tests in this unit
}
- /**
- * @throws \Exception
- */
- public static function tearDownAfterClass() {
- $tablesToTruncate = [
- 'civicrm_contact',
- 'civicrm_financial_type',
- 'civicrm_contribution',
- 'civicrm_contribution_page',
- ];
- $unitTest = new CiviUnitTestCase();
- $unitTest->quickCleanup($tablesToTruncate);
- }
-
/**
* Create a payment processor instance.
+ *
+ * @throws \CRM_Core_Exception
*/
protected function setupPaymentProcessor() {
$this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate([
* Test submit recurring pledge.
*
* - we process 1 pledge with a future start date. A recur contribution and the pledge should be created with first payment date in the future.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() {
$this->params['adjust_recur_start_date'] = TRUE;
* Test submit pledge payment.
*
* - test submitting a pledge payment using contribution form.
+ *
+ * @throws \CRM_Core_Exception
*/
public function testSubmitPledgePayment() {
$this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment();
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
+ * @throws \CRM_Core_Exception
*/
public function testSubmitContributionPageWithPriceSet($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
/**
* Function to add additional price fields to priceset.
+ *
* @param array $params
+ *
+ * @throws \CRM_Core_Exception
*/
public function addPriceFields(&$params) {
$priceSetID = reset($this->_ids['price_set']);
* punctuation used to refer to thousands.
*
* @dataProvider getThousandSeparators
+ * @throws \CRM_Core_Exception
*/
public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);