Unverified Commit ecadaba6 authored by alexpott's avatar alexpott

Issue #2959466 by vaplas, mondrake: Convert web tests to browser tests for image module (Part 2)

parent b8c09bea
<?php
namespace Drupal\image\Tests;
namespace Drupal\Tests\image\FunctionalJavascript;
use Drupal\image\Entity\ImageStyle;
......@@ -26,12 +26,14 @@ public function testAjaxEnabledEffectForm() {
];
// Add style form.
$edit = [
'name' => $style_name,
'label' => $style_label,
];
$this->drupalPostForm($admin_path . '/add', $edit, t('Create new style'));
$this->assertRaw(t('Style %name was created.', ['%name' => $style_label]));
$page = $this->getSession()->getPage();
$assert = $this->assertSession();
$this->drupalGet($admin_path . '/add');
$page->findField('label')->setValue($style_label);
$assert->waitForElementVisible('named', ['button', 'Edit'])->press();
$assert->waitForElementVisible('named', ['id_or_name', 'name'])->setValue($style_name);
$page->pressButton('Create new style');
$assert->pageTextContains("Style $style_label was created.");
// Add two Ajax-enabled test effects.
$this->drupalPostForm($style_path, ['new' => 'image_module_test_ajax'], t('Add'));
......@@ -46,8 +48,16 @@ public function testAjaxEnabledEffectForm() {
foreach ($style->getEffects() as $uuid => $effect) {
$effect_path = $admin_path . '/manage/' . $style_name . '/effects/' . $uuid;
$this->drupalGet($effect_path);
$this->drupalPostAjaxForm(NULL, $effect_edit, ['op' => t('Ajax refresh')]);
$this->drupalPostForm(NULL, $effect_edit, t('Update effect'));
$page->findField('data[test_parameter]')->setValue(111);
$ajax_value = $page->find('css', '#ajax-value')->getText();
$this->assertSame('Ajax value bar', $ajax_value);
$this->getSession()->getPage()->pressButton('Ajax refresh');
$this->assertTrue($page->waitFor(10, function ($page) {
$ajax_value = $page->find('css', '#ajax-value')->getText();
return preg_match('/^Ajax value [0-9.]+ [0-9.]+$/', $ajax_value);
}));
$page->pressButton('Update effect');
$assert->pageTextContains('The image effect was successfully applied.');
}
}
......
<?php
namespace Drupal\Tests\image\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\Tests\image\Kernel\ImageFieldCreationTrait;
use Drupal\Tests\TestFileCreationTrait;
/**
* This class provides methods specifically for testing Image's field handling.
*/
abstract class ImageFieldTestBase extends JavascriptTestBase {
use ImageFieldCreationTrait;
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'node',
'image',
'field_ui',
'image_module_test',
];
/**
* {@inheritdoc}
*/
protected $minkDefaultDriverClass = DrupalSelenium2Driver::class;
/**
* An user with permissions to administer content types and image styles.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create Basic page and Article node types.
if ($this->profile !== 'standard') {
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}
$this->adminUser = $this->drupalCreateUser([
'access content',
'access administration pages',
'administer site configuration',
'administer content types',
'administer node fields',
'administer nodes',
'create article content',
'edit any article content',
'delete any article content',
'administer image styles',
'administer node display',
]);
$this->drupalLogin($this->adminUser);
}
}
<?php
namespace Drupal\image\Tests;
namespace Drupal\Tests\image\FunctionalJavascript;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
......@@ -23,11 +23,11 @@ public function testAJAXValidationMessage() {
/** @var \Drupal\file\FileInterface[] $text_files */
$text_files = $this->drupalGetTestFiles('text');
$text_file = reset($text_files);
$edit = [
'files[' . $field_name . '_0][]' => $this->container->get('file_system')->realpath($text_file->uri),
'title[0][value]' => $this->randomMachineName(),
];
$this->drupalPostAjaxForm(NULL, $edit, $field_name . '_0_upload_button');
$field = $this->getSession()->getPage()->findField('files[' . $field_name . '_0][]');
$field->attachFile($this->container->get('file_system')->realpath($text_file->uri));
$this->assertSession()->waitForElement('css', '.messages--error');
$elements = $this->xpath('//div[contains(@class, :class)]', [
':class' => 'messages--error',
]);
......@@ -72,10 +72,11 @@ public function testFriendlyAjaxValidation() {
// Open an article and trigger the AJAX handler.
$this->drupalGet('node/add/article');
$edit = [
'field_dummy_select[select_widget]' => 'bam',
];
$this->drupalPostAjaxForm(NULL, $edit, 'field_dummy_select[select_widget]');
$id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
$field = $this->getSession()->getPage()->findField('field_dummy_select[select_widget]');
$field->setValue('bam');
// Make sure that the operation did not end with an exception.
$this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
}
}
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