diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php index b29b179..8091a04 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -166,7 +166,7 @@ protected function loadRecords() { $filter = function ($name) use ($value, $prefix_length) { $id = substr($name, $prefix_length); return $id !== $value; - }; + }; break; case 'STARTS_WITH': $filter = function ($name) use ($value, $prefix_length) { diff --git a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php index 7641cf2..b049880 100644 --- a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php +++ b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php @@ -343,6 +343,62 @@ public function testConfigEntityQuery() { } /** + * Tests ID conditions. + */ + public function testStringIdConditions() { + // We need an entity with a non-numeric ID. + $entity = entity_create('config_query_test', array( + 'label' => $this->randomMachineName(), + 'id' => 'foo.bar', + )); + $this->entities[] = $entity; + $entity->enforceIsNew(); + $entity->save(); + + // Test 'STARTS_WITH' condition. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'foo.bar', 'STARTS_WITH') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'f', 'STARTS_WITH') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'miss', 'STARTS_WITH') + ->execute(); + $this->assertResults(array()); + + // Test 'CONTAINS' condition. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'foo.bar', 'CONTAINS') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'oo.ba', 'CONTAINS') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'miss', 'CONTAINS') + ->execute(); + $this->assertResults(array()); + + // Test 'ENDS_WITH' condition. + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'foo.bar', 'ENDS_WITH') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'r', 'ENDS_WITH') + ->execute(); + $this->assertResults(array('foo.bar')); + $this->queryResults = $this->factory->get('config_query_test') + ->condition('id', 'miss', 'ENDS_WITH') + ->execute(); + $this->assertResults(array()); + } + + /** * Tests count query. */ public function testCount() {