View source
<?php
namespace Drupal\rdf\Tests\Field;
class NumberFieldRdfaTest extends FieldRdfaTestBase {
public function testIntegerFormatter() {
$this->fieldType = 'integer';
$testValue = 3;
$this
->createTestField();
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa(array(
'type' => 'number_integer',
), 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__items") and @content]');
$this
->assertFalse($result);
}
public function testIntegerFormatterWithSettings() {
\Drupal::service('theme_handler')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->save();
$this->fieldType = 'integer';
$formatter = array(
'type' => 'number_integer',
'settings' => array(
'thousand_separator' => '.',
'prefix_suffix' => TRUE,
),
);
$testValue = 3333333.33;
$field_settings = array(
'prefix' => '#',
'suffix' => ' llamas.',
);
$this
->createTestField($field_settings);
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(
':testValue' => $testValue,
));
$this
->assertTrue($result);
}
public function testFloatFormatter() {
$this->fieldType = 'float';
$testValue = 3.33;
$this
->createTestField();
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa(array(
'type' => 'number_unformatted',
), 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__items") and @content]');
$this
->assertFalse($result);
}
public function testFloatFormatterWithSettings() {
\Drupal::service('theme_handler')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->save();
$this->fieldType = 'float';
$formatter = array(
'type' => 'number_decimal',
'settings' => array(
'thousand_separator' => '.',
'decimal_separator' => ',',
'prefix_suffix' => TRUE,
),
);
$testValue = 3333333.33;
$field_settings = array(
'prefix' => '$',
'suffix' => ' more.',
);
$this
->createTestField($field_settings);
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(
':testValue' => $testValue,
));
$this
->assertTrue($result);
}
public function testFloatFormatterWithScale() {
$this->fieldType = 'float';
$formatter = array(
'type' => 'number_decimal',
'settings' => array(
'scale' => 5,
),
);
$testValue = 3.33;
$this
->createTestField();
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__items") and @content]');
$this
->assertFalse($result);
}
public function testFloatFormatterWithScaleExercised() {
\Drupal::service('theme_handler')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->save();
$this->fieldType = 'float';
$formatter = array(
'type' => 'number_decimal',
'settings' => array(
'scale' => 5,
),
);
$testValue = 3.1234567;
$this
->createTestField();
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(
':testValue' => $testValue,
));
$this
->assertTrue($result);
}
public function testDecimalFormatter() {
$this->fieldType = 'decimal';
$testValue = 3.33;
$this
->createTestField();
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa(array(
'type' => 'number_decimal',
), 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__items") and @content]');
$this
->assertFalse($result);
}
public function testDecimalFormatterWithSettings() {
\Drupal::service('theme_handler')
->install([
'classy',
]);
$this
->config('system.theme')
->set('default', 'classy')
->save();
$this->fieldType = 'decimal';
$formatter = array(
'type' => 'number_decimal',
'settings' => array(
'thousand_separator' => 't',
'decimal_separator' => '#',
'prefix_suffix' => TRUE,
),
);
$testValue = 3333333.33;
$field_settings = array(
'prefix' => '$',
'suffix' => ' more.',
);
$this
->createTestField($field_settings);
$this
->createTestEntity($testValue);
$this
->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array(
'value' => $testValue,
));
$result = $this
->xpathContent($this
->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(
':testValue' => $testValue,
));
$this
->assertTrue($result);
}
protected function createTestEntity($testValue) {
$mapping = rdf_get_mapping('entity_test', 'entity_test');
$mapping
->setFieldMapping($this->fieldName, array(
'properties' => array(
'schema:baseSalary',
),
))
->save();
$this->entity = entity_create('entity_test', array());
$this->entity->{$this->fieldName}->value = $testValue;
}
}