fix header
[civicrm-core.git] / tests / phpunit / api / v3 / EventTest.php
index ac5f7f2bbd6b9bd86cadb57df25af9ed7d9cb14e..d456681a178580412eefaa9c7401eb6f9f0a1b3f 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -119,6 +119,32 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2');
   }
 
+  /**
+   * Test getLocationEvents() function invokes selectWhereClause() hook
+   */
+  public function testGetEventWithPermissionHook() {
+    $address = $this->callAPISuccess('address', 'create', array(
+      'contact_id' => 'null',
+      'location_type_id' => 1,
+      'street_address' => '1234567',
+    ));
+    $params = array(
+      'address_id' => $address['id'],
+    );
+    $result = $this->callAPISuccess('loc_block', 'create', $params);
+    $params = array(
+      'id' => $this->_events[1]['id'],
+      'loc_block_id' => $result['id'],
+    );
+    $this->callAPISuccess('Event', 'create', $params);
+    $result = CRM_Event_BAO_Event::getLocationEvents();
+    $this->assertEquals(1, count($result));
+
+    $this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'selectWhereClauseHook'));
+    $result = CRM_Event_BAO_Event::getLocationEvents();
+    $this->assertEquals(0, count($result));
+  }
+
   public function testGetEventByEventTitle() {
 
     $params = array(
@@ -383,6 +409,27 @@ class api_v3_EventTest extends CiviUnitTestCase {
     $this->customGroupDelete($ids['custom_group_id']);
   }
 
+  /**
+   * Check searching on custom fields with IS NULL.
+   *
+   * https://issues.civicrm.org/jira/browse/CRM-20740
+   */
+  public function testSearchCustomFieldIsNull() {
+    // create custom group with custom field on event
+    $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
+
+    // Search for events having NULL as the value for this custom
+    // field. This should return all events created in setUp.
+    $check = $this->callAPISuccess($this->_entity, 'get', array(
+        'custom_' . $ids['custom_field_id'] => array('IS NULL' => 1),
+      ));
+
+    $this->assertGreaterThan(0, $check['count']);
+
+    $this->customFieldDelete($ids['custom_field_id']);
+    $this->customGroupDelete($ids['custom_group_id']);
+  }
+
   /**
    * Test searching on custom fields returning a contact reference.
    *
@@ -726,7 +773,7 @@ class api_v3_EventTest extends CiviUnitTestCase {
       'title' => 'le cake is a tie',
       'check_permissions' => TRUE,
     );
-    $config = &CRM_Core_Config::singleton();
+    $config = CRM_Core_Config::singleton();
     $config->userPermissionClass->permissions = array('access CiviCRM');
     $result = $this->callAPIFailure('event', 'create', $params);
     $this->assertEquals('API permission check failed for Event/create call; insufficient permission: require access CiviCRM and access CiviEvent and edit all events', $result['error_message'], 'lacking permissions should not be enough to create an event');