Skip to content
Permalink
Browse files

Refs #7978 fixing regex to take in account IN operator

  • Loading branch information...
pedrofs committed Jan 28, 2016
1 parent caf93bf commit eaeb7cea9e246ae7c4bf0e0dc10f66f47c295181
Showing with 109 additions and 3 deletions.
  1. +1 −1 lib/Cake/Model/Datasource/DboSource.php
  2. +108 −2 lib/Cake/Test/Case/Model/ModelReadTest.php
@@ -2733,7 +2733,7 @@ public function conditionKeysToString($conditions, $quoteValues = true, Model $M
$keys = array_keys($value);
if ($keys === array_values($keys)) {
$count = count($value);
if ($count === 1 && !preg_match('/\s+(?:NOT|\!=)$/', $key)) {
if ($count === 1 && !preg_match('/\s+(?:NOT|IN|\!=)$/', $key)) {
$data = $this->_quoteFields($key) . ' = (';
if ($quoteValues) {
if ($Model !== null) {
@@ -86,6 +86,112 @@ public function testFetchingNonUniqueFKJoinTableRecords() {
$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
*
@@ -8079,8 +8185,8 @@ public function testfindCustom() {
/**
* test after find callback on related model
*
* @return void
*
* @return void
*/
public function testRelatedAfterFindCallback() {
$this->loadFixtures('Something', 'SomethingElse', 'JoinThing');

0 comments on commit eaeb7ce

Please sign in to comment.
You can’t perform that action at this time.