Using case insensitive search to "LIKE" operator in ArrayDataSource #17

Merged
merged 2 commits into from Sep 13, 2011
Jump to file or symbol
Failed to load files and symbols.
+8 −1
Split
@@ -248,7 +248,7 @@ public function conditionsFilter(&$model, $record, $conditions, $or = false) {
break;
case 'LIKE':
$value = preg_replace(array('#(^|[^\\\\])_#', '#(^|[^\\\\])%#'), array('$1.', '$1.*'), $value);
- $return = (isset($record[$field]) && preg_match('#^' . $value . '$#', $record[$field]));
+ $return = (isset($record[$field]) && preg_match('#^' . $value . '$#i', $record[$field]));
break;
case 'IN':
$items = array();
@@ -308,6 +308,13 @@ function testFindConditions() {
$result = $this->Model->find('all', array('conditions' => array('ArrayModel.name LIKE _r%')));
$this->assertEqual($result, $expected);
+
+ $result = $this->Model->find('all', array('conditions' => array('ArrayModel.name LIKE %b%')));
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Model->find('all', array('conditions' => array('ArrayModel.name LIKE %a%')));
+ $expected = array(array('ArrayModel' => array('id' => 1, 'name' => 'USA', 'relate_id' => 1)), array('ArrayModel' => array('id' => 2, 'name' => 'Brazil', 'relate_id' => 1)), array('ArrayModel' => array('id' => 3, 'name' => 'Germany', 'relate_id' => 2)));
+ $this->assertEqual($result, $expected);
$result = $this->Model->find('all', array('conditions' => array('ArrayModel.name' => array('USA', 'Germany'))));
$expected = array(array('ArrayModel' => array('id' => 1, 'name' => 'USA', 'relate_id' => 1)), array('ArrayModel' => array('id' => 3, 'name' => 'Germany', 'relate_id' => 2)));