You are here

public function EmitTest::testCount in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x tests/src/FunctionalJavascript/EmitTest.php \Drupal\Tests\radioactivity\FunctionalJavascript\EmitTest::testCount()

Tests Radioactivity count functionality.

File

tests/src/FunctionalJavascript/EmitTest.php, line 28

Class

EmitTest
Testing the energy emission of the radioactivity field.

Namespace

Drupal\Tests\radioactivity\FunctionalJavascript

Code

public function testCount() {
  $this->fieldName = 'field_count_energy';
  $this
    ->setEntityType('entity_test');
  $this
    ->setEntityBundle('entity_test');
  $this
    ->addCountEnergyField($this->fieldName);
  $this
    ->createEnergyFormDisplay($this->fieldName);
  $this
    ->createEmitterViewDisplay($this->fieldName, 1, 'raw');
  $entity = $this
    ->createContent();
  $this
    ->assetIncidentCount(0);
  $this
    ->drupalGet($entity
    ->toUrl());
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assetIncidentCount(1);
  $this
    ->assertPageEnergyValue($this->fieldName, 0);
  $this
    ->assertFieldEnergyValue($entity, $this->fieldName, 0);

  // Run cron from the browser.
  $this
    ->cronRun();

  // The entity has updated values, reload it.

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = \Drupal::entityTypeManager()
    ->getStorage($this->entityType)
    ->load($entity
    ->id());
  $this
    ->assetIncidentCount(0);
  $this
    ->assertFieldEnergyValue($entity, $this->fieldName, 1);
  $this
    ->drupalGet($entity
    ->toUrl());
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertPageEnergyValue($this->fieldName, 1);
}