From 35fbf8a2a7b9e808b3f2988f514512d27b4d8ff5 Mon Sep 17 00:00:00 2001 From: Michael McAndrew Date: Tue, 11 Oct 2016 13:39:00 +0100 Subject: [PATCH] CRM 19474 - additional test (#9208) * adding test for CRM-19474 * removing unecessary if clause * removing empty line after function description * test that only two contacts are returned --- CRM/Contact/BAO/Query.php | 4 +-- tests/phpunit/api/v3/ContactTest.php | 39 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 9d0b97d440..fc7f4862e2 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2867,9 +2867,7 @@ class CRM_Contact_BAO_Query { } elseif (is_array($value)) { foreach ($value as $k => $v) { - if (!empty($k)) { - $clause[$k] = "($alias $op '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($v, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')"; - } + $clause[$k] = "($alias $op '%" . CRM_Core_DAO::VALUE_SEPARATOR . CRM_Utils_Type::escape($v, 'String') . CRM_Core_DAO::VALUE_SEPARATOR . "%')"; } } else { diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 1d677c1490..2d3493c5e8 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -199,6 +199,45 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type']); } + /** + * Verify that we can retreive contacts of different sub types + */ + public function testGetMultipleContactSubTypes() { + + // This test presumes that there are no parents or students in the dataset + + // create a student + $student = $this->callAPISuccess('contact', 'create', array( + 'email' => 'student@example.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + )); + + // create a parent + $parent = $this->callAPISuccess('contact', 'create', array( + 'email' => 'parent@example.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Parent', + )); + + // create a parent + $contact = $this->callAPISuccess('contact', 'create', array( + 'email' => 'parent@example.com', + 'contact_type' => 'Individual', + )); + + // get all students and parents + $getParams = array('contact_sub_type' => array('IN' => array('Parent', 'Student'))); + $result = civicrm_api3('contact', 'get', $getParams); + + // check that we retrieved the student and the parent + $this->assertArrayHasKey($student['id'], $result['values']); + $this->assertArrayHasKey($parent['id'], $result['values']); + $this->assertEquals(2, $result['count']); + + } + + /** * Verify that attempt to create contact with empty params fails. */ -- 2.25.1