public function CouponCodeGeneratorTest::testPatternValidityChecker in Commerce Core 8.2
Tests the validatePattern method.
@covers ::validatePattern
File
- modules/
promotion/ tests/ src/ Kernel/ CouponCodeGeneratorTest.php, line 87
Class
- CouponCodeGeneratorTest
- Tests the coupon code generator.
Namespace
Drupal\Tests\commerce_promotion\KernelCode
public function testPatternValidityChecker() {
// Numeric pattern length 1 is too short for coupon quantity > 10.
$pattern = new CouponCodePattern('numeric', '', '', 1);
$result = $this->couponCodeGenerator
->validatePattern($pattern, 11);
$this
->assertFalse($result);
// Numeric pattern length 1 is long enough for coupon quantity = 10.
$result = $this->couponCodeGenerator
->validatePattern($pattern, 10);
$this
->assertTrue($result);
// Numeric pattern length 1 is long enough for coupon quantity < 10.
$result = $this->couponCodeGenerator
->validatePattern($pattern, 9);
$this
->assertTrue($result);
// Numeric pattern length 8 is long enough for coupon quantity 1000.
$pattern = new CouponCodePattern('numeric', '', '', 8);
$result = $this->couponCodeGenerator
->validatePattern($pattern, 1000);
$this
->assertTrue($result);
}