diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index d5ca8938cee0..273c243b184b 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -662,9 +662,13 @@ public function membershipRenewalDate($durationUnit, $membershipEndDate) { } /** + * Create a relationship type. + * * @param array $params * - * @return mixed + * @return int + * + * @throws \CRM_Core_Exception */ public function relationshipTypeCreate($params = []) { $params = array_merge([ @@ -699,6 +703,7 @@ public function relationshipTypeDelete($relationshipTypeID) { * @param array $params * * @return mixed + * @throws \CRM_Core_Exception */ public function paymentProcessorTypeCreate($params = NULL) { if (is_null($params)) { @@ -980,6 +985,7 @@ public function contributionCreate($params) { * @param int $contributionId * * @return array|int + * @throws \CRM_Core_Exception */ public function contributionDelete($contributionId) { $params = [ @@ -1866,7 +1872,7 @@ public function restoreDefaultPriceSetConfig() { * @param int $delete * @param string $errorText * - * @throws Exception + * @throws CRM_Core_Exception */ public function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') { @@ -2971,6 +2977,10 @@ protected function createPaymentInstrument($params = [], $financialAccountName = /** * Enable Tax and Invoicing + * + * @param array $params + * + * @return \Civi\Core\SettingsBag */ protected function enableTaxAndInvoicing($params = []) { // Enable component contribute setting diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 046c419fbf36..6e75c6ee8382 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -56,14 +56,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { */ 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, @@ -83,6 +87,12 @@ public function setUp() { ]; } + /** + * 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]); @@ -92,8 +102,12 @@ public function tearDown() { } /** + * Test creating a contribution page. + * * @param int $version + * * @dataProvider versionThreeAndFour + * @throws \CRM_Core_Exception */ public function testCreateContributionPage($version) { $this->_apiversion = $version; @@ -104,8 +118,12 @@ public function testCreateContributionPage($version) { } /** + * Test getting a contribution page. + * * @param int $version + * * @dataProvider versionThreeAndFour + * @throws \CRM_Core_Exception */ public function testGetBasicContributionPage($version) { $this->_apiversion = $version; @@ -119,6 +137,11 @@ public function testGetBasicContributionPage($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']; @@ -133,8 +156,12 @@ public function testGetContributionPageByAmount() { } /** + * Test page deletion. + * * @param int $version + * * @dataProvider versionThreeAndFour + * @throws \CRM_Core_Exception */ public function testDeleteContributionPage($version) { $this->_apiversion = $version; @@ -145,6 +172,11 @@ public function testDeleteContributionPage($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']); @@ -152,6 +184,8 @@ public function testGetFieldsContributionPage() { /** * Test form submission with basic price set. + * + * @throws \CRM_Core_Exception */ public function testSubmit() { $this->setUpContributionPage(); @@ -187,6 +221,8 @@ public function testSubmitZeroDollar() { /** * 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(); @@ -273,6 +309,9 @@ public function testSubmitNewBillingNameDoNotOverwrite() { * 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(); @@ -325,6 +364,8 @@ public function testSubmitRecurMultiProcessorInstantPayment() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockNotSeparatePayment() { $this->setUpMembershipContributionPage(); @@ -336,10 +377,9 @@ public function testSubmitMembershipBlockNotSeparatePayment() { 'billing_middle_name' => 'Goat', 'billing_last_name' => 'Gruff', 'selectMembership' => $this->_ids['membership_type'], - ]; - $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']]); @@ -395,6 +435,8 @@ public function testSubmitMembershipBlockNotSeparatePaymentProcessorInstantRenew /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() { $mut = new CiviMailUtils($this, TRUE); @@ -430,6 +472,8 @@ public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() { /** * Test submit with a membership block in place. + * + * @throws \Exception */ public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() { $mut = new CiviMailUtils($this, TRUE); @@ -468,6 +512,8 @@ public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail( /** * Test submit with a pay later abnd check line item in mails. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() { $mut = new CiviMailUtils($this, TRUE); @@ -496,6 +542,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockIsSeparatePayment() { $this->setUpMembershipContributionPage(TRUE); @@ -523,6 +571,8 @@ public function testSubmitMembershipBlockIsSeparatePayment() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() { $this->setUpMembershipContributionPage(TRUE); @@ -560,6 +610,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() { $mut = new CiviMailUtils($this, TRUE); @@ -607,6 +659,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() { $mut = new CiviMailUtils($this, TRUE); @@ -644,6 +698,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWit /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() { $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 6])]; @@ -736,6 +792,9 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() * @param string $thousandSeparator * punctuation used to refer to thousands. * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception + * * @dataProvider getThousandSeparators */ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNowChargesCorrectAmounts($thousandSeparator) { @@ -765,8 +824,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNowCha // 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, ]); @@ -809,6 +868,8 @@ public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNowCha * 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(); @@ -847,6 +908,8 @@ public function testSubmitPaymentProcessorFailure() { * 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']); @@ -881,7 +944,6 @@ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantP * @param array $params * * @throws \CRM_Core_Exception - * @throws \Exception */ public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = []) { $this->params['is_recur'] = 1; @@ -970,6 +1032,8 @@ public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPay * 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; @@ -1054,6 +1118,8 @@ public function testSubmitMembershipComplexNonPriceSetPaymentPaymentProcessorRec * 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; @@ -1135,6 +1201,8 @@ public function testSubmitMembershipComplexPriceSetPaymentPaymentProcessorRecurI /** * Extend the price set with a second organisation's membership. + * + * @throws \CRM_Core_Exception */ public function addSecondOrganizationMembershipToPriceSet() { $organization2ID = $this->organizationCreate(); @@ -1188,6 +1256,8 @@ public function addSecondOrganizationMembershipToPriceSet() { * 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() { @@ -1215,7 +1285,7 @@ public function testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePayme '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, @@ -1235,6 +1305,8 @@ public function testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePayme * - 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; @@ -1325,6 +1397,8 @@ public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed( /** * Test non-recur contribution with membership payment + * + * @throws \CRM_Core_Exception */ public function testSubmitMembershipIsSeparatePaymentNotRecur() { //Create recur contribution page. @@ -1359,9 +1433,12 @@ public function testSubmitMembershipIsSeparatePaymentNotRecur() { /** * 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); @@ -1397,6 +1474,8 @@ public function setUpPledgeBlock() { * 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', [ @@ -1473,6 +1552,8 @@ public function setUpMembershipBlockPriceSet($membershipTypeParams = []) { /** * 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', [ @@ -1494,7 +1575,10 @@ public function addOtherAmountFieldToMembershipPriceSet() { /** * Help function to set up contribution page with some defaults. + * * @param bool $isRecur + * + * @throws \CRM_Core_Exception */ public function setUpContributionPage($isRecur = FALSE) { if ($isRecur) { @@ -1552,6 +1636,8 @@ public function setUpContributionPage($isRecur = FALSE) { /** * 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(); @@ -1564,7 +1650,7 @@ public function setUpMultiIntervalMembershipContributionPage() { 'duration_unit' => 'month', ]); - $priceSet = civicrm_api3('PriceSet', 'create', [ + $priceSet = $this->callAPISuccess('PriceSet', 'create', [ 'is_quick_config' => 0, 'extends' => 'CiviMember', 'financial_type_id' => 'Member Dues', @@ -1616,6 +1702,8 @@ public function setUpMultiIntervalMembershipContributionPage() { /** * Test submit with a membership block in place. + * + * @throws \CRM_Core_Exception */ public function testSubmitMultiIntervalMembershipContributionPage() { $this->setUpMultiIntervalMembershipContributionPage(); @@ -1651,22 +1739,10 @@ public static function setUpBeforeClass() { // 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([ @@ -1681,6 +1757,8 @@ protected function setupPaymentProcessor() { * 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; @@ -1749,6 +1827,8 @@ public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() { * Test submit pledge payment. * * - test submitting a pledge payment using contribution form. + * + * @throws \CRM_Core_Exception */ public function testSubmitPledgePayment() { $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment(); @@ -1801,6 +1881,7 @@ public function testSubmitPledgePayment() { * punctuation used to refer to thousands. * * @dataProvider getThousandSeparators + * @throws \CRM_Core_Exception */ public function testSubmitContributionPageWithPriceSet($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator); @@ -1836,7 +1917,10 @@ public function testSubmitContributionPageWithPriceSet($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']); @@ -1872,6 +1956,7 @@ public function addPriceFields(&$params) { * punctuation used to refer to thousands. * * @dataProvider getThousandSeparators + * @throws \CRM_Core_Exception */ public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparator) { $this->setCurrencySeparators($thousandSeparator);