You are here

protected function WorkspaceTestUtilities::getOneEntityByLabel in Workspace 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/WorkspaceTestUtilities.php \Drupal\Tests\workspace\Functional\WorkspaceTestUtilities::getOneEntityByLabel()

Loads a single entity by its label.

The UI approach to creating an entity doesn't make it easy to know what the ID is, so this lets us make paths for an entity after it's created.

Parameters

string $type: The type of entity to load.

$label: The label of the entity to load.

Return value

\Drupal\multiversion\Entity\WorkspaceInterface

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

10 calls to WorkspaceTestUtilities::getOneEntityByLabel()
ReplicationSettingsTest::testPullReplicationSettings in tests/src/Functional/ReplicationSettingsTest.php
Verify pull replication settings using the published filter as an example.
ReplicationSettingsTest::testPushReplicationSettings in tests/src/Functional/ReplicationSettingsTest.php
Verify push replication settings using the published filter as an example.
ReplicatorAliasTest::testReplicationAlias in tests/src/Functional/ReplicatorAliasTest.php
Verifies that a user can edit anything in a workspace with a specific perm.
ReplicatorTest::testReplication in tests/src/Functional/ReplicatorTest.php
Test replication.
ReplicatorTest::testSelectiveContentReplication in tests/src/Functional/ReplicatorTest.php
Test selective content replication.

... See full list

File

tests/src/Functional/WorkspaceTestUtilities.php, line 47

Class

WorkspaceTestUtilities
Utility methods for use in BrowserTestBase tests.

Namespace

Drupal\Tests\workspace\Functional

Code

protected function getOneEntityByLabel($type, $label) {

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $etm */
  $etm = \Drupal::service('entity_type.manager');
  $property = $etm
    ->getDefinition($type)
    ->getKey('label');

  /** @var \Drupal\multiversion\Entity\WorkspaceInterface $bears */
  $entity_list = $etm
    ->getStorage($type)
    ->loadByProperties([
    $property => $label,
  ]);
  $entity = current($entity_list);
  if (!$entity) {
    $this
      ->fail("No {$type} entity named {$label} found.");
  }
  return $entity;
}