You are here

public function NumberFieldRdfaTest::testFloatFormatterWithScaleExercised in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php \Drupal\Tests\rdf\Kernel\Field\NumberFieldRdfaTest::testFloatFormatterWithScaleExercised()

Tests the float formatter with a scale. Scale is exercised.

File

core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php, line 125

Class

NumberFieldRdfaTest
Tests RDFa output by number field formatters.

Namespace

Drupal\Tests\rdf\Kernel\Field

Code

public function testFloatFormatterWithScaleExercised() {
  \Drupal::service('theme_installer')
    ->install([
    'classy',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'classy')
    ->save();
  $this->fieldType = 'float';
  $formatter = [
    'type' => 'number_decimal',
    'settings' => [
      'scale' => 5,
    ],
  ];
  $testValue = 3.1234567;
  $this
    ->createTestField();
  $this
    ->createTestEntity($testValue);
  $this
    ->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', [
    'value' => $testValue,
  ]);

  // Test that the content attribute is created.
  $result = $this
    ->xpathContent($this
    ->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', [
    ':testValue' => $testValue,
  ]);
  $this
    ->assertNotEmpty($result);
}