You are here

public function DateTimeItemTest::testSetValueProperty in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Tests/DateTimeItemTest.php \Drupal\datetime\Tests\DateTimeItemTest::testSetValueProperty()

Tests setting the value of the DateTimeItem directly.

File

core/modules/datetime/src/Tests/DateTimeItemTest.php, line 112
Contains \Drupal\datetime\Tests\DateTimeItemTest.

Class

DateTimeItemTest
Tests the new entity API for the date field type.

Namespace

Drupal\datetime\Tests

Code

public function testSetValueProperty() {

  // Test Date::setValue().
  $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, '"Value" property can be set directly.');
}