diff -u b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php --- b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php +++ b/core/lib/Drupal/Core/Config/Entity/QueryFactory.php @@ -16,7 +16,7 @@ $this->directory = $directory; } - function get($entity_type, $conjunction) { + function get($entity_type, $conjunction = 'AND') { return new Query($entity_type, $conjunction, $this->directory); } } only in patch2: unchanged: --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityQueryTest.php @@ -0,0 +1,166 @@ + 'Config Entity Query', + 'description' => 'Tests Config Entity Query functionality.', + 'group' => 'Configuration', + ); + } + + protected function setUp() { + parent::setUp(); + + $entity = entity_create('config_test', array( + 'label' => $this->randomName(), + 'id' => 1, + ) + ); + $this->entities[] = $entity; + $entity->save(); + + $entity = entity_create('config_test', array( + 'label' => $this->randomName(), + 'id' => 2, + ) + ); + $this->entities[] = $entity; + $entity->save(); + + $entity = entity_create('config_test', array( + 'label' => 'test_prefix_' . $this->randomName(), + 'id' => 3, + ) + ); + $this->entities[] = $entity; + $entity->save(); + + $entity = entity_create('config_test', array( + 'label' => $this->randomName() . '_test_suffix', + 'id' => 4, + ) + ); + $this->entities[] = $entity; + $entity->save(); + + $entity = entity_create('config_test', array( + 'label' => $this->randomName() . '_test_contains_' . $this->randomName(), + 'id' => 5, + ) + ); + $this->entities[] = $entity; + $entity->save(); + + // @todo This should be from the container. + $this->factory = new QueryFactory(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); + } + + + /** + * Test basic functionality. + */ + public function testConfigEntityQuery() { + // Run a test without any condition. + +// $this->queryResults = $this->factory->get('config_test') +// ->execute(); + +// $this->assertEqual(count($this->queryResults), 3); +// debug($this->queryResults); +// $this->assertResult(); + + // Filter by ID with equality. + $this->queryResults = $this->factory->get('config_test') + ->condition('id', 3) + ->execute(); + + $this->assertEqual(count($this->queryResults), 1); + + // Filter by label with a known prefix. + $this->queryResults = $this->factory->get('config_test') + ->condition('label', 'test_prefix', 'STARTS_WITH') + ->execute(); + + $this->assertEqual(count($this->queryResults), 1); + $this->assertEqual($this->queryResults[0]->id, 3); + + // Filter by label with a known suffix. + $this->queryResults = $this->factory->get('config_test') + ->condition('label', 'test_suffix', 'ENDS_WITH') + ->execute(); + + $this->assertEqual(count($this->queryResults), 1); + $this->assertEqual($this->queryResults[0]->id, 4); + + // Filter by label with a known containing word. + $this->queryResults = $this->factory->get('config_test') + ->condition('label', 'test_contains', 'CONTAINS') + ->execute(); + + $this->assertEqual(count($this->queryResults), 1); + $this->assertEqual($this->queryResults[0]->id, 5); + + // Filter with an OR condition group. + $this->queryResults = $this->factory->get('config_test', 'OR') + ->condition('id', 1) + ->condition('id', 2) + ->execute(); + $this->assertEqual(count($this->queryResults), 2); + + return; + } + + /** + * Test entity count query. + */ + protected function testCount() { + $this->queryResults = $this->factory->get('config_test') + ->count() + ->execute(); + + $this->assertEqual(count($this->queryResults), 5); + } + +}