public function ExtendedFieldComparatorWebTestCase::testExtendComparablePropertiesMethod in Changed Fields API 7.2
Same name and namespace in other branches
- 7.3 tests/extended_field_comparator.test \ExtendedFieldComparatorWebTestCase::testExtendComparablePropertiesMethod()
Add property for custom field comparison.
File
- tests/
extended_field_comparator.test, line 96 - Test extended field comparator.
Class
- ExtendedFieldComparatorWebTestCase
- Class CoreFieldsWebTestCase.
Code
public function testExtendComparablePropertiesMethod() {
// 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_2'] .= ' 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_2'], 'Value 2', 'Old custom_field value_2 is "Value 2".');
$this
->assertEqual($node->changed_fields['custom_field']['new_value'][0]['value_2'], 'Value 2 changed', 'New custom_field value_2 "Value 2 changed".');
}
}