diff --git a/tests/src/FunctionalJavascript/RecalculateAnonymousShipping.php b/tests/src/FunctionalJavascript/RecalculateAnonymousShipping.php new file mode 100644 --- /dev/null (revision 6fd57af97ed2c4abe1ed12bbf7accc3d101948cb) +++ b/tests/src/FunctionalJavascript/RecalculateAnonymousShipping.php (revision 6fd57af97ed2c4abe1ed12bbf7accc3d101948cb) @@ -0,0 +1,194 @@ + 'US', + 'administrative_area' => 'SC', + 'locality' => 'Greenville', + 'postal_code' => '29616', + 'address_line1' => '9 Drupal Ave', + 'given_name' => 'Bryan', + 'family_name' => 'Centarro', + ]; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'commerce_cart', + 'commerce_payment', + 'commerce_payment_example', + 'commerce_shipping_test', + ]; + + /** + * {@inheritdoc} + */ + protected function getAdministratorPermissions() { + return array_merge([ + 'administer commerce_shipment', + ], parent::getAdministratorPermissions()); + } + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + + $this->store->set('billing_countries', ['US']); + $this->store->save(); + + $variation_type = ProductVariationType::load('default'); + $variation_type->setTraits(['purchasable_entity_shippable']); + $variation_type->save(); + + $order_type = OrderType::load('default'); + $order_type->setThirdPartySetting('commerce_checkout', 'checkout_flow', 'shipping'); + $order_type->setThirdPartySetting('commerce_shipping', 'shipment_type', 'default'); + $order_type->save(); + + // Create the order field. + $field_definition = commerce_shipping_build_shipment_field_definition($order_type->id()); + $this->container->get('commerce.configurable_field_manager') + ->createField($field_definition); + + // Install the variation trait. + $trait_manager = $this->container->get('plugin.manager.commerce_entity_trait'); + $trait = $trait_manager->createInstance('purchasable_entity_shippable'); + $trait_manager->installTrait($trait, 'commerce_product_variation', 'default'); + + /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $paymentGateway */ + $paymentGateway = $this->createEntity('commerce_payment_gateway', [ + 'id' => 'manual', + 'label' => 'Manual example', + 'plugin' => 'manual', + ]); + $paymentGateway->setPluginConfiguration([ + 'display_label' => 'Cash on delivery', + 'instructions' => [ + 'value' => 'Test instructions.', + 'format' => 'plain_text', + ], + ]); + $paymentGateway->save(); + + /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $variation */ + $variation = $this->createEntity('commerce_product_variation', [ + 'type' => 'default', + 'sku' => strtolower($this->randomMachineName()), + 'price' => [ + 'number' => '8.99', + 'currency_code' => 'USD', + ], + ]); + + /** @var \Drupal\commerce_product\Entity\ProductInterface $product */ + $product = $this->createEntity('commerce_product', [ + 'type' => 'default', + 'title' => 'Conference ticket', + 'variations' => [$variation], + 'stores' => [$this->store], + ]); + + $this->createEntity('commerce_order_item_type', [ + 'id' => 'test', + 'label' => 'Test', + 'orderType' => 'default', + ]); + + $order_item = $this->createEntity('commerce_order_item', [ + 'type' => 'test', + 'quantity' => 1, + 'unit_price' => new Price('10', 'USD'), + 'purchased_entity' => $product->getDefaultVariation(), + ]); + + $this->createEntity('commerce_shipment_type', [ + 'id' => 'test', + 'label' => 'Test', + 'profileType' => 'customer', + ]); + + $default_profile = $this->createEntity('profile', [ + 'type' => 'customer', + 'uid' => $this->adminUser->id(), + 'address' => $this->defaultAddress, + ]); + + $this->order = $this->createEntity('commerce_order', [ + 'uid' => 0, + 'type' => 'default', + 'state' => 'completed', + 'order_items' => [$order_item], + 'store_id' => $this->store, + ]); + + $this->shipment = $this->createEntity('commerce_shipment', [ + 'type' => 'default', + 'title' => 'Test shipment', + 'order_id' => $this->order->id(), + 'amount' => new Price('10', 'USD'), + 'items' => [ + new ShipmentItem([ + 'order_item_id' => $order_item->id(), + 'title' => 'Test shipment item label', + 'quantity' => 1, + 'weight' => new Weight(0, 'g'), + 'declared_value' => new Price('1', 'USD'), + ]), + ], + 'shipping_profile' => $default_profile, + ]); + } + + /** + * Tests recalculating anonymous shipping by admin. + */ + public function testRecalculateAnonymousShipping(): void { + $path = '/admin/commerce/orders/' . $this->order->id() . '/shipments/' . $this->shipment->id() . '/edit'; + $this->drupalGet($path); + + $this->assertRenderedAddress($this->defaultAddress); + + $this->getSession()->getPage()->findButton('Recalculate shipping')->click(); + $this->assertSession()->assertWaitOnAjaxRequest(); + + $this->assertRenderedAddress($this->defaultAddress); + } + +}