diff -u b/modules/order/tests/src/Functional/OrderAdminTest.php b/modules/order/tests/src/Functional/OrderAdminTest.php --- b/modules/order/tests/src/Functional/OrderAdminTest.php +++ b/modules/order/tests/src/Functional/OrderAdminTest.php @@ -62,10 +62,6 @@ $this->assertSession()->buttonExists('Create order item'); $entity = $this->variation->getSku() . ' (' . $this->variation->id() . ')'; - // Test that commerce_order_test_field_widget_form_alter() has the expected - // outcome. - $this->assertSame([], \Drupal::state()->get("commerce_order_test_field_widget_form_alter")); - $checkbox = $this->getSession()->getPage()->findField('Override the unit price'); if ($checkbox) { $checkbox->check(); @@ -105,6 +101,10 @@ // Use an adjustment that is not locked by default. $this->clickLink('Edit'); + $this->click('#edit-adjustments-add-more'); + // Test that commerce_order_test_field_widget_form_alter() has the expected + // outcome. + $this->assertSame([], \Drupal::state()->get("commerce_order_test_field_widget_form_alter")); $this->getSession()->getPage()->fillField('edit-adjustments-0-type', 'fee'); $this->click('#edit-adjustments-add-more'); @@ -114,7 +114,7 @@ ]; $this->submitForm($edit, 'Save'); - $this->assertSession()->pageTextContains('The adjustment label field is required.'); + $this->assertSession()->pageTextContains('Label field is required.'); $edit['adjustments[0][definition][label]'] = 'Test fee'; $this->submitForm($edit, 'Save'); $this->assertSession()->pageTextContains('The order has been successfully saved.'); @@ -160,8 +160,11 @@ $this->drupalGet($order->toUrl('edit-form')); $this->assertSession()->fieldValueEquals('adjustments[0][definition][label]', '10% off'); $this->assertSession()->fieldValueEquals('adjustments[1][definition][label]', 'Handling fee'); - $this->assertSession()->optionExists('adjustments[2][type]', 'Custom'); - $this->assertSession()->optionNotExists('adjustments[2][type]', 'Test order adjustment type'); + $this->assertSession()->optionExists('adjustments[1][type]', 'Custom'); + $this->assertSession()->optionNotExists('adjustments[1][type]', 'Test order adjustment type'); + $this->click('input[name="adjustments_0_remove_button"]'); + $this->assertSession()->fieldValueEquals('adjustments[0][definition][label]', 'Handling fee'); + $this->assertSession()->fieldNotExists('adjustments[1][definition][label]'); } /** diff -u b/modules/order/tests/src/FunctionalJavascript/AdjustmentTest.php b/modules/order/tests/src/FunctionalJavascript/AdjustmentTest.php --- b/modules/order/tests/src/FunctionalJavascript/AdjustmentTest.php +++ b/modules/order/tests/src/FunctionalJavascript/AdjustmentTest.php @@ -65,6 +65,8 @@ $this->click('#edit-order-items-form-inline-entity-form-actions-ief-add-save'); $this->assertSession()->assertWaitOnAjaxRequest(); + $this->click('input[name="adjustments_add_more"]'); + $this->assertSession()->waitForField('adjustments[0][type]'); $this->getSession()->getPage()->fillField('adjustments[0][type]', 'fee'); $this->assertSession()->waitForField('adjustments[0][definition][label]'); $this->assertSession()->fieldExists('adjustments[0][definition][amount][number]'); @@ -72,7 +74,7 @@ $this->getSession()->getPage()->fillField('adjustments[0][definition][label]', 'Test adjustment 1'); $this->getSession()->getPage()->fillField('adjustments[0][definition][amount][number]', '1.32'); - $this->click('#edit-adjustments-add-more'); + $this->click('input[name="adjustments_add_more"]'); $this->assertSession()->waitForField('adjustments[1][type]'); $this->assertSession()->fieldValueEquals('adjustments[0][definition][label]', 'Test adjustment 1'); $this->assertSession()->fieldValueEquals('adjustments[0][definition][amount][number]', '1.32'); @@ -99,17 +101,52 @@ $this->assertEquals(new Price('1.31', 'USD'), $order->getTotalPrice()); $this->assertCount(2, $order->getAdjustments()); - // Test removing an adjustment. + // Test removing an adjustment by selecting '_none'. $this->clickLink('Edit'); $this->getSession()->getPage()->fillField('adjustments[1][type]', '_none'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->assertSession()->fieldNotExists('adjustments[1][definition][label]'); - $this->submitForm([], 'Save'); \Drupal::entityTypeManager()->getStorage('commerce_order')->resetCache([1]); $order = Order::load(1); $this->assertEquals(new Price('11.31', 'USD'), $order->getTotalPrice()); $this->assertCount(1, $order->getAdjustments()); + + // Add two more adjustments + $this->clickLink('Edit'); + $this->click('input[name="adjustments_add_more"]'); + $this->assertSession()->waitForField('adjustments[1][type]'); + $this->getSession()->getPage()->fillField('adjustments[1][type]', 'custom'); + $this->assertSession()->waitForField('adjustments[1][definition][label]'); + $this->getSession()->getPage()->fillField('adjustments[1][definition][label]', 'Test adjustment 2'); + $this->getSession()->getPage()->fillField('adjustments[1][definition][amount][number]', '-5.00'); + $this->click('input[name="adjustments_add_more"]'); + $this->assertSession()->waitForField('adjustments[2][type]'); + $this->getSession()->getPage()->fillField('adjustments[2][type]', 'custom'); + $this->assertSession()->waitForField('adjustments[2][definition][label]'); + $this->getSession()->getPage()->fillField('adjustments[2][definition][label]', 'Test adjustment 3'); + $this->getSession()->getPage()->fillField('adjustments[2][definition][amount][number]', '-4.00'); + $this->submitForm([], 'Save'); + \Drupal::entityTypeManager()->getStorage('commerce_order')->resetCache([1]); + $order = Order::load(1); + $this->assertEquals(new Price('2.31', 'USD'), $order->getTotalPrice()); + $this->assertCount(3, $order->getAdjustments()); + + // Test clicking the remove button. + $this->clickLink('Edit'); + $this->assertSession()->fieldValueEquals('adjustments[1][definition][label]', 'Test adjustment 2'); + $this->assertSession()->fieldValueEquals('adjustments[1][definition][amount][number]', '-5.00'); + $this->assertSession()->fieldExists('adjustments[2][definition][label]'); + $this->click('input[name="adjustments_1_remove_button"]'); + $this->waitForAjaxToFinish(); + $this->assertSession()->fieldValueEquals('adjustments[1][definition][label]', 'Test adjustment 3'); + $this->assertSession()->fieldValueEquals('adjustments[1][definition][amount][number]', '-4.00'); + $this->assertSession()->fieldNotExists('adjustments[2][definition][label]'); + $this->submitForm([], 'Save'); + \Drupal::entityTypeManager()->getStorage('commerce_order')->resetCache([1]); + $order = Order::load(1); + $this->assertEquals(new Price('7.31', 'USD'), $order->getTotalPrice()); + $this->assertCount(2, $order->getAdjustments()); } }