public function RadioactivityFieldTypeTest::testSave in Radioactivity 8.3
Same name and namespace in other branches
- 4.0.x tests/src/Kernel/RadioactivityFieldTypeTest.php \Drupal\Tests\radioactivity\Kernel\RadioactivityFieldTypeTest::testSave()
@covers ::preSave
File
- tests/
src/ Kernel/ RadioactivityFieldTypeTest.php, line 69
Class
- RadioactivityFieldTypeTest
- @coversDefaultClass \Drupal\radioactivity\Plugin\Field\FieldType\RadioactivityField @group radioactivity
Namespace
Drupal\Tests\radioactivity\KernelCode
public function testSave() {
$defaultEnergy = 99;
$this
->createEnergyField('field_radioactivity', 'count', TRUE, $defaultEnergy);
// Creating an entity.
$this
->setRequestTime(1000);
$this->entity = EntityTest::create();
$this->entity
->save();
$this
->assertEquals($defaultEnergy, $this->entity
->get('field_radioactivity')->energy);
$this
->assertEquals(1000, $this->entity
->get('field_radioactivity')->timestamp);
// Updating an entity without changing the energy.
$this
->setRequestTime(1010);
$this->entity
->save();
$this
->assertEquals(1000, $this->entity
->get('field_radioactivity')->timestamp);
// Updating an entity with changing the energy.
$this
->setRequestTime(1020);
$this->entity
->get('field_radioactivity')->energy = 88;
$this->entity
->save();
$this
->assertEquals(88, $this->entity
->get('field_radioactivity')->energy);
$this
->assertEquals(1020, $this->entity
->get('field_radioactivity')->timestamp);
// @todo Test Unpublishing + Publishing an entity.
// Use a Node instead of TestEntity.
}