Browse files

Merge pull request #17 from radig/master

Using case insensitive search to "LIKE" operator in ArrayDataSource
  • Loading branch information...
2 parents 0e1a57c + 8409055 commit 3e89880305d13a8f3463762652c44d8d94cb1c48 @predominant predominant committed Sep 13, 2011
Showing with 8 additions and 1 deletion.
  1. +1 −1 models/datasources/array_source.php
  2. +7 −0 tests/cases/models/datasources/array_source.test.php
View
2 models/datasources/array_source.php
@@ -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();
View
7 tests/cases/models/datasources/array_source.test.php
@@ -328,6 +328,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)));

0 comments on commit 3e89880

Please sign in to comment.