ImageAdminStylesTest.php in Drupal 9
File
core/modules/image/tests/src/FunctionalJavascript/ImageAdminStylesTest.php
View source
<?php
namespace Drupal\Tests\image\FunctionalJavascript;
use Drupal\image\Entity\ImageStyle;
class ImageAdminStylesTest extends ImageFieldTestBase {
protected $defaultTheme = 'stark';
public function testAjaxEnabledEffectForm() {
$admin_path = 'admin/config/media/image-styles';
$style_name = strtolower($this
->randomMachineName(10));
$style_label = $this
->randomString();
$style_path = $admin_path . '/manage/' . $style_name;
$effect_edit = [
'data[test_parameter]' => 100,
];
$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.");
$this
->drupalGet($style_path);
$this
->submitForm([
'new' => 'image_module_test_ajax',
], 'Add');
$this
->submitForm($effect_edit, 'Add effect');
$this
->drupalGet($style_path);
$this
->submitForm([
'new' => 'image_module_test_ajax',
], 'Add');
$this
->submitForm($effect_edit, 'Add effect');
$style = ImageStyle::load($style_name);
foreach ($style
->getEffects() as $uuid => $effect) {
$effect_path = $admin_path . '/manage/' . $style_name . '/effects/' . $uuid;
$this
->drupalGet($effect_path);
$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 (bool) preg_match('/^Ajax value [0-9.]+ [0-9.]+$/', $ajax_value);
}));
$page
->pressButton('Update effect');
$assert
->pageTextContains('The image effect was successfully applied.');
}
}
}