function RulesTestDataCase::testRulesIdentifiableDataWrapper in Rules 8.3
Same name and namespace in other branches
- 7.2 tests/rules.test \RulesTestDataCase::testRulesIdentifiableDataWrapper()
Makes sure the RulesIdentifiableDataWrapper is working correctly.
File
- d7-tests/
rules_test_data_case.test, line 122 - Rules 7.x tests.
Class
- RulesTestDataCase
- Test rules data wrappers.
Code
function testRulesIdentifiableDataWrapper() {
$node = $this
->drupalCreateNode();
$wrapper = new RulesTestTypeWrapper('rules_test_type', $node);
$this
->assertTrue($wrapper
->value() == $node, 'Data correctly wrapped.');
// Test serializing and make sure only the id is stored.
$this
->assertTrue(strpos(serialize($wrapper), $node->title) === FALSE, 'Data has been correctly serialized.');
$this
->assertEqual(unserialize(serialize($wrapper))
->value()->title, $node->title, 'Serializing works right.');
$wrapper2 = unserialize(serialize($wrapper));
// Test serializing the unloaded wrapper.
$this
->assertEqual(unserialize(serialize($wrapper2))
->value()->title, $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.');
try {
unserialize($s)
->value();
$this
->fail("Loading hasn't created an exception.");
} catch (EntityMetadataWrapperException $e) {
$this
->pass("Exception was thrown: " . $e
->getMessage());
}
// Test saving a saveable custom, identifiable wrapper.
$action = rules_action('test_type_save');
$node = $this
->drupalCreateNode(array(
'status' => 0,
'type' => 'page',
));
$node->status = 1;
$action
->execute($node);
// Load the node fresh from the db.
$node = node_load($node->nid, NULL, TRUE);
$this
->assertEqual($node->status, 1, 'Savable non-entity has been saved.');
}