You are here

public function DefaultFieldComparatorWebTestCase::testMultipleFieldValuesDeletion in Changed Fields API 7.2

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

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

File

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

Class

DefaultFieldComparatorWebTestCase
Class DefaultFieldComparatorWebTestCase.

Code

public function testMultipleFieldValuesDeletion() {
  $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',
        ),
        array(
          'value' => 'Text 2',
        ),
      ),
    ),
  ));
  $node->field_text_test[LANGUAGE_NONE] = array(
    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']), 2, 'Old field_text_test is multiple (2 values).');
    $this
      ->assertEqual(count($node->changed_fields['field_text_test']['new_value']), 1, 'New field_text_test is single.');
    $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 field_text_test second value is "Text 2".');
  }
}