protected function CartIntegrationTest::setUp in Commerce Shipping 8.2
Same name in this branch
- 8.2 tests/src/FunctionalJavascript/CartIntegrationTest.php \Drupal\Tests\commerce_shipping\FunctionalJavascript\CartIntegrationTest::setUp()
- 8.2 tests/src/Kernel/CartIntegrationTest.php \Drupal\Tests\commerce_shipping\Kernel\CartIntegrationTest::setUp()
Overrides CommerceWebDriverTestBase::setUp
File
- tests/
src/ FunctionalJavascript/ CartIntegrationTest.php, line 47
Class
- CartIntegrationTest
- Tests integration with the Cart module.
Namespace
Drupal\Tests\commerce_shipping\FunctionalJavascriptCode
protected function setUp() : void {
parent::setUp();
// Limit the available countries.
$this->store->shipping_countries = [
'US',
'FR',
'DE',
];
$this->store
->save();
/** @var \Drupal\commerce_payment\Entity\PaymentGateway $gateway */
$gateway = PaymentGateway::create([
'id' => 'example_onsite',
'label' => 'Example',
'plugin' => 'example_onsite',
]);
$gateway
->getPlugin()
->setConfiguration([
'api_key' => '2342fewfsfs',
'payment_method_types' => [
'credit_card',
],
]);
$gateway
->save();
$product_variation_type = ProductVariationType::load('default');
$product_variation_type
->setTraits([
'purchasable_entity_shippable',
]);
$product_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');
// Create product.
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'price' => [
'number' => '7.99',
'currency_code' => 'USD',
],
'weight' => [
'number' => '20',
'unit' => 'g',
],
]);
/** @var \Drupal\commerce_product\Entity\ProductInterface $product */
$this->firstProduct = $this
->createEntity('commerce_product', [
'type' => 'default',
'title' => 'Conference hat',
'variations' => [
$variation,
],
'stores' => [
$this->store,
],
]);
/** @var \Drupal\commerce_shipping\Entity\PackageType $package_type */
$package_type = $this
->createEntity('commerce_package_type', [
'id' => 'package_type_a',
'label' => 'Package Type A',
'dimensions' => [
'length' => 20,
'width' => 20,
'height' => 20,
'unit' => 'mm',
],
'weight' => [
'number' => 20,
'unit' => 'g',
],
]);
$this->container
->get('plugin.manager.commerce_package_type')
->clearCachedDefinitions();
// Create a flat rate per item shipping method to make testing adjustments
// in items easier.
$this
->createEntity('commerce_shipping_method', [
'name' => 'Flat Rate Per Item',
'stores' => [
$this->store
->id(),
],
'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',
],
],
],
'conditions' => [
[
'target_plugin_id' => 'shipment_weight',
'target_plugin_configuration' => [
'operator' => '<',
'weight' => [
'number' => '120',
'unit' => 'g',
],
],
],
],
]);
$checkout_flow = CheckoutFlow::load('shipping');
$checkout_flow_configuration = $checkout_flow
->get('configuration');
$checkout_flow_configuration['panes']['shipping_information']['auto_recalculate'] = FALSE;
$checkout_flow
->set('configuration', $checkout_flow_configuration);
$checkout_flow
->save();
}