public function DefaultFieldComparatorWebTestCase::testFirstValueWasAdded in Changed Fields API 7.3
Same name and namespace in other branches
- 7.2 tests/default_field_comparator.test \DefaultFieldComparatorWebTestCase::testFirstValueWasAdded()
Check comparison: first value was added.
File
- tests/
default_field_comparator.test, line 136 - Test default field comparator.
Class
- DefaultFieldComparatorWebTestCase
- Class DefaultFieldComparatorWebTestCase.
Code
public function testFirstValueWasAdded() {
$node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
'title' => 'Title',
]);
$node->field_text_test = [
LANGUAGE_NONE => [
[
'value' => 'Text 1',
],
],
];
node_save($node);
// Let's ensure that only field_text_test field was changed.
$is_field_text_test_updated = !empty($node->changed_fields) && count($node->changed_fields) == 1 && !empty($node->changed_fields['field_text_test']);
$this
->assertEqual($is_field_text_test_updated, TRUE, 'Only field_text_test field was changed after node updating.');
if ($is_field_text_test_updated) {
$this
->assertEqual($node->changed_fields['field_text_test']['old_value'], FALSE, 'Old field_text_test value is empty.');
$this
->assertEqual($node->changed_fields['field_text_test']['new_value'][0]['value'], 'Text 1', 'New field_text_test value is "Text 1".');
}
}