// Replace spaces with wildcards for a LIKE operation
// UNLESS string contains a comma (this exception is a tiny bit questionable)
// Also need to check if there is space in between sort name.
- elseif ($op == 'LIKE' && strpos($value, ',') === FALSE && strpos($value, ' ') === TRUE) {
+ elseif ($op == 'LIKE' && strpos($value, ',') === FALSE && strpos($value, ' ') !== FALSE) {
$value = str_replace(' ', '%', $value);
}
$value = CRM_Core_DAO::escapeString(trim($value));
$this->assertEquals('Smith', $rows[0]['last_name']);
}
+ /**
+ * Tests if a space is replaced by the wildcard on sort_name when operation is 'LIKE' and there is no comma
+ *
+ * CRM-22060 fix if condition
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testReplaceSpaceByWildcardCondition() {
+ //Check for wildcard
+ $params = [
+ 0 => [
+ 0 => 'sort_name',
+ 1 => 'LIKE',
+ 2 => 'John Doe',
+ 3 => 0,
+ 4 => 1,
+ ],
+ ];
+ $query = new CRM_Contact_BAO_Query($params);
+ list($select, $from, $where) = $query->query();
+ $this->assertStringContainsString("contact_a.sort_name LIKE '%John%Doe%'", $where);
+
+ //Check for NO wildcard due to comma
+ $params[0][2] = 'Doe, John';
+ $query = new CRM_Contact_BAO_Query($params);
+ list($select, $from, $where) = $query->query();
+ $this->assertStringContainsString("contact_a.sort_name LIKE '%Doe, John%'", $where);
+ }
+
}
$this->individualCreate($contactParams_2);
$result = $this->callAPISuccess('contact', 'get', ['sort_name' => 'Blackwell F']);
- $this->assertEquals(1, $result['count']);
+ // Since #22060 we expect both results as space is being replaced with wildcard
+ $this->assertEquals(2, $result['count']);
}
/**