public function IntervalItemTest::testValueChange in Interval Field 8
Tests using entity fields of the interval field type.
File
- tests/
src/ Kernel/ IntervalItemTest.php, line 64
Class
- IntervalItemTest
- Defines a class for testing interval item.
Namespace
Drupal\Tests\interval\KernelCode
public function testValueChange() {
// Verify entity creation.
$entity = EntityTest::create();
$value = [
'interval' => 30,
'period' => 'minute',
];
$entity->field_interval = $value;
$entity->name->value = $this
->randomMachineName();
$this
->entityValidateAndSave($entity);
// Verify initial field value
$this
->assertEqual($entity->field_interval->interval, $value['interval']);
$this
->assertEqual($entity->field_interval->period, $value['period']);
$this
->assertEqual($entity
->get('field_interval')
->first()
->buildPHPString(), '30 minutes');
// Verify changing the date value.
$new_value = [
'interval' => 2,
'period' => 'hour',
];
$entity->field_interval = $new_value;
$this
->assertEqual($entity->field_interval->interval, $new_value['interval']);
$this
->assertEqual($entity->field_interval->period, $new_value['period']);
$this
->assertEqual($entity
->get('field_interval')
->first()
->buildPHPString(), '2 hours');
}