View source
<?php
namespace Drupal\responsive_image\Tests;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
class ResponsiveImageFieldUiTest extends WebTestBase {
use FieldUiTestTrait;
public static $modules = array(
'node',
'field_ui',
'image',
'responsive_image',
'responsive_image_test_module',
'block',
);
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer content types',
'administer node fields',
'administer node form display',
'administer node display',
'bypass node access',
));
$this
->drupalLogin($admin_user);
$type_name = strtolower($this
->randomMachineName(8)) . '_test';
$type = $this
->drupalCreateContentType(array(
'name' => $type_name,
'type' => $type_name,
));
$this->type = $type
->id();
}
function testResponsiveImageFormatterUI() {
$manage_fields = 'admin/structure/types/manage/' . $this->type;
$manage_display = $manage_fields . '/display';
$this
->fieldUIAddNewField($manage_fields, 'image', 'Image field', 'image');
$this
->drupalGet($manage_display);
$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.');
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText("Select a responsive image style.", 'The expected summary is displayed.');
$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();
$this
->drupalGet($manage_display);
$this
->assertText("Select a responsive image style.", 'The expected summary is displayed.');
$this
->drupalPostAjaxForm(NULL, array(), "field_image_settings_edit");
$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");
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText('Responsive image style: Style One');
$this
->assertText('Linked to content');
$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");
$this
->drupalPostForm(NULL, array(), t('Save'));
$this
->assertText('Responsive image style: Style One');
$this
->assertText('Linked to file');
}
}