public function PromotionSubscriberTest::testSubscriberNoShippingPromotions in Commerce Shipping 8.2
Test that things does not crash when we have no shipping promotions.
File
- tests/
src/ Kernel/ EventSubscriber/ PromotionSubscriberTest.php, line 97
Class
- PromotionSubscriberTest
- Tests the promotion subscriber.
Namespace
Drupal\Tests\commerce_shipping\Kernel\EventSubscriberCode
public function testSubscriberNoShippingPromotions() {
/** @var \Drupal\commerce_shipping\EventSubscriber\PromotionSubscriber $subscriber */
$subscriber = $this->container
->get('commerce_shipping.promotion_subscriber');
$rates = [
new ShippingRate([
'shipping_method_id' => 'test',
'service' => new ShippingService('test', 'Test'),
'amount' => Price::fromArray([
'currency_code' => 'USD',
'number' => 100,
]),
]),
];
$method = $this
->createMock(ShippingMethodInterface::class);
$event = new ShippingRatesEvent($rates, $method, $this->shipment);
// Create a promotion as well.
$promotion = Promotion::create([
'name' => 'Promotion 1',
'order_types' => [
'default',
],
'stores' => [
$this->store
->id(),
],
'status' => TRUE,
'offer' => [
'target_plugin_id' => 'order_item_percentage_off',
'target_plugin_configuration' => [
'percentage' => '0.5',
],
],
]);
$promotion
->save();
// Now run the subscriber.
$subscriber
->onCalculate($event);
$this
->assertEqual(count($event
->getRates()), 1);
}