public function DateEmwTestCase::testCheckEntityMetadataWrapper in Date 7.2
Same name and namespace in other branches
- 7.3 tests/DateEmwTestCase.test \DateEmwTestCase::testCheckEntityMetadataWrapper()
Test the edge case where timezone_db is empty.
In this case the value returned by entity metadata wrappers is not the same as that which is stored in the node.
See also
https://www.drupal.org/node/2123039
File
- tests/
DateEmwTestCase.test, line 94 - Test Date (ISO) and the Entity Metadata Wrappers play well together.
Class
- DateEmwTestCase
- Test Date (ISO) and the Entity Metadata Wrappers play well together.
Code
public function testCheckEntityMetadataWrapper() {
// Create and save a edit.
$edit = array();
$edit['title'] = 'Testing dates';
$edit['type'] = 'story';
$this
->drupalCreateNode($edit);
// Fetch the Node.
$node = $this
->drupalGetNodeByTitle($edit['title']);
// Prepare variables for token replacement.
$variables['node'] = $node;
// At this point we have a node with the appropriate field types available.
$wrapper = entity_metadata_wrapper('node', $node);
$original = '1482721671';
foreach ($this->date_types as $type => $label) {
$field = 'field_test_' . $type;
$wrapper->{$field} = $original;
$from_metadata_wrapper = $wrapper->{$field}
->value();
$this
->assertEqual($original, $from_metadata_wrapper, t('!type plays nicely with Entity Metadata Wrappers. !original == !fetched', array(
'!type' => $label,
'!original' => $original,
'!fetched' => $from_metadata_wrapper,
)));
$token = "[node:field-test-{$type}:raw]";
$from_token = token_replace($token, $variables);
$this
->assertEqual($original, $from_token, t('!type plays nicely with Entity tokens. !original == !fetched', array(
'!type' => $label,
'!original' => $original,
'!fetched' => $from_token,
)));
}
}