You are here

protected function EntityTypeBundleInfoTest::createNewTestSubjectWithEntityTypeAndBundles in Entity Construction Kit (ECK) 8

Creates a new test subject with entity type and bundles.

Parameters

int $numberOfBundlesToCreate: The number of bundles to create.

Return value

\Drupal\eck\EckEntityTypeBundleInfo The bundle info to test.

3 calls to EntityTypeBundleInfoTest::createNewTestSubjectWithEntityTypeAndBundles()
EntityTypeBundleInfoTest::correctlyCountsEntityTypeBundles in tests/src/Unit/EntityTypeBundleInfoTest.php
Tests that the number of entity type bundles is counted correctly.
EntityTypeBundleInfoTest::returnsMachineNamesIfEntityTypeHasBundles in tests/src/Unit/EntityTypeBundleInfoTest.php
Tests that machine names are returned if there are bundles.
EntityTypeBundleInfoTest::returnsTrueWhenEntityTypeHasAtLeastOneBundle in tests/src/Unit/EntityTypeBundleInfoTest.php
Tests that entityTypeHasBundles returns true if it has bundles.

File

tests/src/Unit/EntityTypeBundleInfoTest.php, line 239

Class

EntityTypeBundleInfoTest
Tests the form element implementation.

Namespace

Drupal\Tests\eck\Unit

Code

protected function createNewTestSubjectWithEntityTypeAndBundles($numberOfBundlesToCreate = 1) {
  $bundles = [];
  for ($i = 0; $i < $numberOfBundlesToCreate; $i++) {
    $machineName = $this
      ->randomMachineName();
    $bundleMock = $this
      ->getMockForAbstractClass(EntityInterface::class);
    $bundleMock
      ->method('id')
      ->willReturn(strtolower($machineName));
    $bundleMock
      ->method('label')
      ->willReturn($machineName);
    $bundles[strtolower($machineName)] = $bundleMock;
  }
  $entityStorageMock = $this
    ->getMockForAbstractClass(EntityStorageInterface::class);
  $entityStorageMock
    ->method('loadMultiple')
    ->willReturn($bundles);
  return $this
    ->createNewTestSubjectWithEntityType(NULL, $entityStorageMock);
}