CRM-14720 add extra test for '=' queries
authoreileenmcnaughton <eileen@fuzion.co.nz>
Mon, 12 Oct 2015 07:30:33 +0000 (07:30 +0000)
committereileenmcnaughton <eileen@fuzion.co.nz>
Mon, 12 Oct 2015 07:31:05 +0000 (07:31 +0000)
tests/phpunit/CRM/Contact/BAO/QueryTest.php

index 4daff9d8131e51d961f5e3fe30ea0673dfcf1926..fa989ae0ad695737f908567e588a7b931f05a78e 100644 (file)
@@ -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);
+
+  }
+
 }