You are here

public function RadioactivityProcessorTest::testQueueProcessDecay in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/Unit/RadioactivityProcessorTest.php \Drupal\Tests\radioactivity\Unit\RadioactivityProcessorTest::testQueueProcessDecay()

@covers ::queueProcessDecay @dataProvider providerQueueProcessDecay

File

tests/src/Unit/RadioactivityProcessorTest.php, line 213

Class

RadioactivityProcessorTest
@coversDefaultClass \Drupal\radioactivity\RadioactivityProcessor @group radioactivity

Namespace

Drupal\Tests\radioactivity\Unit

Code

public function testQueueProcessDecay($profile, $halfLife, $cutoff, $initialEnergy, $elapsedTime, $isPublished, $resultEnergy) {
  $fieldConfig = $this
    ->prophesize(FieldStorageConfigInterface::class);
  $fieldConfig
    ->getTargetEntityTypeId()
    ->willReturn('entity_test');
  $fieldConfig
    ->get('field_name')
    ->willReturn('ra_field');
  $fieldConfig
    ->getSetting('profile')
    ->willReturn($profile);
  $fieldConfig
    ->getSetting('halflife')
    ->willReturn($halfLife);
  $fieldConfig
    ->getSetting('cutoff')
    ->willReturn($cutoff);
  $fieldItemList = $this
    ->prophesize(FieldItemListInterface::class);
  $fieldItemList
    ->getValue()
    ->willReturn([
    [
      'energy' => $initialEnergy,
      'timestamp' => $this->requestTime - $elapsedTime,
    ],
  ]);
  $fieldItemList
    ->setValue([
    'energy' => $resultEnergy,
    'timestamp' => $this->requestTime,
  ])
    ->shouldBeCalledTimes($isPublished ? 1 : 0);

  /** @var \Drupal\Core\Entity\EntityTypeInterface $entityType */
  $entityType = $this
    ->prophesize(EntityTypeInterface::class);
  $entityType
    ->isRevisionable()
    ->willReturn(FALSE);

  /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */
  $entity = $this
    ->prophesize(PublishedContentEntityInterface::class);
  $entity
    ->getEntityType()
    ->willReturn($entityType);
  $entity
    ->isPublished()
    ->willReturn($isPublished);
  $entity
    ->get('ra_field')
    ->willReturn($fieldItemList
    ->reveal());
  $entity
    ->save()
    ->shouldBeCalledTimes($isPublished ? 1 : 0);
  $entityStorage = $this
    ->prophesize(EntityStorageInterface::class);
  $entityStorage
    ->loadMultiple([
    123,
  ])
    ->willReturn([
    $entity
      ->reveal(),
  ]);
  $this->entityTypeManager
    ->getStorage('entity_test')
    ->willReturn($entityStorage
    ->reveal());
  $this->sut
    ->queueProcessDecay($fieldConfig
    ->reveal(), [
    123,
  ]);
}