function ConfigEntityQueryTest::testDotted

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testDotted()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testDotted()
  3. 11.x core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php \Drupal\KernelTests\Core\Entity\ConfigEntityQueryTest::testDotted()

Tests dotted path matching.

File

core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php, line 582

Class

ConfigEntityQueryTest
Tests Config Entity Query functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testDotted() {
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->condition('array.level1.*', 1)
        ->execute();
    $this->assertResults([
        '1',
        '3',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->condition('*.level1.level2', 2)
        ->execute();
    $this->assertResults([
        '2',
        '4',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->condition('array.level1.*', 3)
        ->execute();
    $this->assertResults([
        '5',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->condition('array.level1.level2', 3)
        ->execute();
    $this->assertResults([
        '5',
    ]);
    // Test dotted sorting.
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->sort('array.level1.level2')
        ->execute();
    $this->assertResults([
        '6',
        '1',
        '3',
        '2',
        '4',
        '5',
        '7',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->sort('array.level1.level2', 'DESC')
        ->execute();
    $this->assertResults([
        '7',
        '5',
        '2',
        '4',
        '1',
        '3',
        '6',
    ]);
    // Make sure that values on the wildcard level do not match if there are
    // sub-keys defined. This must not find anything even if entity 2 has a
    // top-level key number with value 41.
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->condition('*.level1.level2', 41)
        ->execute();
    $this->assertResults([]);
    // Make sure that "IS NULL" and "IS NOT NULL" work correctly with
    // array-valued fields/keys.
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->exists('array.level1.level2')
        ->execute();
    $this->assertResults([
        '1',
        '2',
        '3',
        '4',
        '5',
        '7',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->exists('array.level1')
        ->execute();
    $this->assertResults([
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->exists('array')
        ->execute();
    $this->assertResults([
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->notExists('array.level1.level2')
        ->execute();
    $this->assertResults([
        '6',
    ]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->notExists('array.level1')
        ->execute();
    $this->assertResults([]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->notExists('array')
        ->execute();
    $this->assertResults([]);
    // Make sure that "IS NULL" and "IS NOT NULL" work correctly when the dotted
    // path cannot be fully followed.
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->exists('does.not.exist')
        ->execute();
    $this->assertResults([]);
    $this->queryResults = $this->entityStorage
        ->getQuery()
        ->notExists('does.not.exist')
        ->execute();
    $this->assertResults([
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
    ]);
}

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