diff --git a/tests/src/FunctionalJavascript/CheckoutPaneTest.php b/tests/src/FunctionalJavascript/CheckoutPaneTest.php index 7837751..eeaa5e4 100644 --- a/tests/src/FunctionalJavascript/CheckoutPaneTest.php +++ b/tests/src/FunctionalJavascript/CheckoutPaneTest.php @@ -446,6 +446,81 @@ class CheckoutPaneTest extends CommerceWebDriverTestBase { } /** + * Test for Flat Rate Per Item shipping cost updates. + * + * @covers \Drupal\commerce_shipping\EventSubscriber\OrderItemSubscriber + */ + public function testRecalculatePerItem() { + $page = $this->getSession()->getPage(); + + $this->createEntity('commerce_shipping_method', [ + 'name' => 'Flat Rate Per Item', + 'stores' => [$this->store->id()], + // Ensures this method is first in list and checked by default. + 'weight' => -20, + 'plugin' => [ + 'target_plugin_id' => 'flat_rate_per_item', + 'target_plugin_configuration' => [ + 'rate_label' => 'Flat Rate Per Item', + 'rate_amount' => [ + 'number' => '10.00', + 'currency_code' => 'USD', + ], + ], + ], + ]); + // Add product to order and calculate shipping. + $this->drupalGet($this->firstProduct->toUrl()->toString()); + $this->submitForm([], 'Add to cart'); + $this->drupalGet('checkout/1'); + $address = [ + 'given_name' => 'John', + 'family_name' => 'Smith', + 'address_line1' => '1098 Alta Ave', + 'locality' => 'Mountain View', + 'administrative_area' => 'CA', + 'postal_code' => '94043', + ]; + $address_prefix = 'shipping_information[shipping_profile][address][0][address]'; + $page->fillField($address_prefix . '[country_code]', 'US'); + $this->waitForAjaxToFinish(); + foreach ($address as $property => $value) { + $page->fillField($address_prefix . '[' . $property . ']', $value); + } + $page->findButton('Recalculate shipping')->click(); + $this->waitForAjaxToFinish(); + $this->submitForm([ + 'payment_information[add_payment_method][payment_details][number]' => '4111111111111111', + 'payment_information[add_payment_method][payment_details][expiration][month]' => '02', + 'payment_information[add_payment_method][payment_details][expiration][year]' => '2020', + 'payment_information[add_payment_method][payment_details][security_code]' => '123', + 'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'Johnny', + 'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Appleseed', + 'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '123 New York Drive', + 'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'New York City', + 'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'NY', + 'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '10001', + ], 'Continue to review'); + $this->assertSession()->pageTextContains('Shipping $10.00'); + + // Test whether the shipping amount gets updated. + $this->drupalGet('/cart'); + $page->fillField('edit_quantity[0]', 5); + $page->findButton('Update cart')->click(); + $this->assertSession()->pageTextContains('Shipping $50.00'); + + $this->drupalGet('checkout/1'); + $this->assertSession()->pageTextContains('Shipping $50.00'); + + $page->findButton('Recalculate shipping')->click(); + $this->waitForAjaxToFinish(); + $this->assertSession()->pageTextContains('Shipping $50.00'); + + $page->findButton('Continue to review')->click(); + $this->assertSession()->pageTextContains('Shipping $50.00'); + } + + /** * Asserts that a select field has all of the provided options. * * Core only has assertOption(), this helper decreases the number of needed