Unverified Commit 56658f00 authored by alexpott's avatar alexpott

Issue #2809513 by Lendude, brentgees: Convert AJAX part of...

Issue #2809513 by Lendude, brentgees: Convert AJAX part of \Drupal\responsive_image\Tests\ResponsiveImageFieldUiTest to JavascriptTestBase and the rest to BrowserTestBase
parent 819a788e
......@@ -2,25 +2,29 @@
namespace Drupal\responsive_image\Tests;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
/**
* Tests the "Responsive Image" formatter settings form.
* Class ResponsiveImageFieldUiTest.
*
* @group responsive_image
*/
class ResponsiveImageFieldUiTest extends WebTestBase {
use FieldUiTestTrait;
class ResponsiveImageFieldUiTest extends WebDriverTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['node', 'field_ui', 'image', 'responsive_image', 'responsive_image_test_module', 'block'];
public static $modules = [
'node',
'field_ui',
'image',
'responsive_image',
'responsive_image_test_module',
'block',
];
/**
* {@inheritdoc}
......@@ -29,39 +33,67 @@ protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
// Create a test user.
$admin_user = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'bypass node access']);
$admin_user = $this->drupalCreateUser([
'access content',
'administer content types',
'administer node fields',
'administer node form display',
'administer node display',
'bypass node access',
]);
$this->drupalLogin($admin_user);
// Create content type, with underscores.
$type_name = strtolower($this->randomMachineName(8)) . '_test';
$type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]);
$type = $this->drupalCreateContentType([
'name' => $type_name,
'type' => $type_name,
]);
$this->type = $type->id();
}
/**
* Tests formatter settings.
*/
public function testResponsiveImageFormatterUI() {
$manage_fields = 'admin/structure/types/manage/' . $this->type;
$manage_display = $manage_fields . '/display';
public function testResponsiveImageFormatterUi() {
$manage = 'admin/structure/types/manage/' . $this->type;
$add_field = $manage . '/fields/add-field';
$manage_display = $manage . '/display';
$assert_session = $this->assertSession();
// Create a field, and a node with some data for the field.
$this->fieldUIAddNewField($manage_fields, 'image', 'Image field', 'image');
// Display the "Manage display".
// Create the field.
$this->drupalGet($add_field);
$page = $this->getSession()->getPage();
$storage_type = $page->findField('edit-new-storage-type');
$storage_type->setValue('image');
// Set the label.
$label = $page->findField('edit-label');
$label->setValue('Image');
// Wait for the machine name.
$assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');
// Save the current page.
$save_button = $page->findButton('Save and continue');
$save_button->click();
// Display the "Manage display" page.
$this->drupalGet($manage_display);
// Change the formatter and check that the summary is updated.
$edit = [
'fields[field_image][type]' => 'responsive_image',
'fields[field_image][region]' => 'content',
'refresh_rows' => 'field_image',
];
$this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]);
$this->assertText("Select a responsive image style.", 'The expected summary is displayed.');
$page = $this->getSession()->getPage();
$field_image_type = $page->findField('fields[field_image][type]');
$field_image_type->setValue('responsive_image');
// Submit the form.
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText("Select a responsive image style.", 'The expected summary is displayed.');
$summary_text = $assert_session->waitForElement('xpath', $this->cssSelectToXpath('#field-image .ajax-new-content .field-plugin-summary'));
$this->assertEquals('Select a responsive image style.', $summary_text->getText());
$page->pressButton('Save');
$assert_session->responseContains("Select a responsive image style.");
// Create responsive image styles.
$responsive_image_style = ResponsiveImageStyle::create([
......@@ -88,11 +120,15 @@ public function testResponsiveImageFormatterUI() {
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Refresh the page.
$this->drupalGet($manage_display);
$this->assertText("Select a responsive image style.", 'The expected summary is displayed.');
$assert_session->responseContains("Select a responsive image style.");
// Click on the formatter settings button to open the formatter settings
// form.
$this->drupalPostAjaxForm(NULL, [], "field_image_settings_edit");
$field_image_type = $page->findField('fields[field_image][type]');
$field_image_type->setValue('responsive_image');
$page->find('css', '#edit-fields-field-image-settings-edit')->click();
$assert_session->waitForField('fields[field_image][settings_edit_form][settings][responsive_image_style]');
// Assert that the correct fields are present.
$fieldnames = [
......@@ -100,32 +136,25 @@ public function testResponsiveImageFormatterUI() {
'fields[field_image][settings_edit_form][settings][image_link]',
];
foreach ($fieldnames as $fieldname) {
$this->assertField($fieldname);
$assert_session->fieldExists($fieldname);
}
$edit = [
'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");
$page->findField('fields[field_image][settings_edit_form][settings][responsive_image_style]')->setValue('style_one');
$page->findField('fields[field_image][settings_edit_form][settings][image_link]')->setValue('content');
// Save the form to save the settings.
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText('Responsive image style: Style One');
$this->assertText('Linked to content');
$page->pressButton('Save');
// Click on the formatter settings button to open the formatter settings
// form.
$this->drupalPostAjaxForm(NULL, [], "field_image_settings_edit");
$edit = [
'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");
$assert_session->responseContains('Responsive image style: Style One');
$assert_session->responseContains('Linked to content');
$page->find('css', '#edit-fields-field-image-settings-edit')->click();
$assert_session->waitForField('fields[field_image][settings_edit_form][settings][responsive_image_style]');
$page->findField('fields[field_image][settings_edit_form][settings][image_link]')->setValue('file');
// Save the form to save the settings.
$page->pressButton('Save');
// Save the form to save the third party settings.
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText('Responsive image style: Style One');
$this->assertText('Linked to file');
$assert_session->responseContains('Responsive image style: Style One');
$assert_session->responseContains('Linked to file');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment