public function DefaultFieldComparatorWebTestCase::testMultipleFieldValuesOrdering in Changed Fields API 7.3
Same name and namespace in other branches
- 7.2 tests/default_field_comparator.test \DefaultFieldComparatorWebTestCase::testMultipleFieldValuesOrdering()
Check comparison of multi-value fields - ordering.
File
- tests/
default_field_comparator.test, line 292 - Test default field comparator.
Class
- DefaultFieldComparatorWebTestCase
- Class DefaultFieldComparatorWebTestCase.
Code
public function testMultipleFieldValuesOrdering() {
$node = $this
->drupalCreateNode([
'type' => 'article',
'promote' => 1,
'title' => 'Title',
'body' => [
LANGUAGE_NONE => [
[
'value' => 'Body',
'format' => filter_default_format(),
'summary' => 'Summary',
],
],
],
'field_text_test' => [
LANGUAGE_NONE => [
[
'value' => 'Text 1',
],
[
'value' => 'Text 2',
],
],
],
]);
$node->field_text_test[LANGUAGE_NONE] = [
[
'value' => 'Text 2',
],
[
'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(count($node->changed_fields['field_text_test']['old_value']), 2, 'Old field_text_test is multiple (2 values).');
$this
->assertEqual(count($node->changed_fields['field_text_test']['new_value']), 2, 'New field_text_test is multiple (2 values).');
$this
->assertEqual($node->changed_fields['field_text_test']['old_value'][0]['value'], 'Text 1', 'Old first field_text_test value is "Text 1".');
$this
->assertEqual($node->changed_fields['field_text_test']['old_value'][1]['value'], 'Text 2', 'Old second field_text_test first value is "Text 2".');
$this
->assertEqual($node->changed_fields['field_text_test']['new_value'][0]['value'], 'Text 2', 'New first field_text_test value is "Text 2".');
$this
->assertEqual($node->changed_fields['field_text_test']['new_value'][1]['value'], 'Text 1', 'New second field_text_test first value is "Text 1".');
}
}