annotate core/modules/image/tests/src/FunctionalJavascript/ImageAdminStylesTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents c2387f117808
children
rev   line source
Chris@16 1 <?php
Chris@16 2
Chris@16 3 namespace Drupal\Tests\image\FunctionalJavascript;
Chris@16 4
Chris@16 5 use Drupal\image\Entity\ImageStyle;
Chris@16 6
Chris@16 7 /**
Chris@16 8 * Tests creation, deletion, and editing of image styles and effects.
Chris@16 9 *
Chris@16 10 * @group image
Chris@16 11 */
Chris@16 12 class ImageAdminStylesTest extends ImageFieldTestBase {
Chris@16 13
Chris@16 14 /**
Chris@16 15 * Tests editing Ajax-enabled image effect forms.
Chris@16 16 */
Chris@16 17 public function testAjaxEnabledEffectForm() {
Chris@16 18 $admin_path = 'admin/config/media/image-styles';
Chris@16 19
Chris@16 20 // Setup a style to be created and effects to add to it.
Chris@16 21 $style_name = strtolower($this->randomMachineName(10));
Chris@16 22 $style_label = $this->randomString();
Chris@16 23 $style_path = $admin_path . '/manage/' . $style_name;
Chris@16 24 $effect_edit = [
Chris@16 25 'data[test_parameter]' => 100,
Chris@16 26 ];
Chris@16 27
Chris@16 28 // Add style form.
Chris@16 29 $page = $this->getSession()->getPage();
Chris@16 30 $assert = $this->assertSession();
Chris@16 31 $this->drupalGet($admin_path . '/add');
Chris@16 32 $page->findField('label')->setValue($style_label);
Chris@16 33 $assert->waitForElementVisible('named', ['button', 'Edit'])->press();
Chris@16 34 $assert->waitForElementVisible('named', ['id_or_name', 'name'])->setValue($style_name);
Chris@16 35 $page->pressButton('Create new style');
Chris@16 36 $assert->pageTextContains("Style $style_label was created.");
Chris@16 37
Chris@16 38 // Add two Ajax-enabled test effects.
Chris@16 39 $this->drupalPostForm($style_path, ['new' => 'image_module_test_ajax'], t('Add'));
Chris@16 40 $this->drupalPostForm(NULL, $effect_edit, t('Add effect'));
Chris@16 41 $this->drupalPostForm($style_path, ['new' => 'image_module_test_ajax'], t('Add'));
Chris@16 42 $this->drupalPostForm(NULL, $effect_edit, t('Add effect'));
Chris@16 43
Chris@16 44 // Load the saved image style.
Chris@16 45 $style = ImageStyle::load($style_name);
Chris@16 46
Chris@16 47 // Edit back the effects.
Chris@16 48 foreach ($style->getEffects() as $uuid => $effect) {
Chris@16 49 $effect_path = $admin_path . '/manage/' . $style_name . '/effects/' . $uuid;
Chris@16 50 $this->drupalGet($effect_path);
Chris@16 51 $page->findField('data[test_parameter]')->setValue(111);
Chris@16 52 $ajax_value = $page->find('css', '#ajax-value')->getText();
Chris@16 53 $this->assertSame('Ajax value bar', $ajax_value);
Chris@16 54 $this->getSession()->getPage()->pressButton('Ajax refresh');
Chris@16 55 $this->assertTrue($page->waitFor(10, function ($page) {
Chris@16 56 $ajax_value = $page->find('css', '#ajax-value')->getText();
Chris@16 57 return preg_match('/^Ajax value [0-9.]+ [0-9.]+$/', $ajax_value);
Chris@16 58 }));
Chris@16 59 $page->pressButton('Update effect');
Chris@16 60 $assert->pageTextContains('The image effect was successfully applied.');
Chris@16 61 }
Chris@16 62 }
Chris@16 63
Chris@16 64 }