CRM-17101 - unit test searching on custom fields with <=.
authorJohan Vervloet <johanv@johanv.org>
Thu, 27 Aug 2015 19:31:44 +0000 (21:31 +0200)
committerJohan Vervloet <johanv@johanv.org>
Thu, 27 Aug 2015 19:31:44 +0000 (21:31 +0200)
----------------------------------------
* CRM-17101: civicrm_api3_basic_get does not work for SQL operators on custom fields.
  https://issues.civicrm.org/jira/browse/CRM-17101

tests/phpunit/api/v3/EventTest.php

index 10ca65627161d655c6aa5fcec9236dfb6585ede1..1149b8e596ccbc4a33ad64833c3d496633e15c22 100644 (file)
@@ -449,6 +449,37 @@ class api_v3_EventTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Test searching on custom fields with less than or equal.
+   * 
+   * See CRM-17101.
+   */
+  public function testEventGetCustomFieldLte() {
+    // create custom group with custom field on event
+    $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+
+    // Create an event, with a custom value.
+    $params = $this->_params;
+    $params['title'] = "My test event.";
+    $params['start_date'] = "2015-03-14";
+    // Just assume that an event type 1 exists.
+    $params['event_type_id'] = 1;
+    $params['custom_' . $ids['custom_field_id']] = "AAAA";
+
+    $save_result = $this->callApiSuccess($this->_entity, 'create', $params);
+
+    // Retrieve the activity, search for custom field < 'BBBB'
+    $get_result = $this->callAPISuccess($this->_entity, 'get', array(
+      'return.custom_' . $ids['custom_field_id'] => 1,
+      'custom_' . $ids['custom_field_id'] => array('<=' => 'BBBB'),
+    ));
+
+    // Expect that we find the saved event.
+    $this->assertArrayKeyExists($save_result['id'], $get_result['values']);
+
+    $this->callAPISuccess($this->_entity, 'Delete', array('id' => $save_result['id']));
+  }
+
   /**
    * Test searching on custom fields with netsted call with id param.
    *