You are here

protected function InlineEntityFormTestBase::assertEntityByLabel in Inline Entity Form 8

Ensures that an entity with a specific label exists.

Parameters

string $label: The label of the entity.

string $entity_type_id: The entity type ID.

string $bundle: (optional) The bundle this entity should have.

1 call to InlineEntityFormTestBase::assertEntityByLabel()
SimpleWidgetTest::testEntityWithoutBundle in tests/src/FunctionalJavascript/SimpleWidgetTest.php
Ensures that an entity without bundles can be used with the simple widget.

File

tests/src/FunctionalJavascript/InlineEntityFormTestBase.php, line 130

Class

InlineEntityFormTestBase
Base Class for Inline Entity Form Tests.

Namespace

Drupal\Tests\inline_entity_form\FunctionalJavascript

Code

protected function assertEntityByLabel(string $label, $entity_type_id = 'node', $bundle = NULL) {
  $entity_type_manager = \Drupal::entityTypeManager();
  $entity_type = $entity_type_manager
    ->getDefinition($entity_type_id);
  $label_key = $entity_type
    ->getKey('label');
  $bundle_key = $entity_type
    ->getKey('bundle');
  $query = $entity_type_manager
    ->getStorage($entity_type_id)
    ->getQuery();
  $query
    ->condition($label_key, $label);
  if ($bundle && $bundle_key) {
    $query
      ->condition($bundle_key, $bundle);
  }
  $result = $query
    ->execute();
  $this
    ->assertNotEmpty($result);
}