|
7 | 7 | */
|
8 | 8 | class FunctionsTest extends TestCase
|
9 | 9 | {
|
10 |
| - public $tests = array( |
11 |
| - array( |
12 |
| - 'input' => array(), |
13 |
| - 'output' => array(), |
14 |
| - ), |
15 |
| - array( |
16 |
| - 'input' => array( |
17 |
| - 'SOME_FIELD' => 'Some value', |
18 |
| - 'SOME_OTHER_FIELD' => 'Some other value' |
19 |
| - ), |
20 |
| - 'output' => array( |
21 |
| - 'SOME_FIELD' => 'Some value', |
22 |
| - 'SOME_OTHER_FIELD' => 'Some other value' |
23 |
| - ), |
24 |
| - ), |
25 |
| - array( |
26 |
| - 'input' => array( |
27 |
| - 'NAME' => 'Danny van Kooten' |
28 |
| - ), |
29 |
| - 'output' => array( |
30 |
| - 'NAME' => 'Danny van Kooten', |
31 |
| - 'FNAME' => 'Danny', |
32 |
| - 'LNAME' => 'van Kooten' |
33 |
| - ), |
34 |
| - ), |
35 |
| - array( |
36 |
| - 'input' => array( |
37 |
| - 'NAME' => 'Danny' |
38 |
| - ), |
39 |
| - 'output' => array( |
40 |
| - 'NAME' => 'Danny', |
41 |
| - 'FNAME' => 'Danny', |
42 |
| - ), |
43 |
| - ), |
44 |
| - ); |
45 |
| - |
46 |
| - |
47 |
| - /** |
48 |
| - * @covers mc4wp_obfuscate_email_addresses() |
49 |
| - */ |
50 |
| - public function test_mc4wp_obfuscate_email_addresses() |
51 |
| - { |
52 |
| - |
53 |
| - // by no means should the two strings be similar |
54 |
| - $string = 'Mailchimp API error: Recipient "johnnydoe@gmail.com" has too many recent signup requests'; |
55 |
| - $obfuscated = mc4wp_obfuscate_email_addresses($string); |
56 |
| - self::assertNotEquals($string, $obfuscated); |
57 |
| - |
58 |
| - // less than 70% of the string should be similar |
59 |
| - $string = 'johnnydoe@gmail.com'; |
60 |
| - $obfuscated = mc4wp_obfuscate_email_addresses($string); |
61 |
| - similar_text($string, $obfuscated, $percentage); |
62 |
| - self::assertTrue($percentage <= 70); |
63 |
| - } |
64 |
| - |
65 |
| - /** |
66 |
| - * @covers mc4wp_obfuscate_string |
67 |
| - */ |
68 |
| - public function test_mc4wp_obfuscate_string() |
69 |
| - { |
70 |
| - |
71 |
| - // by no means should the two strings be similar |
72 |
| - $string = 'super-secret-string'; |
73 |
| - $obfuscated = mc4wp_obfuscate_string($string); |
74 |
| - self::assertNotEquals($string, $obfuscated); |
75 |
| - |
76 |
| - // less than 50% of the string should be similar |
77 |
| - similar_text($string, $obfuscated, $percentage); |
78 |
| - self::assertTrue($percentage <= 50); |
79 |
| - } |
80 |
| - |
81 |
| - /** |
82 |
| - * @covers mc4wp_add_name_data |
83 |
| - */ |
84 |
| - public function test_mc4wp_add_name_data() |
85 |
| - { |
86 |
| - foreach ($this->tests as $test) { |
87 |
| - self::assertEquals(mc4wp_add_name_data($test['input']), $test['output']); |
88 |
| - } |
89 |
| - } |
90 |
| - |
91 |
| - /** |
92 |
| - * @covers mc4wp_array_get |
93 |
| - */ |
94 |
| - public function test_mc4wp_array_get() |
95 |
| - { |
96 |
| - self::assertEquals(mc4wp_array_get(array( 'foo' => 'bar' ), 'foo'), 'bar'); |
97 |
| - self::assertEquals(mc4wp_array_get(array( 'foo' => 'bar' ), 'foofoo', 'default'), 'default'); |
98 |
| - self::assertEquals(mc4wp_array_get(array( 'foo' => array( 'bar' => 'foobar' ) ), 'foo.bar'), 'foobar'); |
99 |
| - self::assertEquals(mc4wp_array_get(array( 'foo' => array( 'bar' => 'foobar' ) ), 'foo.foo', 'default'), 'default'); |
100 |
| - } |
| 10 | + public $tests = array( |
| 11 | + array( |
| 12 | + 'input' => array(), |
| 13 | + 'output' => array(), |
| 14 | + ), |
| 15 | + array( |
| 16 | + 'input' => array( |
| 17 | + 'SOME_FIELD' => 'Some value', |
| 18 | + 'SOME_OTHER_FIELD' => 'Some other value' |
| 19 | + ), |
| 20 | + 'output' => array( |
| 21 | + 'SOME_FIELD' => 'Some value', |
| 22 | + 'SOME_OTHER_FIELD' => 'Some other value' |
| 23 | + ), |
| 24 | + ), |
| 25 | + array( |
| 26 | + 'input' => array( |
| 27 | + 'NAME' => 'Danny van Kooten' |
| 28 | + ), |
| 29 | + 'output' => array( |
| 30 | + 'NAME' => 'Danny van Kooten', |
| 31 | + 'FNAME' => 'Danny', |
| 32 | + 'LNAME' => 'van Kooten' |
| 33 | + ), |
| 34 | + ), |
| 35 | + array( |
| 36 | + 'input' => array( |
| 37 | + 'NAME' => 'Danny' |
| 38 | + ), |
| 39 | + 'output' => array( |
| 40 | + 'NAME' => 'Danny', |
| 41 | + 'FNAME' => 'Danny', |
| 42 | + ), |
| 43 | + ), |
| 44 | + ); |
| 45 | + |
| 46 | + |
| 47 | + /** |
| 48 | + * @covers mc4wp_obfuscate_email_addresses() |
| 49 | + */ |
| 50 | + public function test_mc4wp_obfuscate_email_addresses() |
| 51 | + { |
| 52 | + // by no means should the two strings be similar |
| 53 | + $string = 'Mailchimp API error: Recipient "johnnydoe@gmail.com" has too many recent signup requests'; |
| 54 | + $obfuscated = mc4wp_obfuscate_email_addresses($string); |
| 55 | + self::assertNotEquals($string, $obfuscated); |
| 56 | + |
| 57 | + // less than 70% of the string should be similar |
| 58 | + $string = 'johnnydoe@gmail.com'; |
| 59 | + $obfuscated = mc4wp_obfuscate_email_addresses($string); |
| 60 | + similar_text($string, $obfuscated, $percentage); |
| 61 | + self::assertTrue($percentage <= 70); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @covers mc4wp_obfuscate_string |
| 66 | + */ |
| 67 | + public function test_mc4wp_obfuscate_string() |
| 68 | + { |
| 69 | + self::assertEquals('', mc4wp_obfuscate_string('')); |
| 70 | + self::assertEquals('a', mc4wp_obfuscate_string('a')); |
| 71 | + self::assertEquals('aa', mc4wp_obfuscate_string('aa')); |
| 72 | + self::assertEquals('a*a', mc4wp_obfuscate_string('aaa')); |
| 73 | + self::assertEquals('a**a', mc4wp_obfuscate_string('aaaa')); |
| 74 | + self::assertEquals('abcd****************************-us1', mc4wp_obfuscate_string('abcdefghijklmnopqrstuvwxyzabcdef-us1')); |
| 75 | + |
| 76 | + // by no means should the two strings be similar |
| 77 | + $string = 'super-secret-string'; |
| 78 | + $obfuscated = mc4wp_obfuscate_string($string); |
| 79 | + self::assertNotEquals($string, $obfuscated); |
| 80 | + |
| 81 | + // less than 50% of the string should be similar |
| 82 | + similar_text($string, $obfuscated, $percentage); |
| 83 | + self::assertTrue($percentage <= 50); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @covers mc4wp_add_name_data |
| 88 | + */ |
| 89 | + public function test_mc4wp_add_name_data() |
| 90 | + { |
| 91 | + foreach ($this->tests as $test) { |
| 92 | + self::assertEquals(mc4wp_add_name_data($test['input']), $test['output']); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @covers mc4wp_array_get |
| 98 | + */ |
| 99 | + public function test_mc4wp_array_get() |
| 100 | + { |
| 101 | + self::assertEquals(mc4wp_array_get(array( 'foo' => 'bar' ), 'foo'), 'bar'); |
| 102 | + self::assertEquals(mc4wp_array_get(array( 'foo' => 'bar' ), 'foofoo', 'default'), 'default'); |
| 103 | + self::assertEquals(mc4wp_array_get(array( 'foo' => array( 'bar' => 'foobar' ) ), 'foo.bar'), 'foobar'); |
| 104 | + self::assertEquals(mc4wp_array_get(array( 'foo' => array( 'bar' => 'foobar' ) ), 'foo.foo', 'default'), 'default'); |
| 105 | + } |
101 | 106 |
|
102 | 107 | public function test_mc4wp_get_request_ip_address()
|
103 | 108 | {
|
|
0 commit comments