public function RadioactivityFieldTypeTest::testSave in Radioactivity 4.0.x
Same name and namespace in other branches
- 8.3 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
->assertEqual($this->entity
->get('field_radioactivity')->energy, $defaultEnergy);
$this
->assertEqual($this->entity
->get('field_radioactivity')->timestamp, 1000);
// Updating an entity without changing the energy.
$this
->setRequestTime(1010);
$this->entity
->save();
$this
->assertEqual($this->entity
->get('field_radioactivity')->timestamp, 1000);
// Updating an entity with changing the energy.
$this
->setRequestTime(1020);
$this->entity
->get('field_radioactivity')->energy = 88;
$this->entity
->save();
$this
->assertEqual($this->entity
->get('field_radioactivity')->energy, 88);
$this
->assertEqual($this->entity
->get('field_radioactivity')->timestamp, 1020);
// @todo Test Unpublishing + Publishing an entity.
// Use a Node instead of TestEntity.
}