You are here

public function DefaultFieldComparatorWebTestCase::testMultipleFieldValuesAddition in Changed Fields API 7.2

Same name and namespace in other branches
  1. 7.3 tests/default_field_comparator.test \DefaultFieldComparatorWebTestCase::testMultipleFieldValuesAddition()

Check comparison of multi-value fields - add a field value.

File

tests/default_field_comparator.test, line 196
Test default field comparator.

Class

DefaultFieldComparatorWebTestCase
Class DefaultFieldComparatorWebTestCase.

Code

public function testMultipleFieldValuesAddition() {
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => 1,
    'title' => 'Title',
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Body',
          'format' => filter_default_format(),
          'summary' => 'Summary',
        ),
      ),
    ),
    'field_text_test' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Text 1',
        ),
      ),
    ),
  ));
  $node->field_text_test[LANGUAGE_NONE][] = array(
    'value' => 'Text 2',
  );
  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']), 1, 'Old field_text_test is single.');
    $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 field_text_test value is "Text 1".');
    $this
      ->assertEqual($node->changed_fields['field_text_test']['new_value'][0]['value'], 'Text 1', 'New field_text_test first value is "Text 1".');
    $this
      ->assertEqual($node->changed_fields['field_text_test']['new_value'][1]['value'], 'Text 2', 'New field_text_test second value is "Text 2".');
  }
}