You are here

public function DefaultFieldComparatorWebTestCase::testLastValueWasDeleted in Changed Fields API 7.2

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

Check comparison: last value was deleted.

File

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

Class

DefaultFieldComparatorWebTestCase
Class DefaultFieldComparatorWebTestCase.

Code

public function testLastValueWasDeleted() {
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'promote' => 1,
    'title' => 'Title',
    'field_text_test' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Text 1',
        ),
      ),
    ),
  ));
  unset($node->field_text_test[LANGUAGE_NONE][0]);
  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($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'], FALSE, 'New field_text_test value is empty.');
  }
}