Refs #7978 fixing regex to take in account IN operator

This commit is contained in:
Pedro Fernandes Steimbruch 2016-01-28 17:34:08 -02:00
parent caf93bf923
commit eaeb7cea9e
2 changed files with 109 additions and 3 deletions

View file

@ -2733,7 +2733,7 @@ class DboSource extends DataSource {
$keys = array_keys($value); $keys = array_keys($value);
if ($keys === array_values($keys)) { if ($keys === array_values($keys)) {
$count = count($value); $count = count($value);
if ($count === 1 && !preg_match('/\s+(?:NOT|\!=)$/', $key)) { if ($count === 1 && !preg_match('/\s+(?:NOT|IN|\!=)$/', $key)) {
$data = $this->_quoteFields($key) . ' = ('; $data = $this->_quoteFields($key) . ' = (';
if ($quoteValues) { if ($quoteValues) {
if ($Model !== null) { if ($Model !== null) {

View file

@ -86,6 +86,112 @@ class ModelReadTest extends BaseModelTest {
$this->assertTrue(in_array(false, $doomed)); $this->assertTrue(in_array(false, $doomed));
} }
/**
* Test IN operator
*
* @return void
*/
public function testInOperator() {
$this->loadFixtures('Product');
$Product = new Product();
$expected = array(
array(
'Product' => array(
'id' => 1,
'name' => "Park's Great Hits",
'type' => 'Music',
'price' => 19
)
)
);
$result = $Product->find('all', array('conditions' => array('Product.id IN' => array(1))));
$this->assertEquals($expected, $result);
$expected = array(
array(
'Product' => array(
'id' => 2,
'name' => "Silly Puddy",
'type' => 'Toy',
'price' => 3
)
),
array(
'Product' => array(
'id' => 3,
'name' => "Playstation",
'type' => 'Toy',
'price' => 89
)
),
array(
'Product' => array(
'id' => 4,
'name' => "Men's T-Shirt",
'type' => 'Clothing',
'price' => 32
)
),
array(
'Product' => array(
'id' => 5,
'name' => "Blouse",
'type' => 'Clothing',
'price' => 34
)
),
array(
'Product' => array(
'id' => 6,
'name' => "Electronica 2002",
'type' => 'Music',
'price' => 4
)
),
array(
'Product' => array(
'id' => 7,
'name' => "Country Tunes",
'type' => 'Music',
'price' => 21
)
),
array(
'Product' => array(
'id' => 8,
'name' => "Watermelon",
'type' => 'Food',
'price' => 9
)
)
);
$result = $Product->find('all', array('conditions' => array('Product.id NOT IN' => array(1))));
$this->assertEquals($expected, $result);
$expected = array(
array(
'Product' => array(
'id' => 1,
'name' => "Park's Great Hits",
'type' => 'Music',
'price' => 19
)
),
array(
'Product' => array(
'id' => 2,
'name' => "Silly Puddy",
'type' => 'Toy',
'price' => 3
)
),
);
$result = $Product->find('all', array('conditions' => array('Product.id IN' => array(1,2))));
$this->assertEquals($expected, $result);
}
/** /**
* testGroupBy method * testGroupBy method
* *