From 9a1491bb3a407eeba82ce081d5d86fe4324791bf Mon Sep 17 00:00:00 2001 From: eileenmcnaughton Date: Mon, 12 Oct 2015 07:30:33 +0000 Subject: [PATCH] CRM-14720 add extra test for '=' queries --- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 4daff9d813..fa989ae0ad 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -248,4 +248,32 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { CRM_Contact_BAO_GroupContactCache::load($group, TRUE); } + /** + * Test smart groups with non-numeric don't fail on equal queries. + * + * CRM-14720 + */ + public function testNonNumericEqualsPostal() { + $this->individualCreate(array('api.address.create' => array('postal_code' => 5, 'location_type_id' => 'Main'))); + $this->individualCreate(array('api.address.create' => array('postal_code' => 'EH10 4RB-889', 'location_type_id' => 'Main'))); + $this->individualCreate(array('api.address.create' => array('postal_code' => '4', 'location_type_id' => 'Main'))); + $this->individualCreate(array('api.address.create' => array('postal_code' => '6', 'location_type_id' => 'Main'))); + + $params = array(array('postal_code', '=', 'EH10 4RB-889', 0, 0)); + CRM_Contact_BAO_Query::convertFormValues($params); + + $query = new CRM_Contact_BAO_Query( + $params, array('contact_id'), + NULL, TRUE, FALSE, 1, + TRUE, + TRUE, FALSE + ); + + $sql = $query->query(FALSE); + $this->assertEquals("WHERE ( civicrm_address.postal_code = 'eh10 4rb-889' ) AND (contact_a.is_deleted = 0)", $sql[2]); + $result = CRM_Core_DAO::executeQuery(implode(' ', $sql)); + $this->assertEquals(1, $result->N); + + } + } -- 2.25.1