diff --git a/core/lib/Drupal/Core/Database/InvalidQueryException.php b/core/lib/Drupal/Core/Database/InvalidQueryException.php new file mode 100644 index 00000000000..ffd5bab23c4 --- /dev/null +++ b/core/lib/Drupal/Core/Database/InvalidQueryException.php @@ -0,0 +1,16 @@ +conditions[] = array( 'field' => $field, 'value' => $value, diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php index d9da2d6b883..7b90e07c95b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/SelectTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\system\Tests\Database; +use Drupal\Core\Database\InvalidQueryException; /** * Tests the SELECT builder. @@ -481,4 +482,33 @@ class SelectTest extends DatabaseTestBase { $this->fail('No Exception thrown.'); } + /** + * Tests thrown exception for IN query conditions with an empty array. + */ + function testEmptyInCondition() { + try { + db_select('test', 't') + ->fields('t') + ->condition('age', array(), 'IN') + ->execute(); + + $this->fail('Expected exception not thrown'); + } + catch (InvalidQueryException $e) { + $this->assertEqual("Query condition 'age IN ()' cannot be empty.", $e->getMessage()); + } + + try { + db_select('test', 't') + ->fields('t') + ->condition('age', array(), 'NOT IN') + ->execute(); + + $this->fail('Expected exception not thrown'); + } + catch (InvalidQueryException $e) { + $this->assertEqual("Query condition 'age NOT IN ()' cannot be empty.", $e->getMessage()); + } + } + }