function RulesTestDataCase::testDataSaving
Same name in other branches
- 7.x-2.x tests/rules.test \RulesTestDataCase::testDataSaving()
Tests intelligently saving data.
File
-
d7-tests/
rules_test_data_case.test, line 37
Class
- RulesTestDataCase
- Test rules data wrappers.
Code
function testDataSaving() {
$node = $this->drupalCreateNode();
$state = new RulesState(rule());
$state->addVariable('node', $node, array(
'type' => 'node',
));
$wrapper = $state->get('node');
$node->title = 'test';
$wrapper->set($node);
$state->saveChanges('node', $wrapper, FALSE);
$this->assertFalse($this->drupalGetNodeByTitle('test'), 'Changes have not been saved.');
$state->saveChanges('node', $wrapper, TRUE);
$this->assertTrue($this->drupalGetNodeByTitle('test'), 'Changes have been saved.');
// Test skipping saving.
$state->addVariable('node2', $node, array(
'type' => 'node',
'skip save' => TRUE,
));
$wrapper = $state->get('node2');
$node->title = 'test2';
$wrapper->set($node);
$state->saveChanges('node2', $wrapper, TRUE);
$this->assertFalse($this->drupalGetNodeByTitle('test2'), 'Changes have not been saved.');
// Try saving a non-entity wrapper, which should result in saving the
// parent entity containing the property.
$wrapper = $state->get('node');
$wrapper->title
->set('test3');
$state->saveChanges('node:title', $wrapper, TRUE);
$this->assertTrue($this->drupalGetNodeByTitle('test3'), 'Parent entity has been saved.');
}