You are here

public function DefaultFieldComparatorWebTestCase::testFileField in Changed Fields API 7.3

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

Check comparison of file field.

File

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

Class

DefaultFieldComparatorWebTestCase
Class DefaultFieldComparatorWebTestCase.

Code

public function testFileField() {
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'promote' => 1,
    'title' => 'Title',
    'field_file_test' => [
      LANGUAGE_NONE => [
        $this
          ->createFile(drupal_get_path('module', 'changed_fields') . '/tests/test_files/test_1.txt'),
      ],
    ],
  ]);
  $node->field_file_test[LANGUAGE_NONE][0] = $this
    ->createFile(drupal_get_path('module', 'changed_fields') . '/tests/test_files/test_2.txt');
  node_save($node);

  // Let's ensure that only field_file_test field was changed.
  $is_field_file_test_updated = !empty($node->changed_fields) && count($node->changed_fields) == 1 && !empty($node->changed_fields['field_file_test']);
  $this
    ->assertEqual($is_field_file_test_updated, TRUE, 'Only field_file_test field was changed after node updating.');
  if ($is_field_file_test_updated) {
    $this
      ->assertEqual($node->changed_fields['field_file_test']['old_value'][0]['fid'], '1', 'Old field_file_test fid is "1".');
    $this
      ->assertEqual($node->changed_fields['field_file_test']['new_value'][0]['fid'], '2', 'New field_file_test fid is "2".');
  }
}