public function ParagraphsPackTestCase::testParagraphsPackFieldItemsInstanceCreation in Paragraphs pack 7
Test function for field items instance creation.
File
- tests/
paragraphs_pack.test, line 235 - Paragraphs pack primary module's tests.
Class
- ParagraphsPackTestCase
- Test Case for Paragraphs pack primary module.
Code
public function testParagraphsPackFieldItemsInstanceCreation() {
$field_label = 'Test body';
$target_type = 'node';
// Run tested function.
paragraphs_pack_add_field_items($this->paragraph_bundle_name, $field_label, $target_type);
// Test field instance existence.
$field = paragraphs_pack_get_field_items($target_type);
$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['widget']['type'], 'entityreference_autocomplete');
// Test display settings.
$display = array(
'default' => array(
'label' => 'hidden',
'module' => 'paragraphs_pack',
'settings' => array(
'entity_type' => $target_type,
),
'type' => PP_FORMATTER_VIEW_MODE,
),
'paragraphs_editor_preview' => array(
'label' => 'hidden',
'module' => 'paragraphs_pack',
'settings' => array(
'entity_type' => $target_type,
),
'type' => PP_FORMATTER_VIEW_MODE,
),
);
$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),
)));
}
}