| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Give\Vendors\StellarWP\Validation\Tests\Unit\Rules; |
| 6 |
|
| 7 |
use Give\Vendors\StellarWP\Validation\Rules\Numeric; |
| 8 |
use Give\Vendors\StellarWP\Validation\Tests\TestCase; |
| 9 |
class NumericTest extends TestCase |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @since 1.1.0 |
| 13 |
*/ |
| 14 |
public function testShouldPassWhenValueIsNumeric() |
| 15 |
{ |
| 16 |
$rule = new Numeric(); |
| 17 |
|
| 18 |
self::assertValidationRulePassed($rule, 1); |
| 19 |
self::assertValidationRulePassed($rule, 100.00); |
| 20 |
self::assertValidationRulePassed($rule, '1'); |
| 21 |
self::assertValidationRulePassed($rule, '100.00'); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* @since 1.1.0 |
| 26 |
*/ |
| 27 |
public function testShouldFailWhenValueIsNotNumeric() |
| 28 |
{ |
| 29 |
$rule = new Numeric(); |
| 30 |
|
| 31 |
self::assertValidationRuleFailed($rule, 'abc'); |
| 32 |
self::assertValidationRuleFailed($rule, 'abc123'); |
| 33 |
self::assertValidationRuleFailed($rule, '123abc'); |
| 34 |
self::assertValidationRuleFailed($rule, '123.abc'); |
| 35 |
self::assertValidationRuleFailed($rule, '123.345.56'); |
| 36 |
self::assertValidationRuleFailed($rule, 'abc.123'); |
| 37 |
self::assertValidationRuleFailed($rule, 'abc123.abc'); |
| 38 |
self::assertValidationRuleFailed($rule, 'abc.123abc'); |
| 39 |
self::assertValidationRuleFailed($rule, 'abc123.abc456'); |
| 40 |
} |
| 41 |
} |
| 42 |
|