--CRM-16188, added test to check transitioncomponent function
authorPradeep Nayak <pradpnayak@gmail.com>
Fri, 12 Feb 2016 04:34:06 +0000 (10:04 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 16 Feb 2016 17:04:57 +0000 (22:34 +0530)
tests/phpunit/api/v3/OrderTest.php

index 8934970f0d9e71df67264ed751d0a8057b2035a0..6853a0fa2990cbe1b4ed2f7b4f0d014985689040 100644 (file)
@@ -481,4 +481,56 @@ class api_v3_OrderTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Test cancel order api
+   */
+  public function testCancelWithParticipant() {
+    $this->_eventId = Event::create($this->_individualId);
+    $eventParams = array(
+      'id' => $this->_eventId,
+      'financial_type_id' => 4,
+      'is_monetary' => 1,
+    );
+    $this->callAPISuccess('event', 'create', $eventParams);
+    $participantParams = array(
+      'financial_type_id' => 4,
+      'event_id' => $this->_eventId,
+      'role_id' => 1,
+      'status_id' => 1,
+      'fee_currency' => 'USD',
+      'contact_id' => $this->_individualId,
+    );
+    $participant = $this->callAPISuccess('Participant', 'create', $participantParams);
+    $extraParams = array(
+      'contribution_mode' => 'participant',
+      'participant_id' => $participant['id'],
+    );
+    $contribution = $this->addOrder(TRUE, 100, $extraParams);
+    $paymentParticipant = array(
+      'participant_id' => $participant['id'],
+      'contribution_id' => $contribution['id'],
+    );
+    $this->callAPISuccess('ParticipantPayment', 'create', $paymentParticipant);
+    $params = array(
+      'contribution_id' => $contribution['id'],
+    );
+    $this->callAPISuccess('order', 'cancel', $params);
+    $order = $this->callAPISuccess('Order', 'get', $params);
+    $expectedResult = array(
+      $contribution['id'] => array(
+        'total_amount' => 100,
+        'contribution_id' => $contribution['id'],
+        'contribution_status' => 'Cancelled',
+        'net_amount' => 100,
+      ),
+    );
+    $this->checkPaymentResult($order, $expectedResult); 
+    $participantPayment = $this->callAPISuccess('ParticipantPayment', 'getsingle', $params);
+    $participant = $this->callAPISuccess('participant', 'get', array('id' => $participantPayment['participant_id']));
+    $this->assertEquals($participant['values'][$participant['id']]['participant_status'], 'Cancelled');
+    $this->callAPISuccess('Contribution', 'Delete', array(
+      'id' => $contribution['id'],
+    ));
+  }
+
 }