You are here

protected function RadioactivityFunctionTestTrait::createEnergyField in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Traits/RadioactivityFunctionTestTrait.php \Drupal\Tests\radioactivity\Traits\RadioactivityFunctionTestTrait::createEnergyField()

Adds an radioactivity energy field to the content type.

Parameters

string $fieldName: Field machine name.

string $profile: Profile type.

bool $required: Required input.

int|float $defaultEnergy: Field energy when the entity is created.

int $granularity: Energy decay granularity.

int $halfLifeTime: Half life time.

int|float $cutoff: Energy cut off value.

int $cardinality: Field cardinality.

5 calls to RadioactivityFunctionTestTrait::createEnergyField()
RadioactivityFieldTypeTest::testSave in tests/src/Kernel/RadioactivityFieldTypeTest.php
@covers ::preSave
RadioactivityFunctionTestTrait::addCountEnergyField in tests/src/Traits/RadioactivityFunctionTestTrait.php
Adds a Count type energy field to the content type.
RadioactivityFunctionTestTrait::addDecayEnergyField in tests/src/Traits/RadioactivityFunctionTestTrait.php
Adds a Decay type energy field to the content type.
RadioactivityFunctionTestTrait::addLinearEnergyField in tests/src/Traits/RadioactivityFunctionTestTrait.php
Adds a Linear type energy field to the content type.
RadioactivityValueFormatterTest::setUp in tests/src/Kernel/RadioactivityValueFormatterTest.php
Set the default field storage backend for fields created during tests.

File

tests/src/Traits/RadioactivityFunctionTestTrait.php, line 108

Class

RadioactivityFunctionTestTrait
Radioactivity functional test trait.

Namespace

Drupal\Tests\radioactivity\Traits

Code

protected function createEnergyField($fieldName, $profile, $required = FALSE, $defaultEnergy = 0, $granularity = 900, $halfLifeTime = 43200, $cutoff = 10, $cardinality = 1) {
  FieldStorageConfig::create([
    'entity_type' => $this->entityType,
    'type' => 'radioactivity',
    'field_name' => $fieldName,
    'cardinality' => $cardinality,
    'settings' => [
      'profile' => $profile,
      'granularity' => $granularity,
      'halflife' => $halfLifeTime,
      'cutoff' => $cutoff,
    ],
  ])
    ->save();
  FieldConfig::create([
    'entity_type' => $this->entityType,
    'bundle' => $this->entityBundle,
    'field_name' => $fieldName,
    'required' => $required,
    'default_value' => [
      [
        'energy' => $defaultEnergy,
        'timestamp' => 0,
      ],
    ],
  ])
    ->save();
}