Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more tests to use the full form flow #21906

Merged
merged 1 commit into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions ext/contributioncancelactions/tests/phpunit/CancelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public function testPaypalProCancel(): void {
/**
* Create an order with more than one membership.
*
* @throws \CRM_Core_Exception
*/
protected function createMembershipOrder(): void {
$priceFieldID = $this->callAPISuccessGetValue('price_field', [
Expand Down Expand Up @@ -182,9 +181,8 @@ protected function createMembershipType(): void {
* @param array $params
*
* @return int
* @throws \CRM_Core_Exception
*/
public function createPaymentProcessor($params = []): int {
public function createPaymentProcessor(array $params = []): int {
$params = array_merge([
'name' => 'demo',
'domain_id' => CRM_Core_Config::domainID(),
Expand Down Expand Up @@ -245,7 +243,6 @@ public function testPaypalStandardCancel(): void {
/**
* Test cancel order api
* @throws API_Exception
* @throws CRM_Core_Exception
*/
public function testCancelOrderWithParticipant(): void {
$this->createContact();
Expand All @@ -261,24 +258,25 @@ public function testCancelOrderWithParticipant(): void {
* form.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testCancelFromContributionForm(): void {
$this->createContact();
$this->createMembershipType();
$this->createMembershipOrder();
$this->createLoggedInUser();
$formValues = [
'id' => $this->ids['Contribution'][0],
'contact_id' => $this->ids['contact'][0],
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'),
];
$form = new CRM_Contribute_Form_Contribution();
$_SERVER['REQUEST_METHOD'] = 'GET';
$form->controller = new CRM_Core_Controller();
$form->controller->setStateMachine(new CRM_Core_StateMachine($form->controller));
$form->testSubmit($formValues, CRM_Core_Action::UPDATE);
$_SESSION['_' . $form->controller->_name . '_container']['values']['Contribution'] = $formValues;
$_REQUEST['action'] = 'update';
$_REQUEST['id'] = $this->ids['Contribution'][0];
$form->buildForm();
$form->postProcess();

$contribution = Contribution::get()
->addWhere('id', '=', $this->ids['Contribution'][0])
Expand All @@ -300,7 +298,6 @@ public function testCancelFromContributionForm(): void {
*
* @return int
* @throws API_Exception
* @throws CRM_Core_Exception
*/
protected function createEventOrder(): int {
$this->ids['event'][0] = (int) Event::create()->setValues(['title' => 'Event', 'start_date' => 'tomorrow', 'event_type_id:name' => 'Workshop'])->execute()->first()['id'];
Expand Down
21 changes: 8 additions & 13 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3449,9 +3449,7 @@ public function testCompleteTransactionMembershipPriceSet(): void {
* Test if renewal activity is create after changing Pending contribution to
* Completed via offline
*
* @throws \CRM_Core_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception|\CiviCRM_API3_Exception
*/
public function testPendingToCompleteContribution(): void {
$this->createPriceSetWithPage('membership');
Expand All @@ -3464,12 +3462,11 @@ public function testPendingToCompleteContribution(): void {
'status_id' => 'Scheduled',
]);
$this->assertEquals(1, $activity['count']);

$_REQUEST['id'] = $this->getContributionID();
$_REQUEST['action'] = 'update';
// change pending contribution to completed
$form = new CRM_Contribute_Form_Contribution();

$form->_params = [
'id' => $this->getContributionID(),
/* @var CRM_Contribute_Form_Contribution $form */
$form = $this->getFormObject('CRM_Contribute_Form_Contribution', [
'total_amount' => 20,
'net_amount' => 20,
'fee_amount' => 0,
Expand All @@ -3489,15 +3486,13 @@ public function testPendingToCompleteContribution(): void {
'hidden_AdditionalDetail' => 1,
'hidden_Premium' => 1,
'from_email_address' => '"civi45" <civi45@civicrm.com>',
'receipt_date' => '',
'receipt_date_time' => '',
'payment_processor_id' => $this->paymentProcessorID,
'currency' => 'USD',
'contribution_page_id' => $this->_ids['contribution_page'],
'source' => 'Membership Signup and Renewal',
];

$form->testSubmit($form->_params, CRM_Core_Action::UPDATE);
]);
$form->buildForm();
$form->postProcess();

// Case 2: After successful payment for Pending backoffice there are three activities created
// 2.a Update status of existing Scheduled Membership Signup (created in step 1) to Completed
Expand Down
15 changes: 9 additions & 6 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public function testMembershipDeletePreserveContribution() {
* Test Activity creation on cancellation of membership contribution.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testActivityForCancelledContribution(): void {
// @todo figure out why financial validation fails with this test.
Expand All @@ -160,16 +159,20 @@ public function testActivityForCancelledContribution(): void {

$this->createContributionAndMembershipOrder();
$membershipID = $this->callAPISuccessGetValue('MembershipPayment', ['return' => 'id']);
$form = new CRM_Contribute_Form_Contribution();
$form->_id = $this->ids['Contribution'][0];
$form->testSubmit([

$_REQUEST['id'] = $this->ids['Contribution'][0];
$_REQUEST['action'] = 'update';
// change pending contribution to completed
/* @var CRM_Contribute_Form_Contribution $form */
$form = $this->getFormObject('CRM_Contribute_Form_Contribution', [
'total_amount' => 100,
'financial_type_id' => 1,
'contact_id' => $contactId,
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'contribution_status_id' => 3,
],
CRM_Core_Action::UPDATE);
]);
$form->buildForm();
$form->postProcess();

$this->callAPISuccessGetSingle('Activity', [
'activity_type_id' => 'Membership Signup',
Expand Down