public function ExtendedFieldComparatorWebTestCase::testGetDefaultComparablePropertiesMethod in Changed Fields API 7.2
Same name and namespace in other branches
- 7.3 tests/extended_field_comparator.test \ExtendedFieldComparatorWebTestCase::testGetDefaultComparablePropertiesMethod()
Custom field comparison.
File
- tests/
extended_field_comparator.test, line 52 - Test extended field comparator.
Class
- ExtendedFieldComparatorWebTestCase
- Class CoreFieldsWebTestCase.
Code
public function testGetDefaultComparablePropertiesMethod() {
// Create article with fields.
$node = $this
->drupalCreateNode(array(
'type' => 'article',
'promote' => 1,
'title' => 'Title',
'body' => array(
LANGUAGE_NONE => array(
array(
'value' => 'Body',
'format' => 'plain_text',
'summary' => 'Summary',
),
),
),
'custom_field' => array(
LANGUAGE_NONE => array(
array(
'value_1' => 'Value 1',
'value_2' => 'Value 2',
),
),
),
));
// Change node custom_field values.
$node->custom_field[LANGUAGE_NONE][0]['value_1'] .= ' changed';
node_save($node);
// Let's ensure that only custom_field field was changed.
$is_custom_field_updated = !empty($node->changed_fields) && count($node->changed_fields) == 1 && !empty($node->changed_fields['custom_field']);
$this
->assertEqual($is_custom_field_updated, TRUE, 'Only custom_field field was changed after node updating.');
if ($is_custom_field_updated) {
// Check changed custom_field value_1.
$this
->assertEqual($node->changed_fields['custom_field']['old_value'][0]['value_1'], 'Value 1', 'Old custom_field value_1 is "Value 1".');
$this
->assertEqual($node->changed_fields['custom_field']['new_value'][0]['value_1'], 'Value 1 changed', 'New custom_field value_1 "Value 1 changed".');
}
}