You are here

public function ParagraphsPackTestCase::testParagraphsPackFieldFileInstanceCreation in Paragraphs pack 7

Test function for field file instance creation.

File

tests/paragraphs_pack.test, line 381
Paragraphs pack primary module's tests.

Class

ParagraphsPackTestCase
Test Case for Paragraphs pack primary module.

Code

public function testParagraphsPackFieldFileInstanceCreation() {
  $field_label = 'Test file';
  $settings = array(
    'file_extensions' => 'png jpg gif',
  );

  // Run tested function.
  paragraphs_pack_add_field_file($this->paragraph_bundle_name, $field_label, $settings);

  // Test field instance existence.
  $field = paragraphs_pack_get_field_file();
  $instance_info = field_info_instance(PP_PARAGRAPH_TYPE, $field['field_name'], $this->paragraph_bundle_name);
  $instance_exists = !empty($instance_info);
  $this
    ->assertTrue($instance_exists, t('Instance was created successfully.'));

  // Test field instance settings.
  if ($instance_exists) {
    $this
      ->assertEqual($instance_info['field_name'], $field['field_name']);
    $this
      ->assertEqual($instance_info['entity_type'], PP_PARAGRAPH_TYPE);
    $this
      ->assertEqual($instance_info['bundle'], $this->paragraph_bundle_name);
    $this
      ->assertEqual($instance_info['label'], $field_label);
    $settings_difference = $this
      ->array_diff_assoc_deep($settings, $instance_info['settings']);
    $this
      ->assertTrue(empty($settings_difference), t('Field instance contains all specified settings. Differences (print_r) %differences', array(
      '%differences' => print_r($settings_difference, TRUE),
    )));
  }
}