public function DimensionsItemTest::testField in Physical Fields 8
Tests the field.
File
- tests/
src/ Kernel/ DimensionsItemTest.php, line 54
Class
- DimensionsItemTest
- Tests the 'physical_dimensions' field type.
Namespace
Drupal\Tests\physical\KernelCode
public function testField() {
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = EntityTest::create([
'test_dimensions' => [
'length' => '5',
'width' => '7',
'height' => '2',
'unit' => 'in',
],
]);
$entity
->save();
$entity = $this
->reloadEntity($entity);
/** @var \Drupal\physical\Plugin\Field\FieldType\DimensionsItem $item */
$item = $entity
->get('test_dimensions')
->first();
$length = $item
->getLength();
$this
->assertInstanceOf(Length::class, $length);
$this
->assertEquals(new Length('5', 'in'), $length);
$width = $item
->getWidth();
$this
->assertInstanceOf(Length::class, $width);
$this
->assertEquals(new Length('7', 'in'), $width);
$height = $item
->getHeight();
$this
->assertInstanceOf(Length::class, $height);
$this
->assertEquals(new Length('2', 'in'), $height);
}