Issue #2823910 by daffie, pwolanin, smustgrave, dawehner, larowlan: DBTNG/EQ condition works inconsistently with arrays
parent
6cdc56148a
commit
330d393ec2
|
@ -105,6 +105,10 @@ class Condition implements ConditionInterface, \Countable {
|
|||
if (empty($value) && is_array($value)) {
|
||||
throw new InvalidQueryException(sprintf("Query condition '%s %s ()' cannot be empty.", $field, $operator));
|
||||
}
|
||||
if (is_array($value) && in_array($operator, ['=', '<', '>', '<=', '>=', 'IS NULL', 'IS NOT NULL'], TRUE)) {
|
||||
$value = implode(', ', $value);
|
||||
throw new InvalidQueryException(sprintf("Query condition '%s %s %s' must have an array compatible operator.", $field, $operator, $value));
|
||||
}
|
||||
|
||||
$this->conditions[] = [
|
||||
'field' => $field,
|
||||
|
|
|
@ -70,7 +70,7 @@ class UserStorage extends SqlContentEntityStorage implements UserStorageInterfac
|
|||
public function deleteRoleReferences(array $rids) {
|
||||
// Remove the role from all users.
|
||||
$this->database->delete('user__roles')
|
||||
->condition('roles_target_id', $rids)
|
||||
->condition('roles_target_id', $rids, 'IN')
|
||||
->execute();
|
||||
|
||||
$this->resetCache();
|
||||
|
|
|
@ -591,4 +591,40 @@ class SelectTest extends DatabaseTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testNonArrayOperatorWithArrayValueCondition().
|
||||
*
|
||||
* @return array[]
|
||||
* Array of non array compatible operators and its value in the expected
|
||||
* exception message.
|
||||
*/
|
||||
public function providerNonArrayOperatorWithArrayValueCondition() {
|
||||
return [
|
||||
'=' => ['=', '='],
|
||||
'>' => ['>', '>'],
|
||||
'<' => ['<', '<'],
|
||||
'>=' => ['>=', '>='],
|
||||
'<=' => ['<=', '<='],
|
||||
'IS NULL' => ['IS NULL', 'IS NULL'],
|
||||
'IS NOT NULL' => ['IS NOT NULL', 'IS NOT NULL'],
|
||||
'Empty string' => ['', '='],
|
||||
'Not set' => [NULL, '='],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests thrown exception for non array operator conditions with array value.
|
||||
*
|
||||
* @dataProvider providerNonArrayOperatorWithArrayValueCondition
|
||||
*/
|
||||
public function testNonArrayOperatorWithArrayValueCondition($operator, $operator_in_exception_message) {
|
||||
$this->expectException(InvalidQueryException::class);
|
||||
$this->expectExceptionMessage("Query condition 'age " . $operator_in_exception_message . " 26, 27' must have an array compatible operator.");
|
||||
|
||||
$this->connection->select('test', 't')
|
||||
->fields('t')
|
||||
->condition('age', [26, 27], $operator)
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class ConditionTest extends UnitTestCase {
|
|||
$query_placeholder = $query_placeholder->reveal();
|
||||
|
||||
$condition = $connection->condition('AND');
|
||||
$condition->condition($field_name, ['value']);
|
||||
$condition->condition($field_name, 'value');
|
||||
$condition->compile($connection, $query_placeholder);
|
||||
|
||||
$this->assertEquals($expected, $condition->__toString());
|
||||
|
|
Loading…
Reference in New Issue