public function DateTimeItemTest::testSetValue in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/datetime/src/Tests/DateTimeItemTest.php \Drupal\datetime\Tests\DateTimeItemTest::testSetValue()
Tests DateTimeItem::setValue().
File
- core/
modules/ datetime/ src/ Tests/ DateTimeItemTest.php, line 87 - Contains \Drupal\datetime\Tests\DateTimeItemTest.
Class
- DateTimeItemTest
- Tests the new entity API for the date field type.
Namespace
Drupal\datetime\TestsCode
public function testSetValue() {
// Test DateTimeItem::setValue() using string.
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity
->get('field_datetime')
->set(0, $value);
$entity
->save();
// Load the entity and ensure the field was saved correctly.
$id = $entity
->id();
$entity = entity_load('entity_test', $id);
$this
->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.');
// Test DateTimeItem::setValue() using property array.
$entity = entity_create('entity_test');
$value = '2014-01-01T20:00:00Z';
$entity
->set('field_datetime', $value);
$entity
->save();
// Load the entity and ensure the field was saved correctly.
$id = $entity
->id();
$entity = entity_load('entity_test', $id);
$this
->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with array value.');
}