public function ConfigEntityQueryTest::testStringIdConditions in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testStringIdConditions()
Tests ID conditions.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Entity/ ConfigEntityQueryTest.php, line 373
Class
- ConfigEntityQueryTest
- Tests Config Entity Query functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testStringIdConditions() {
// We need an entity with a non-numeric ID.
$entity = ConfigQueryTest::create([
'label' => 'entity_1',
'id' => 'foo.bar',
]);
$this->entities[] = $entity;
$entity
->enforceIsNew();
$entity
->save();
// Test 'STARTS_WITH' condition.
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'foo.bar', 'STARTS_WITH')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'f', 'STARTS_WITH')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'miss', 'STARTS_WITH')
->execute();
$this
->assertResults([]);
// Test 'CONTAINS' condition.
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'foo.bar', 'CONTAINS')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'oo.ba', 'CONTAINS')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'miss', 'CONTAINS')
->execute();
$this
->assertResults([]);
// Test 'ENDS_WITH' condition.
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'foo.bar', 'ENDS_WITH')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'r', 'ENDS_WITH')
->execute();
$this
->assertResults([
'foo.bar',
]);
$this->queryResults = $this->entityStorage
->getQuery()
->condition('id', 'miss', 'ENDS_WITH')
->execute();
$this
->assertResults([]);
}