PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / vendor / vendor-prefixed / stellarwp / validation / tests / unit / Rules / BooleanTest.php

BooleanTest.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at vendor/vendor-prefixed/stellarwp/validation/tests/unit/Rules/BooleanTest.php

63 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace unit\Rules;
4
5 use Give\Vendors\StellarWP\Validation\Rules\Boolean;
6 use Give\Vendors\StellarWP\Validation\Tests\TestCase;
7
8 class BooleanTest extends TestCase
9 {
10 /**
11 * @since 1.4.0
12 *
13 * @dataProvider booleansProvider
14 */
15 public function testRuleValidatesBooleans($value, $pass)
16 {
17 $rule = new Boolean();
18
19 if ($pass) {
20 self::assertValidationRulePassed($rule, $value);
21 } else {
22 self::assertValidationRuleFailed($rule, $value);
23 }
24 }
25
26 /**
27 * @since 1.4.1 updates tests to pass false-y values
28 * @since 1.4.0
29 */
30 public function booleansProvider(): array
31 {
32 return [
33 // values that pass
34 [true, true],
35 [1, true],
36 ['1', true],
37 ['true', true],
38 ['yes', true],
39 ['on', true],
40 [false, true],
41 [0, true],
42 ['0', true],
43 ['false', true],
44 ['no', true],
45 ['off', true],
46
47 // values that fail
48 ['abc', false],
49 ['123', false],
50 ];
51 }
52
53 /**
54 * @since 1.4.0
55 */
56 public function testCastsToBoolean()
57 {
58 $rule = new Boolean();
59 self::assertSame(true, $rule->sanitize('1'));
60 self::assertSame(false, $rule->sanitize('0'));
61 }
62 }
63