Skip to content

Commit

Permalink
Merge pull request #11265 from eileenmcnaughton/test
Browse files Browse the repository at this point in the history
[NFC] Minor refactor of test to allow re-use
  • Loading branch information
totten authored Nov 10, 2017
2 parents 8c7a26d + 7c902b1 commit 182727a
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions tests/phpunit/CRM/Event/Form/ParticipantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ public function setUp() {
* @throws \Exception
*/
public function testSubmit() {
$event = $this->eventCreate();
$contactID = $this->individualCreate();
$form = $this->getFormObject('CRM_Event_Form_Participant');
$form->_single = TRUE;
$form->_contactId = $contactID;
$form->setCustomDataTypes();
$form = $this->commonPrepare();
$form->submit(array(
'register_date' => 'now',
'register_date_time' => '00:00:00',
'status_id' => 1,
'role_id' => 1,
'event_id' => $event['id'],
'event_id' => $form->_eventId,
));
$participants = $this->callAPISuccess('Participant', 'get', array());
$this->assertEquals(1, $participants['count']);
Expand All @@ -42,14 +37,7 @@ public function testSubmit() {
* @throws \Exception
*/
public function testSubmitWithPayment() {
$event = $this->eventCreate(array('is_monetary' => 1, 'financial_type_id' => 1));
$contactID = $this->individualCreate();
$form = $this->getFormObject('CRM_Event_Form_Participant');
$form->_single = TRUE;
$form->_contactId = $contactID;
$form->setCustomDataTypes();
$form->_bltID = 5;
$form->_eventId = $event['id'];
$form = $this->commonPrepare(array('is_monetary' => 1, 'financial_type_id' => 1));
$paymentProcessorID = $this->processorCreate(array('is_test' => 0));
$form->_mode = 'Live';
$form->_values['fee'] = array();
Expand All @@ -63,7 +51,7 @@ public function testSubmitWithPayment() {
'register_date_time' => '00:00:00',
'status_id' => 1,
'role_id' => 1,
'event_id' => $event['id'],
'event_id' => $form->_eventId,
'credit_card_number' => 4444333322221111,
'cvv2' => 123,
'credit_card_exp_date' => array(
Expand Down Expand Up @@ -134,4 +122,28 @@ public function testParticipantOfflineReceipt() {
);
}

/**
* Shared preparation.
*
* @param array $eventParams
*
* @return CRM_Event_Form_Participant
*/
protected function commonPrepare($eventParams = array()) {
$event = $this->eventCreate($eventParams);
$contactID = $this->individualCreate();
$form = $this->getFormObject('CRM_Event_Form_Participant');
$form->_single = TRUE;
$form->_contactId = $contactID;
$form->setCustomDataTypes();
$form->_eventId = $event['id'];
if (!empty($eventParams['is_monetary'])) {
$form->_mode = 'Live';
$form->_bltID = 5;
$form->_values['fee'] = array();
$form->_isPaidEvent = TRUE;
}
return $form;
}

}

0 comments on commit 182727a

Please sign in to comment.