function ConfigEntityQueryTest::testStringIdConditions

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testStringIdConditions()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testStringIdConditions()
  3. 11.x 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 375

Class

ConfigEntityQueryTest
Tests Config Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testStringIdConditions() : void {
  // 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([]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.