add tests for exising behaviour on membership_type, membership_type_id fields (so...
authoreileen <eileen@fuzion.co.nz>
Sat, 3 Aug 2013 23:56:17 +0000 (11:56 +1200)
committereileen <eileen@fuzion.co.nz>
Sat, 3 Aug 2013 23:56:17 +0000 (11:56 +1200)
tests/phpunit/api/v3/MembershipTest.php

index b0053094ae758e5c255b29e944c3edc54581d1cf..2445872b9eb96e75309a85889a4c53038d9fb982 100644 (file)
@@ -659,7 +659,92 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       'id' => $result['id'],
     ));
   }
+  /**
+   * Test civicrm_contact_memberships_create with membership_contact_id
+   * membership).
+   * Success expected.
+   */
+  function testMembershipCreateValidMembershipTypeString() {
+    $params = array(
+      'membership_contact_id' => $this->_contactID,
+      'membership_type_id' => 'General',
+      'join_date' => '2011-01-21',
+      'start_date' => '2010-01-21',
+      'end_date' => '2008-12-21',
+      'source' => 'Payment',
+      'is_override' => 1,
+      'status_id' => $this->_membershipStatusID,
+    );
+
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->assertEquals($this->_membershipTypeID, $result['values'][$result['id']]['membership_type_id']);
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
+      'id' => $result['id'],
+    ));
+  }
+
+  /**
+   * Test civicrm_contact_memberships_create with membership_contact_id
+   * membership).
+   * Success expected.
+   */
+  function testMembershipCreateInValidMembershipTypeString() {
+    $params = array(
+      'membership_contact_id' => $this->_contactID,
+      'membership_type_id' => 'invalid',
+      'join_date' => '2011-01-21',
+      'start_date' => '2010-01-21',
+      'end_date' => '2008-12-21',
+      'source' => 'Payment',
+      'is_override' => 1,
+      'status_id' => $this->_membershipStatusID,
+    );
+
+    $result = $this->callAPIFailure('membership', 'create', $params);
+  }
 
-  ///////////////// civicrm_membership_delete methods
+  /**
+   * Test civicrm_contact_memberships_create with membership_contact_id
+   * membership).
+   * Success expected.
+   */
+  function testMembershipCreateInValidMembershipTypeStringOldFormat() {
+    $params = array(
+      'membership_contact_id' => $this->_contactID,
+      'membership_type' => 'invalid',
+      'join_date' => '2011-01-21',
+      'start_date' => '2010-01-21',
+      'end_date' => '2008-12-21',
+      'source' => 'Payment',
+      'is_override' => 1,
+      'status_id' => $this->_membershipStatusID,
+    );
+
+    $result = $this->callAPIFailure('membership', 'create', $params);
+  }
+
+  /**
+   * Test civicrm_contact_memberships_create with membership_contact_id
+   * membership).
+   * Success expected.
+   */
+  function testMembershipCreateValidMembershipTypeStringOldFormat() {
+    $params = array(
+      'membership_contact_id' => $this->_contactID,
+      'membership_type' => 'General',
+      'join_date' => '2011-01-21',
+      'start_date' => '2010-01-21',
+      'end_date' => '2008-12-21',
+      'source' => 'Payment',
+      'is_override' => 1,
+      'status_id' => $this->_membershipStatusID,
+    );
+
+    $result = $this->callAPISuccess('membership', 'create', $params);
+    $this->assertEquals($this->_membershipTypeID, $result['values'][$result['id']]['membership_type_id']);
+    $result = $this->callAPISuccess('Membership', 'Delete', array(
+      'id' => $result['id'],
+    ));
+  }
 }