You are here

public function RadioactivityProcessorTest::testQueueProcessDecay in Radioactivity 4.0.x

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

@covers ::queueProcessDecay @dataProvider providerQueueProcessDecay

File

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

Class

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

Namespace

Drupal\Tests\radioactivity\Unit

Code

public function testQueueProcessDecay($fieldType, $profile, $halfLife, $cutoff, $initialEnergy, $elapsedTime, $isPublished, $langcode, $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
    ->createMock(FieldItemListInterface::class);
  $fieldItemList
    ->expects($this
    ->any())
    ->method('__get')
    ->willReturn($this
    ->returnValueMap([
    [
      'energy',
      $initialEnergy,
    ],
    [
      'timestamp',
      $this->requestTime - $elapsedTime,
    ],
  ]));
  $fieldItemList
    ->expects($isPublished ? $this
    ->once() : $this
    ->never())
    ->method('setValue')
    ->with([
    'energy' => $resultEnergy,
    'timestamp' => $this->requestTime,
  ]);
  $fieldDefinition = $this
    ->prophesize(FieldDefinitionInterface::class);
  $fieldDefinition
    ->getType()
    ->willReturn($fieldType);
  $fieldItemList
    ->expects($this
    ->any())
    ->method('getFieldDefinition')
    ->willReturn($fieldDefinition);
  $language = $this
    ->prophesize(LanguageInterface::class);
  $language
    ->getId()
    ->willReturn($langcode);

  /** @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);
  $entity
    ->save()
    ->shouldBeCalledTimes($isPublished ? 1 : 0);
  $entity
    ->getTranslationLanguages()
    ->willReturn([
    $language,
  ]);
  $entity
    ->getTranslation($langcode)
    ->willReturn($entity);
  $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,
  ]);
}