protected function CouponRedemptionPaneTest::setUp in Commerce Core 8.2
Overrides CommerceWebDriverTestBase::setUp
File
- modules/
promotion/ tests/ src/ FunctionalJavascript/ CouponRedemptionPaneTest.php, line 59
Class
- CouponRedemptionPaneTest
- Tests the coupon redemption checkout pane.
Namespace
Drupal\Tests\commerce_promotion\FunctionalJavascriptCode
protected function setUp() : void {
parent::setUp();
$this->cart = $this->container
->get('commerce_cart.cart_provider')
->createCart('default', $this->store, $this->adminUser);
$this->cartManager = $this->container
->get('commerce_cart.cart_manager');
OrderItemType::create([
'id' => 'test',
'label' => 'Test',
'orderType' => 'default',
])
->save();
$order_item = OrderItem::create([
'type' => 'test',
'quantity' => 1,
'unit_price' => new Price('999.00', 'USD'),
]);
$order_item
->save();
$this->cartManager
->addOrderItem($this->cart, $order_item);
// Starts now, enabled. No end time.
$this->promotion = $this
->createEntity('commerce_promotion', [
'name' => 'Promotion (with coupon)',
'order_types' => [
'default',
],
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.10',
],
],
'start_date' => '2017-01-01',
'conditions' => [],
]);
$coupon = $this
->createEntity('commerce_promotion_coupon', [
'code' => $this
->getRandomGenerator()
->word(8),
'status' => TRUE,
]);
$coupon
->save();
$this->promotion
->addCoupon($coupon);
$this->promotion
->save();
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $offsite_gateway */
$offsite_gateway = PaymentGateway::create([
'id' => 'offsite',
'label' => 'Off-site',
'plugin' => 'example_offsite_redirect',
'configuration' => [
'redirect_method' => 'post',
'payment_method_types' => [
'credit_card',
],
],
]);
$offsite_gateway
->save();
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $onsite_gateway */
$onsite_gateway = PaymentGateway::create([
'id' => 'onsite',
'label' => 'On-site',
'plugin' => 'example_onsite',
'configuration' => [
'api_key' => '2342fewfsfs',
'payment_method_types' => [
'credit_card',
],
],
]);
$onsite_gateway
->save();
$profile = $this
->createEntity('profile', [
'type' => 'customer',
'address' => [
'country_code' => 'US',
'postal_code' => '53177',
'locality' => 'Milwaukee',
'address_line1' => 'Pabst Blue Ribbon Dr',
'administrative_area' => 'WI',
'given_name' => 'Frederick',
'family_name' => 'Pabst',
],
'uid' => $this->adminUser
->id(),
]);
$payment_method1 = $this
->createEntity('commerce_payment_method', [
'uid' => $this->adminUser
->id(),
'type' => 'credit_card',
'payment_gateway' => 'onsite',
'card_type' => 'visa',
'card_number' => '1111',
'billing_profile' => $profile,
'reusable' => TRUE,
'expires' => strtotime('2028/03/24'),
]);
$payment_method1
->setBillingProfile($profile);
$payment_method1
->save();
$payment_method2 = $this
->createEntity('commerce_payment_method', [
'type' => 'credit_card',
'payment_gateway' => 'onsite',
'card_type' => 'visa',
'card_number' => '9999',
'billing_profile' => $profile,
'reusable' => TRUE,
'expires' => strtotime('2028/03/24'),
]);
$payment_method2
->setBillingProfile($profile);
$payment_method2
->save();
}