You are here

protected function LinkCheckerLinkAccessTest::createBundle in Link checker 8

Helper function for bundle creation.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entityTypeDefinition: The enity type.

Return value

string The nudle ID.

1 call to LinkCheckerLinkAccessTest::createBundle()
LinkCheckerLinkAccessTest::testLinkAccess in tests/src/Kernel/LinkCheckerLinkAccessTest.php
Runs basic tests for link access.

File

tests/src/Kernel/LinkCheckerLinkAccessTest.php, line 244

Class

LinkCheckerLinkAccessTest
Tests basic linkchecker link access functionality.

Namespace

Drupal\Tests\linkchecker\Kernel

Code

protected function createBundle(EntityTypeInterface $entityTypeDefinition) {
  if ($bundleEntityType = $entityTypeDefinition
    ->getBundleEntityType()) {
    $bundleStorage = $this->entityTypeManager
      ->getStorage($bundleEntityType);

    // To be sure that we will create non-existing bundle.
    do {
      $bundleId = strtolower($this
        ->randomMachineName(8));
    } while ($bundleStorage
      ->load($bundleId));
    $bundleTypeDefinition = $this->entityTypeManager
      ->getDefinition($bundleEntityType);
    $bundle = $bundleStorage
      ->create([
      $bundleTypeDefinition
        ->getKey('id') => $bundleId,
      $bundleTypeDefinition
        ->getKey('label') => $bundleId,
    ]);
    $bundle
      ->save();
  }
  else {
    $bundleId = $entityTypeDefinition
      ->id();
  }
  return $bundleId;
}