A unit test for searching memberships on custom field values.
authorJohan Vervloet <johanv@johanv.org>
Tue, 10 Mar 2015 14:39:15 +0000 (15:39 +0100)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 12 Aug 2015 23:39:32 +0000 (11:39 +1200)
tests/phpunit/api/v3/MembershipTest.php

index aa5d0937a20e895b0f81722d0c9924c1fa245864..e31e2dc753fd490702e8802a33a23adc9036f21d 100644 (file)
@@ -714,6 +714,40 @@ class api_v3_MembershipTest extends CiviUnitTestCase {
     $this->assertEquals("custom string", $check['values'][$result['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
   }
 
+  /**
+   * Search on custom field value.
+   */
+  public function testSearchWithCustomDataCRM16036() {
+    // Create a custom field on membership
+    $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+
+    // Create a new membership, but don't assign anything to the custom field.
+    $params = $this->_params;
+    $result = $this->callAPIAndDocument(
+      $this->_entity,
+      'create',
+      $params,
+      __FUNCTION__,
+      __FILE__,
+      NULL,
+      'SearchWithCustomData');
+
+    // search memberships with CRM-16036 as custom field value.
+    // Since we did not touch the custom field of any membership,
+    // this should not return any results.
+    $check = $this->callAPISuccess($this->_entity, 'get', array(
+      'custom_' . $ids['custom_field_id'] => "CRM-16036",
+    ));
+
+    // Cleanup.
+    $this->callAPISuccess($this->_entity, 'delete', array(
+      'id' => $result['id'],
+    ));
+
+    // Assert.
+    $this->assertEquals(0, $check['count']);
+  }
+
   /**
    * Test civicrm_contact_memberships_create with membership id (edit
    * membership).