function EntityQueryRelationshipTest::testInvalidFieldName

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php \Drupal\KernelTests\Core\Entity\EntityQueryRelationshipTest::testInvalidFieldName()

Tests a non-existent field name in a complex query relationship.

Attributes

#[DataProvider('providerTestInvalidFieldName')]

File

core/tests/Drupal/KernelTests/Core/Entity/EntityQueryRelationshipTest.php, line 234

Class

EntityQueryRelationshipTest
Tests the Entity Query relationship API.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testInvalidFieldName(string $field_name) : void {
  $this->expectException(QueryException::class);
  $this->expectExceptionMessage("'non_existent_field_name' not found");
  // Check that non-existent field names in a complex relationship query
  // throws a meaningful exception.
  $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_test')
    ->getQuery()
    ->accessCheck()
    ->condition($field_name, $this->randomString(), '=')
    ->execute();
}

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