public function EntityMetadataTestCase::testWrapperSerialization in Entity API 7
Tests serializing data wrappers, in particular for EntityDrupalWrapper.
File
- ./
entity.test, line 1100 - Entity CRUD API tests.
Class
- EntityMetadataTestCase
- Tests metadata wrappers.
Code
public function testWrapperSerialization() {
$node = $this
->drupalCreateNode();
$wrapper = entity_metadata_wrapper('node', $node);
$this
->assertTrue($wrapper
->value() == $node, 'Data correctly wrapped.');
// Test serializing and make sure only the node id is stored.
$this
->assertTrue(strpos(serialize($wrapper), $node->title) === FALSE, 'Node has been correctly serialized.');
$this
->assertEqual(unserialize(serialize($wrapper))->title
->value(), $node->title, 'Serializing works right.');
$wrapper2 = unserialize(serialize($wrapper));
// Test serializing the unloaded wrapper.
$this
->assertEqual(unserialize(serialize($wrapper2))->title
->value(), $node->title, 'Serializing works right.');
// Test loading a not more existing node.
$s = serialize($wrapper2);
node_delete($node->nid);
$this
->assertFalse(node_load($node->nid), 'Node deleted.');
$value = unserialize($s)
->value();
$this
->assertNull($value, 'Tried to load not existing node.');
}