You are here

public function ParagraphsPackTestCase::testParagraphsPackFieldBodyInstanceCreation in Paragraphs pack 7

Test function for field body instance creation.

File

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

Class

ParagraphsPackTestCase
Test Case for Paragraphs pack primary module.

Code

public function testParagraphsPackFieldBodyInstanceCreation() {
  $field_label = 'Test body';

  // Run function that's being tested.
  paragraphs_pack_add_field_body($this->paragraph_bundle_name, $field_label);

  // Test field instance existence.
  $field = paragraphs_pack_get_field_body();
  $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);
    $this
      ->assertEqual($instance_info['settings']['display_summary'], TRUE);

    // Test widget settings.
    $widget = array(
      'module' => 'text',
      'settings' => array(
        'rows' => 5,
      ),
      'type' => 'text_textarea',
    );
    $widget_difference = $this
      ->array_diff_assoc_deep($widget, $instance_info['widget']);
    $this
      ->assertTrue(empty($widget_difference), t('Widget contains all specified settings. Differences (print_r) %differences', array(
      '%differences' => print_r($widget_difference, TRUE),
    )));

    // Test display settings.
    $display = array(
      'default' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(),
        'type' => 'text_default',
      ),
      'paragraphs_editor_preview' => array(
        'label' => 'hidden',
        'module' => 'text',
        'settings' => array(),
        'type' => 'text_default',
      ),
    );
    $display_difference = $this
      ->array_diff_assoc_deep($display, $instance_info['display']);
    $this
      ->assertTrue(empty($display_difference), t('Display contains all specified settings. Differences (print_r) %differences', array(
      '%differences' => print_r($display_difference, TRUE),
    )));
  }
}