public function MeasurementItemTest::testField in Physical Fields 8
Tests the field.
File
- tests/
src/ Kernel/ MeasurementItemTest.php, line 57
Class
- MeasurementItemTest
- Tests the 'physical_measurement' field type.
Namespace
Drupal\Tests\physical\KernelCode
public function testField() {
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = EntityTest::create([
'test_weight' => [
'number' => '10',
'unit' => 'lb',
],
]);
$entity
->save();
$entity = $this
->reloadEntity($entity);
/** @var \Drupal\physical\Plugin\Field\FieldType\MeasurementItem $item */
$item = $entity
->get('test_weight')
->first();
$measurement = $item
->toMeasurement();
$this
->assertInstanceOf(Weight::class, $measurement);
$this
->assertEquals(new Weight('10', 'lb'), $measurement);
}