CRM-16036 - extra unit test.
authorJohan Vervloet <johanv@johanv.org>
Mon, 3 Aug 2015 12:02:46 +0000 (14:02 +0200)
committereileenmcnaugton <eileen@fuzion.co.nz>
Wed, 12 Aug 2015 23:39:39 +0000 (11:39 +1200)
----------------------------------------
* CRM-16036: API: searching on custom fields does not work
  https://issues.civicrm.org/jira/browse/CRM-16036

tests/phpunit/api/v3/EventTest.php

index 0471c1062901c0989f43fa6e8755bf93eb12ff3d..598767d0edaf222b40239d108664bca2cadddbd1 100644 (file)
@@ -449,6 +449,48 @@ class api_v3_EventTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Test searching on custom fields with netsted call with id param.
+   * 
+   * Search for an event on a custom field, and perform a chained call
+   * to retrieve it's (non-existing) loc block, using $value-substitution.
+   * This test just checks whether the event is found, because something
+   * happened in CiviCRM 4.6.5 that broke my fix for CRM-16036, causing 
+   * CiviCRM to return 0 results.
+   * Of course, CRM-16168 should also be fixed for this test to pass.
+   */
+  public function testEventSearchCustomFieldWithChainedCall() {
+    // Create a custom group, and add a custom contact reference field.
+    $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+    $custom_field_id = $ids['custom_field_id'];
+    
+    // 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_' . $custom_field_id] = "12345";
+
+    $this->callAPISuccess($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
+
+    // Retrieve the activity, and chain loc block using $value.
+    $result = $this->callAPIAndDocument($this->_entity, 'get', array(
+      'custom_' . $custom_field_id => "12345",
+      'api.LocBlock.get' => array("id" => '$value.loc_block_id'),
+    ), __FUNCTION__, __FILE__);
+
+    $this->assertEquals(1, $result['count']);
+
+    $this->customFieldDelete($ids['custom_field_id']);
+    $this->customGroupDelete($ids['custom_group_id']);
+    $this->callAPISuccess('event', 'delete', array(
+      'id' => $result['id'],
+      'skip_undelete' => TRUE,
+    ));
+  }
+  
+  
   /**
    * Test that an event with a price set can be created.
    */