forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCronArray.php
More file actions
120 lines (112 loc) · 2.65 KB
/
getCronArray.php
File metadata and controls
120 lines (112 loc) · 2.65 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Test the `_get_cron_array()` function.
*
* @group cron
* @covers ::_get_cron_array
*/
class Tests_Cron_getCronArray extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
// Make sure the schedule is clear.
_set_cron_array( array() );
}
public function tear_down() {
// Make sure the schedule is clear.
_set_cron_array( array() );
parent::tear_down();
}
/**
* Tests the output validation for the `_get_cron_array()` function when the option is unset.
*
* @ticket 53940
*/
public function test_get_cron_array_output_validation_with_no_option() {
delete_option( 'cron' );
$crons = _get_cron_array();
$this->assertIsArray( $crons, 'Cron jobs is not an array.' );
$this->assertCount( 0, $crons, 'Cron job does not contain the expected number of entries.' );
}
/**
* Tests the output validation for the `_get_cron_array()` function.
*
* @ticket 53940
*
* @dataProvider data_get_cron_array_output_validation
*
* @param mixed $input Cron "array".
* @param int $expected Expected array entry count of the cron option after update.
*/
public function test_get_cron_array_output_validation( $input, $expected ) {
update_option( 'cron', $input );
$crons = _get_cron_array();
$this->assertIsArray( $crons, 'Cron jobs is not an array.' );
$this->assertCount( $expected, $crons, 'Cron job does not contain the expected number of entries.' );
}
/**
* Data provider.
*
* @return array
*/
public function data_get_cron_array_output_validation() {
return array(
'stdClass' => array(
'input' => new stdClass(),
'expected' => 0,
),
'null' => array(
'input' => null,
'expected' => 0,
),
'false' => array(
'input' => false,
'expected' => 0,
),
'true' => array(
'input' => true,
'expected' => 0,
),
'integer' => array(
'input' => 53940,
'expected' => 0,
),
'float' => array(
'input' => 539.40,
'expected' => 0,
),
'string' => array(
'input' => 'ticket 53940',
'expected' => 0,
),
'empty array' => array(
'input' => array(),
'expected' => 0,
),
'cron array' => array(
'input' => array(
'version' => 2,
time() => array(
'hookname' => array(
'event key' => array(
'schedule' => 'schedule',
'args' => 'args',
'interval' => 'interval',
),
),
),
),
'expected' => 1,
),
'cron v1' => array(
'input' => array(
time() => array(
'hookname' => array(
'args' => 'args',
),
),
),
'expected' => 1,
),
);
}
}