diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Condition.php b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php index d231f0b..01c36c1 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Condition.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Condition.php @@ -176,6 +176,9 @@ protected function match(array $condition, $value) { return TRUE; case 'IS NULL': return FALSE; + case 'MATCH': + $regex = '@^' . str_replace('\\*', '(.*)', preg_quote($value, '@')) . '$@i'; + return preg_match($regex, $condition['value']); default: throw new QueryException('Invalid condition operator.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php index bfafc9e..ab54924 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/ConfigEntityQueryTest.php @@ -118,6 +118,32 @@ protected function setUp() { $this->entities[] = $entity; $entity->enforceIsNew(); $entity->save(); + + $entity = entity_create('config_query_test', array( + 'label' => 'foo_bar_*', + 'id' => '6', + 'number' => 39, + 'array' => array( + 'foo/*/bar', + 'foo' + ), + )); + $this->entities[] = $entity; + $entity->enforceIsNew(); + $entity->save(); + + $entity = entity_create('config_query_test', array( + 'label' => 'foo_*_bar', + 'id' => '7', + 'number' => 40, + 'array' => array( + 'foo/bar/*', + 'bar' + ), + )); + $this->entities[] = $entity; + $entity->enforceIsNew(); + $entity->save(); } /** @@ -127,11 +153,11 @@ public function testConfigEntityQuery() { // Run a test without any condition. $this->queryResults = $this->factory->get('config_query_test') ->execute(); - $this->assertResults(array('1', '2', '3', '4', '5')); + $this->assertResults(array('1', '2', '3', '4', '5', '6', '7')); // No conditions, OR. $this->queryResults = $this->factory->get('config_query_test', 'OR') ->execute(); - $this->assertResults(array('1', '2', '3', '4', '5')); + $this->assertResults(array('1', '2', '3', '4', '5', '6', '7')); // Filter by ID with equality. $this->queryResults = $this->factory->get('config_query_test') @@ -173,13 +199,13 @@ public function testConfigEntityQuery() { $this->queryResults = $this->factory->get('config_query_test') ->condition('id', '3', '>') ->execute(); - $this->assertResults(array('4', '5')); + $this->assertResults(array('4', '5', '6', '7')); // Filter by ID with the >= operator. $this->queryResults = $this->factory->get('config_query_test') ->condition('id', '3', '>=') ->execute(); - $this->assertResults(array('3', '4', '5')); + $this->assertResults(array('3', '4', '5', '6', '7')); // Filter by ID with the < operator. $this->queryResults = $this->factory->get('config_query_test') @@ -247,7 +273,7 @@ public function testConfigEntityQuery() { $this->queryResults = $this->factory->get('config_query_test') ->condition('id', array('1', '2'), 'NOT IN') ->execute(); - $this->assertResults(array('3', '4', '5')); + $this->assertResults(array('3', '4', '5', '6', '7')); // Filter with an OR condition group on different fields. $this->queryResults = $this->factory->get('config_query_test', 'OR') @@ -326,7 +352,7 @@ public function testConfigEntityQuery() { $this->queryResults = $this->factory->get('config_query_test') ->exists('id') ->execute(); - $this->assertResults(array('1', '2', '3', '4', '5')); + $this->assertResults(array('1', '2', '3', '4', '5', '6', '7')); $this->queryResults = $this->factory->get('config_query_test') ->exists('non-existent') @@ -341,7 +367,7 @@ public function testConfigEntityQuery() { $this->queryResults = $this->factory->get('config_query_test') ->notExists('non-existent') ->execute(); - $this->assertResults(array('1', '2', '3', '4', '5')); + $this->assertResults(array('1', '2', '3', '4', '5', '6', '7')); } /** @@ -378,38 +404,38 @@ protected function testSortRange() { $this->queryResults = $this->factory->get('config_query_test') ->sort('number', 'DESC') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('3', '5', '2', '1', '4')); + $this->assertIdentical(array_values($this->queryResults), array('3', '5', '2', '7', '6', '1', '4')); $this->queryResults = $this->factory->get('config_query_test') ->sort('number', 'ASC') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('4', '1', '2', '5', '3')); + $this->assertIdentical(array_values($this->queryResults), array('4', '1', '6', '7', '2', '5', '3')); // Apply some filters and sort. $this->queryResults = $this->factory->get('config_query_test') ->condition('id', '3', '>') ->sort('number', 'DESC') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('5', '4')); + $this->assertIdentical(array_values($this->queryResults), array('5', '7', '6', '4')); $this->queryResults = $this->factory->get('config_query_test') ->condition('id', '3', '>') ->sort('number', 'ASC') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('4', '5')); + $this->assertIdentical(array_values($this->queryResults), array('4', '6', '7', '5')); // Apply a pager and sort. $this->queryResults = $this->factory->get('config_query_test') ->sort('number', 'DESC') ->range('2', '2') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('2', '1')); + $this->assertIdentical(array_values($this->queryResults), array('2', '7')); $this->queryResults = $this->factory->get('config_query_test') ->sort('number', 'ASC') ->range('2', '2') ->execute(); - $this->assertIdentical(array_values($this->queryResults), array('2', '5')); + $this->assertIdentical(array_values($this->queryResults), array('6', '7')); // Add a range to a query without a start parameter. $this->queryResults = $this->factory->get('config_query_test') @@ -456,6 +482,29 @@ protected function testDotted() { } /** + * Tests wildcard path matching. + */ + protected function testWildcards() { + // Match with wildcard. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('label', 'foo_some_bar', 'MATCH') + ->execute(); + $this->assertResults(array('7')); + + // Match with wildcard. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('label', 'foo_bar_bar', 'MATCH') + ->execute(); + $this->assertResults(array('6', '7')); + + // Match with wildcard. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('label', 'foo_bar_baz', 'MATCH') + ->execute(); + $this->assertResults(array('6')); + } + + /** * Asserts the results as expected regardless of order. * * @param array $expected