Commit 4eaf4157 authored by catch's avatar catch

Issue #1901934 by damiankloip, dawehner, chx: Fixed Configuration entity query...

Issue #1901934 by damiankloip, dawehner, chx: Fixed Configuration entity query doesn't filter properly for NULL values.
parent b30e657b
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\Query\ConditionBase;
use Drupal\Core\Entity\Query\ConditionInterface;
use Drupal\Core\Entity\Query\QueryException;
/**
* Defines the condition class for the config entity query.
......@@ -110,7 +111,11 @@ protected function matchArray(array $condition, array $data, array $needs_matchi
if ($parent === '*') {
$candidates = array_keys($data);
}
elseif (isset($data[$parent])) {
else {
// Avoid a notice when calling match() later.
if (!isset($data[$parent])) {
$data[$parent] = NULL;
}
$candidates = array($parent);
}
foreach ($candidates as $key) {
......@@ -169,6 +174,10 @@ protected function match(array $condition, $value) {
return substr($value, -strlen($condition['value'])) === (string) $condition['value'];
case 'IS NOT NULL':
return TRUE;
case 'IS NULL':
return FALSE;
default:
throw new QueryException('Invalid condition operator.');
}
}
return $condition['operator'] === 'IS NULL';
......
......@@ -321,6 +321,27 @@ public function testConfigEntityQuery() {
->condition($and_condition_2)
->execute();
$this->assertResults(array('1', '2', '4', '5'));
// Test the exists and notExists conditions.
$this->queryResults = $this->factory->get('config_query_test')
->exists('id')
->execute();
$this->assertResults(array('1', '2', '3', '4', '5'));
$this->queryResults = $this->factory->get('config_query_test')
->exists('non-existent')
->execute();
$this->assertResults(array());
$this->queryResults = $this->factory->get('config_query_test')
->notExists('id')
->execute();
$this->assertResults(array());
$this->queryResults = $this->factory->get('config_query_test')
->notExists('non-existent')
->execute();
$this->assertResults(array('1', '2', '3', '4', '5'));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment