forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpRand.php
More file actions
101 lines (95 loc) · 2.1 KB
/
wpRand.php
File metadata and controls
101 lines (95 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* @group pluggable
*
* @covers ::wp_rand
*/
class Tests_Pluggable_wpRand extends WP_UnitTestCase {
/**
* Tests that wp_rand() returns a non-negative integer for both positive and negative input.
*
* @ticket 55194
* @dataProvider data_wp_rand_should_return_a_non_negative_integer
*
* @param int $min Lower limit for the generated number.
* @param int $max Upper limit for the generated number.
*/
public function test_wp_rand_should_return_a_non_negative_integer( $min, $max ) {
$this->assertGreaterThanOrEqual(
0,
wp_rand( $min, $max ),
'The value was not greater than or equal to 0'
);
$this->assertLessThan(
100,
wp_rand( $min, $max ),
'The value was not less than 100'
);
}
/**
* Data provider.
*
* @return array
*/
public function data_wp_rand_should_return_a_non_negative_integer() {
return array(
'1 and 99' => array(
'min' => 1,
'max' => 99,
),
'-1 and 99' => array(
'min' => -1,
'max' => 99,
),
'1 and -99' => array(
'min' => 1,
'max' => -99,
),
'-1 and -99' => array(
'min' => -1,
'max' => -99,
),
'1.0 and 99.0' => array(
'min' => 1.0,
'max' => 99.0,
),
'-1.0 and -99.0' => array(
'min' => -1.0,
'max' => -99.0,
),
);
}
/**
* Tests that wp_rand() returns zero when `$min` and `$max` are zero.
*
* @ticket 55194
* @dataProvider data_wp_rand_should_return_zero_when_min_and_max_are_zero
*
* @param mixed $min Lower limit for the generated number.
* @param mixed $max Upper limit for the generated number.
*/
public function test_wp_rand_should_return_zero_when_min_and_max_are_zero( $min, $max ) {
$this->assertSame( 0, wp_rand( $min, $max ) );
}
/**
* Data provider.
*
* @return array
*/
public function data_wp_rand_should_return_zero_when_min_and_max_are_zero() {
return array(
'min and max as 0' => array(
'min' => 0,
'max' => 0,
),
'min and max as 0.0' => array(
'min' => 0.0,
'max' => 0.0,
),
'min as null, max as 0' => array(
'min' => null,
'max' => 0,
),
);
}
}