->addWhere('id', '=', $fromParticipantID)
->execute()
->first();
-
+ $participantPayments = civicrm_api3('ParticipantPayment', 'get', [
+ 'return' => 'id',
+ 'participant_id' => $fromParticipantID,
+ ])['values'];
unset($toParticipantValues['id']);
$toParticipantValues['contact_id'] = $toContactID;
$toParticipantValues['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Event_BAO_Participant', 'status_id', 'Registered');
$toParticipantValues['register_date'] = date("Y-m-d");
//first create the new participant row -don't set registered_by yet or email won't be sent
$participant = CRM_Event_BAO_Participant::create($toParticipantValues);
-
+ foreach ($participantPayments as $payment) {
+ civicrm_api3('ParticipantPayment', 'create', ['id' => $payment['id'], 'participant_id' => $participant->id]);
+ }
//send a confirmation email to the new participant
$this->participantTransfer($participant);
//now update registered_by_id
$line_items = CRM_Price_BAO_LineItem::getLineItems($fromParticipantID);
foreach ($line_items as $id => $item) {
//Remove contribution id from older participant line item.
- CRM_Core_DAO::singleValueQuery("UPDATE civicrm_line_item SET contribution_id = NULL WHERE id = %1", [1 => [$id, 'Integer']]);
+ CRM_Core_DAO::singleValueQuery('UPDATE civicrm_line_item SET contribution_id = NULL WHERE id = %1', [1 => [$id, 'Integer']]);
+
$item['entity_id'] = $participant->id;
$item['id'] = NULL;
$item['entity_table'] = "civicrm_participant";
*/
class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
+ use CRMTraits_Financial_OrderTrait;
/**
* Options on the from Email address array.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testTransferParticipantRegistration() {
+ public function testTransferParticipantRegistration(): void {
//Register a contact to a sample event.
- $this->createParticipantRecordsFromTwoFieldPriceSet();
- $contribution = $this->callAPISuccessGetSingle('Contribution', []);
+ $this->createEventOrder();
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'id']);
//Check line item count of the contribution id before transfer.
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
- $this->assertEquals(count($lineItems), 2);
+ $this->assertCount(2, $lineItems);
$participantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $contribution['id'], 'participant_id', 'contribution_id');
/* @var CRM_Event_Form_SelfSvcTransfer $form */
$form = $this->getFormObject('CRM_Event_Form_SelfSvcTransfer');
//Assert participant is transferred to $toContactId.
$participant = $this->callAPISuccess('Participant', 'getsingle', [
- 'return' => ["transferred_to_contact_id"],
+ 'return' => ['transferred_to_contact_id'],
'id' => $participantId,
]);
$this->assertEquals($participant['transferred_to_contact_id'], $toContactId);
//Check line item count of the contribution id remains the same.
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution['id']);
- $this->assertEquals(count($lineItems), 2);
+ $this->assertCount(2, $lineItems);
+ // There should be 2 participant payments on the contribution & 0 others existing.
+ $this->callAPISuccessGetCount('ParticipantPayment', ['contribution_id' => $contribution['id']], 2);
+ $this->callAPISuccessGetCount('ParticipantPayment', [], 2);
+ $this->callAPISuccessGetCount('ParticipantPayment', ['participant_id' => $toParticipant['id']], 1);
+ $this->callAPISuccessGetCount('ParticipantPayment', ['participant_id' => $participantId], 0);
}
/**