You are here

public function FractionGenerateSampleValueTest::testGenerateSampleValue in Fraction 2.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/FractionGenerateSampleValueTest.php \Drupal\Tests\fraction\Kernel\FractionGenerateSampleValueTest::testGenerateSampleValue()

Tests setting the sample value.

File

tests/src/Kernel/FractionGenerateSampleValueTest.php, line 58

Class

FractionGenerateSampleValueTest
Class to test generating and setting sample values.

Namespace

Drupal\Tests\fraction\Kernel

Code

public function testGenerateSampleValue() {
  $node = Node::create([
    'type' => 'article',
    'title' => 'test',
  ]);
  $node
    ->save();
  $node
    ->get(self::FIELD_NAME)
    ->generateSampleItems();
  $this
    ->entityValidateAndSave($node);
  $result = $node
    ->get(self::FIELD_NAME)
    ->getValue();
  $result = reset($result);
  $this
    ->assertTrue(is_array($result));
  $this
    ->assertArrayHasKey('numerator', $result);
  $this
    ->assertArrayHasKey('denominator', $result);
  $this
    ->assertTrue($result['denominator'] > 0, TRUE);
}