CouponStorageTest.php in Commerce Core 8.2
File
modules/promotion/tests/src/Kernel/CouponStorageTest.php
View source
<?php
namespace Drupal\Tests\commerce_promotion\Kernel;
use Drupal\commerce_promotion\Entity\Coupon;
use Drupal\Tests\commerce_order\Kernel\OrderKernelTestBase;
class CouponStorageTest extends OrderKernelTestBase {
protected $couponStorage;
public static $modules = [
'commerce_promotion',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('commerce_promotion');
$this
->installEntitySchema('commerce_promotion_coupon');
$this
->installConfig([
'commerce_promotion',
]);
$this
->installSchema('commerce_promotion', [
'commerce_promotion_usage',
]);
$this->couponStorage = $this->container
->get('entity_type.manager')
->getStorage('commerce_promotion_coupon');
}
public function testLoadEnabledByCode() {
$coupon_code = $this
->randomMachineName();
$coupon = Coupon::create([
'code' => $coupon_code,
'status' => TRUE,
]);
$coupon
->save();
$coupon_loaded = $this->couponStorage
->loadEnabledByCode($coupon_code);
$this
->assertEquals($coupon
->id(), $coupon_loaded
->id());
$coupon_code = $this
->randomMachineName();
$coupon = Coupon::create([
'code' => $coupon_code,
'status' => FALSE,
]);
$coupon
->save();
$coupon_loaded = $this->couponStorage
->loadEnabledByCode($coupon_code);
$this
->assertEmpty($coupon_loaded);
}
}