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 / InTest.php

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

77 lines 1.8 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 InvalidArgumentException;
6 use Give\Vendors\StellarWP\Validation\Rules\In;
7 use Give\Vendors\StellarWP\Validation\Tests\TestCase;
8
9 class InTest extends TestCase
10 {
11 /**
12 * @since 1.2.0
13 */
14 public function testShouldAllowEquivalentValuesInArray()
15 {
16 $rule = new In('foo', 1);
17
18 $this->assertValidationRulePassed($rule, 'foo');
19 $this->assertValidationRulePassed($rule, 1);
20 $this->assertValidationRulePassed($rule, '1');
21 }
22
23 /**
24 * @since 1.2.0
25 */
26 public function testShouldFailValuesNotInArray()
27 {
28 $rule = new In('foo', 1);
29
30 $this->assertValidationRuleFailed($rule, 'bar');
31 $this->assertValidationRuleFailed($rule, 2);
32 $this->assertValidationRuleFailed($rule, false);
33 }
34
35 /**
36 * @since 1.2.0
37 */
38 public function testShouldCreateRuleFromCommaDelimitedList()
39 {
40 $rule = In::fromString('foo,1');
41
42 $this->assertValidationRulePassed($rule, 'foo');
43 $this->assertValidationRulePassed($rule, 1);
44 $this->assertValidationRulePassed($rule, '1');
45 $this->assertValidationRuleFailed($rule, 'qux');
46 }
47
48 /**
49 * @since 1.2.0
50 */
51 public function testFromStringShouldRequireValues()
52 {
53 $this->expectException(InvalidArgumentException::class);
54
55 In::fromString('');
56 }
57
58 /**
59 * @since 1.2.0
60 */
61 public function testShouldThrowInvalidExceptionWithoutValues()
62 {
63 $this->expectException(InvalidArgumentException::class);
64
65 new In();
66 }
67
68 /**
69 * @since 1.2.0
70 */
71 public function testSerializeOptionShouldRetunValuesArray()
72 {
73 $rule = new In('foo', 'bar', 'baz');
74 $this->assertEquals(['foo', 'bar', 'baz'], $rule->serializeOption());
75 }
76 }
77