Verified Commit 50692daf authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3473999 by mondrake, smustgrave, catch: Ajax-enabled image effect forms...

Issue #3473999 by mondrake, smustgrave, catch: Ajax-enabled image effect forms do not update to the latest ajax processed configuration

(cherry picked from commit 4bfa1e99)
parent cc9bd24b
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -122,7 +122,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->imageEffect->submitConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form, $form_state));

    $this->imageEffect->setWeight($form_state->getValue('weight'));
    if (!$this->imageEffect->getUuid()) {
    if ($uuid = $this->imageEffect->getUuid()) {
      $this->imageStyle->getEffect($uuid)->setConfiguration($this->imageEffect->getConfiguration());
    }
    else {
      $this->imageStyle->addImageEffect($this->imageEffect->getConfiguration());
    }
    $this->imageStyle->save();
+26 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public function testAjaxEnabledEffectForm(): void {
    foreach ($style->getEffects() as $uuid => $effect) {
      $effect_path = $admin_path . '/manage/' . $style_name . '/effects/' . $uuid;
      $this->drupalGet($effect_path);
      $this->assertSession()->fieldValueEquals('data[test_parameter]', '100');
      $page->findField('data[test_parameter]')->setValue(111);
      $ajax_value = $page->find('css', '#ajax-value')->getText();
      $this->assertSame('Ajax value bar', $ajax_value);
@@ -67,7 +68,32 @@ public function testAjaxEnabledEffectForm(): void {
      }));
      $page->pressButton('Update effect');
      $assert->statusMessageContains('The image effect was successfully applied.', 'status');
      $this->drupalGet($effect_path);
      $this->assertSession()->fieldValueEquals('data[test_parameter]', '111');
    }

    // Edit the 1st effect, multiple AJAX calls before updating.
    $style = ImageStyle::load($style_name);
    $uuid = array_values($style->getEffects()->getInstanceIds())[0];
    $this->drupalGet($admin_path . '/manage/' . $style_name . '/effects/' . $uuid);
    $this->assertSession()->fieldValueEquals('data[test_parameter]', '111');
    $field = $page->findField('data[test_parameter]');
    $field->setValue(200);
    $page->pressButton('Ajax refresh');
    $this->assertSession()->assertExpectedAjaxRequest(1);
    $field->setValue(300);
    $page->pressButton('Ajax refresh');
    $this->assertSession()->assertExpectedAjaxRequest(2);
    $field->setValue(400);
    $page->pressButton('Ajax refresh');
    $this->assertSession()->assertExpectedAjaxRequest(3);
    $page->pressButton('Update effect');
    $this->assertSession()->statusMessageContains('The image effect was successfully applied.', 'status');
    $style = ImageStyle::load($style_name);
    $effectConfiguration = $style->getEffect($uuid)->getConfiguration();
    $this->assertSame(400, $effectConfiguration['data']['test_parameter']);
    $this->drupalGet($admin_path . '/manage/' . $style_name . '/effects/' . $uuid);
    $this->assertSession()->fieldValueEquals('data[test_parameter]', '400');
  }

}