function ResponsiveImageFieldUiTest::testResponsiveImageFormatterUI in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/responsive_image/src/Tests/ResponsiveImageFieldUiTest.php \Drupal\responsive_image\Tests\ResponsiveImageFieldUiTest::testResponsiveImageFormatterUI()
Tests formatter settings.
File
- core/
modules/ responsive_image/ src/ Tests/ ResponsiveImageFieldUiTest.php, line 49 - Contains \Drupal\responsive_image\Tests\ResponsiveImageFieldUiTest.
Class
- ResponsiveImageFieldUiTest
- Tests the "Responsive Image" formatter settings form.
Namespace
Drupal\responsive_image\TestsCode
function testResponsiveImageFormatterUI() {
$manage_fields = 'admin/structure/types/manage/' . $this->type;
$manage_display = $manage_fields . '/display';
// Create a field, and a node with some data for the field.
$this
->fieldUIAddNewField($manage_fields, 'image', 'Image field', 'image');
// Display the "Manage display".
$this
->drupalGet($manage_display);
// Change the formatter and check that the summary is updated.
$edit = array(
'fields[field_image][type]' => 'responsive_image',
'refresh_rows' => 'field_image',
);
$this
->drupalPostAjaxForm(NULL, $edit, array(
'op' => t('Refresh'),
));
$this
->assertText("Select a responsive image style.", 'The expected summary is displayed.');
// Submit the form.
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText("Select a responsive image style.", 'The expected summary is displayed.');
// Create responsive image styles.
$responsive_image_style = entity_create('responsive_image_style', array(
'id' => 'style_one',
'label' => 'Style One',
'breakpoint_group' => 'responsive_image_test_module',
'fallback_image_style' => 'thumbnail',
));
$responsive_image_style
->addImageStyleMapping('responsive_image_test_module.mobile', '1x', array(
'image_mapping_type' => 'image_style',
'image_mapping' => 'thumbnail',
))
->addImageStyleMapping('responsive_image_test_module.narrow', '1x', array(
'image_mapping_type' => 'image_style',
'image_mapping' => 'medium',
))
->addImageStyleMapping('responsive_image_test_module.wide', '1x', array(
'image_mapping_type' => 'image_style',
'image_mapping' => 'large',
))
->save();
\Drupal::entityManager()
->clearCachedFieldDefinitions();
// Refresh the page.
$this
->drupalGet($manage_display);
$this
->assertText("Select a responsive image style.", 'The expected summary is displayed.');
// Click on the formatter settings button to open the formatter settings
// form.
$this
->drupalPostAjaxForm(NULL, array(), "field_image_settings_edit");
// Assert that the correct fields are present.
$fieldnames = array(
'fields[field_image][settings_edit_form][settings][responsive_image_style]',
'fields[field_image][settings_edit_form][settings][image_link]',
);
foreach ($fieldnames as $fieldname) {
$this
->assertField($fieldname);
}
$edit = array(
'fields[field_image][settings_edit_form][settings][responsive_image_style]' => 'style_one',
'fields[field_image][settings_edit_form][settings][image_link]' => 'content',
);
$this
->drupalPostAjaxForm(NULL, $edit, "field_image_plugin_settings_update");
// Save the form to save the settings.
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText('Responsive image style: Style One');
$this
->assertText('Linked to content');
// Click on the formatter settings button to open the formatter settings
// form.
$this
->drupalPostAjaxForm(NULL, array(), "field_image_settings_edit");
$edit = array(
'fields[field_image][settings_edit_form][settings][responsive_image_style]' => 'style_one',
'fields[field_image][settings_edit_form][settings][image_link]' => 'file',
);
$this
->drupalPostAjaxForm(NULL, $edit, "field_image_plugin_settings_update");
// Save the form to save the third party settings.
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText('Responsive image style: Style One');
$this
->assertText('Linked to file');
}