1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
2
|
|
|
/** |
3
|
|
|
* The SignatureTest class file. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack-connection |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Connection; |
9
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Provides unit tests for the methods in the Jetpack_Signature class. |
14
|
|
|
*/ |
15
|
|
|
class SignatureTest extends TestCase { |
16
|
|
|
/** |
17
|
|
|
* Tests the Jetpack_Signature->join_with_equal_sign() method. |
18
|
|
|
* |
19
|
|
|
* @covers Automattic\Jetpack\Connection\Jetpack_Signature->join_with_equal_sign |
20
|
|
|
* @dataProvider join_with_equal_sign_data_provider |
21
|
|
|
* |
22
|
|
|
* @param string $name Query string key value. |
23
|
|
|
* @param string|array $value Associated value for query string key. |
24
|
|
|
* @param string|array $expected_output The expected output of $signature->join_with_equal_sign. |
25
|
|
|
*/ |
26
|
|
|
public function test_join_with_equal_sign( $name, $value, $expected_output ) { |
27
|
|
|
$signature = new \Jetpack_Signature( 'some-secret', 0 ); |
|
|
|
|
28
|
|
|
$this->assertEquals( $expected_output, $signature->join_with_equal_sign( $name, $value ) ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Data provider for test_join_with_equal_sign. |
33
|
|
|
* |
34
|
|
|
* The test data arrays have the format: |
35
|
|
|
* 'name' => The value that the constant will be set to. Null if the constant will not be set. |
36
|
|
|
* 'value' => The name of the constant. |
37
|
|
|
* 'expected_output' => The expected output of Utils::jetpack_api_constant_filter(). |
38
|
|
|
*/ |
39
|
|
|
public function join_with_equal_sign_data_provider() { |
40
|
|
|
return array( |
41
|
|
|
'string_value' => |
42
|
|
|
array( |
43
|
|
|
'name' => 'street', |
44
|
|
|
'value' => '1600 Pennsylvania Ave', |
45
|
|
|
'expected_output' => 'street=1600 Pennsylvania Ave', |
46
|
|
|
), |
47
|
|
|
'array_value' => |
48
|
|
|
array( |
49
|
|
|
'name' => 'first_names', |
50
|
|
|
'value' => array( 'Michael', 'Jim', 'Pam' ), |
51
|
|
|
'expected_output' => array( 'first_names[0]=Michael', 'first_names[1]=Jim', 'first_names[2]=Pam' ), |
52
|
|
|
), |
53
|
|
|
'nested_array_value' => |
54
|
|
|
array( |
55
|
|
|
'name' => 'numbers', |
56
|
|
|
'value' => array( array( 0, 1 ), array( 2, 3 ), array( 4, 5 ) ), |
57
|
|
|
'expected_output' => array( |
58
|
|
|
'numbers[0][0]=0', |
59
|
|
|
'numbers[0][1]=1', |
60
|
|
|
'numbers[1][0]=2', |
61
|
|
|
'numbers[1][1]=3', |
62
|
|
|
'numbers[2][0]=4', |
63
|
|
|
'numbers[2][1]=5', |
64
|
|
|
), |
65
|
|
|
), |
66
|
|
|
'nested_associative_array_value' => |
67
|
|
|
array( |
68
|
|
|
'name' => 'people', |
69
|
|
|
'value' => array( |
70
|
|
|
array( |
71
|
|
|
'last_name' => 'Scott', |
72
|
|
|
'first_name' => 'Michael', |
73
|
|
|
'city' => 'Boulder', |
74
|
|
|
), |
75
|
|
|
array( |
76
|
|
|
'first_name' => 'Jim', |
77
|
|
|
'state' => 'Texas', |
78
|
|
|
'last_name' => 'Halpert', |
79
|
|
|
), |
80
|
|
|
), |
81
|
|
|
// Note: Expected output is sorted. |
82
|
|
|
'expected_output' => array( |
83
|
|
|
'people[0][city]=Boulder', |
84
|
|
|
'people[0][first_name]=Michael', |
85
|
|
|
'people[0][last_name]=Scott', |
86
|
|
|
'people[1][first_name]=Jim', |
87
|
|
|
'people[1][last_name]=Halpert', |
88
|
|
|
'people[1][state]=Texas', |
89
|
|
|
), |
90
|
|
|
), |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: