Build query using CRM_Utils_SQL_Select.
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipTest.php
index 1d2c007fb14c83aaf5ae56ed5c994503503cd4a8..aa5d0937a20e895b0f81722d0c9924c1fa245864 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -338,9 +338,8 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
    * Memberships expected.
    */
   public function testGetOnlyActive() {
-    $description = "Demonstrates use of 'filter' active_only' param";
+    $description = "Demonstrates use of 'filter' active_only' param.";
     $this->_membershipID = $this->contactMembershipCreate($this->_params);
-    $subfile = 'filterIsCurrent';
     $params = array(
       'contact_id' => $this->_contactID,
       'active_only' => 1,
@@ -356,7 +355,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
       ),
     );
 
-    $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
+    $membership = $this->callAPIAndDocument('membership', 'get', $params, __FUNCTION__, __FILE__, $description, 'FilterIsCurrent');
     $this->assertEquals($membership['values'][$this->_membershipID]['status_id'], $this->_membershipStatusID);
     $this->assertEquals($membership['values'][$this->_membershipID]['contact_id'], $this->_contactID);
 
@@ -554,6 +553,38 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess('membership', 'get', $params);
     $this->assertEquals(0, $result['count']);
 
+    // Set up params for enable/disable checks
+    $relationship1 = $this->callAPISuccess('relationship', 'get', array('contact_id_a' => $memberContactId[1]));
+    $params = array(
+      'contact_id' => $memberContactId[1],
+      'membership_type_id' => $membershipTypeId,
+    );
+
+    // Deactivate relationship using create and assert membership is not inherited
+    $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 0));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(0, $result['count']);
+
+    // Re-enable relationship using create and assert membership is inherited
+    $this->callAPISuccess('relationship', 'create', array('id' => $relationship1['id'], 'is_active' => 1));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(1, $result['count']);
+
+    // Deactivate relationship using setvalue and assert membership is not inherited
+    $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 0));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(0, $result['count']);
+
+    // Re-enable relationship using setvalue and assert membership is inherited
+    $this->callAPISuccess('relationship', 'setvalue', array('id' => $relationship1['id'], 'field' => 'is_active', 'value' => 1));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(1, $result['count']);
+
+    // Delete relationship and assert membership is not inherited
+    $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id']));
+    $result = $this->callAPISuccess('membership', 'get', $params);
+    $this->assertEquals(0, $result['count']);
+
     // Tear down - reverse of creation to be safe
     $this->contactDelete($memberContactId[2]);
     $this->contactDelete($memberContactId[1]);
@@ -586,7 +617,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * If is_overide is passed in status must also be passed in
+   * If is_overide is passed in status must also be passed in.
    */
   public function testCreateOverrideNoStatus() {
     $params = $this->_params;
@@ -675,7 +706,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
 
-    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'CreateWithCustomData');
     $check = $this->callAPISuccess($this->_entity, 'get', array(
       'id' => $result['id'],
       'contact_id' => $this->_contactID,
@@ -804,14 +835,14 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Change custom field using update
+   * Change custom field using update.
    */
   public function testUpdateWithCustom() {
     $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
 
     $params = $this->_params;
     $params['custom_' . $ids['custom_field_id']] = "custom string";
-    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+    $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, NULL, 'UpdateCustomData');
     $result = $this->callAPISuccess($this->_entity, 'create', array(
       'id' => $result['id'],
       'custom_' . $ids['custom_field_id'] => "new custom",
@@ -864,7 +895,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test civicrm_contact_memberships_create Invalid membership data
+   * Test civicrm_contact_memberships_create Invalid membership data.
    * Error expected.
    */
   public function testMembershipCreateInvalidMemData() {
@@ -961,7 +992,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that if membership join date is not set it defaults to today
+   * Test that if membership join date is not set it defaults to today.
    */
   public function testEmptyJoinDate() {
     unset($this->_params['join_date'], $this->_params['is_override']);
@@ -973,7 +1004,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that if membership start date is not set it defaults to correct end date
+   * Test that if membership start date is not set it defaults to correct end date.
    *  - fixed
    */
   public function testEmptyStartDateFixed() {
@@ -1273,7 +1304,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that if membership end date is not set it defaults to correct end date
+   * Test that if membership end date is not set it defaults to correct end date.
    *  - rolling
    */
   public function testEmptyEndDateFixed() {
@@ -1287,7 +1318,7 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that if membership end date is not set it defaults to correct end date
+   * Test that if membership end date is not set it defaults to correct end date.
    *  - rolling
    */
   public function testEmptyEndDateRolling() {