You are here

public function DefaultFieldComparatorWebTestCase::testImageAlt in Changed Fields API 7.3

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

Check comparison of image field (with additional alt property).

If 'alt' option is enabled in field instance then API should take in into consideration.

File

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

Class

DefaultFieldComparatorWebTestCase
Class DefaultFieldComparatorWebTestCase.

Code

public function testImageAlt() {
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'promote' => 1,
    'title' => 'Title',
    'field_image_test' => [
      LANGUAGE_NONE => [
        $this
          ->createFile(drupal_get_path('module', 'changed_fields') . '/tests/test_files/test.png'),
      ],
    ],
  ]);
  $node->field_image_test[LANGUAGE_NONE][0]['alt'] = 'Alt changed';
  node_save($node);

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