forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeDate.php
More file actions
155 lines (124 loc) · 4.06 KB
/
theDate.php
File metadata and controls
155 lines (124 loc) · 4.06 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* @group date
* @group datetime
* @group post
* @covers ::the_date
* @covers ::the_weekday_date
*/
class Tests_Date_TheDate extends WP_UnitTestCase {
/** @var array $hooks_called Count of hooks called. */
protected $hooks_called = array(
'the_time' => 0,
'get_the_time' => 0,
'the_modified_time' => 0,
'get_the_modified_time' => 0,
'the_date' => 0,
'get_the_date' => 0,
'the_modified_date' => 0,
'get_the_modified_date' => 0,
'get_post_time' => 0,
'get_post_modified_time' => 0,
);
public function test_should_call_hooks() {
add_filter( 'the_time', array( $this, 'count_hook' ) );
add_filter( 'get_the_time', array( $this, 'count_hook' ) );
add_filter( 'get_post_time', array( $this, 'count_hook' ) );
add_filter( 'the_modified_time', array( $this, 'count_hook' ) );
add_filter( 'get_the_modified_time', array( $this, 'count_hook' ) );
add_filter( 'get_post_modified_time', array( $this, 'count_hook' ) );
add_filter( 'the_date', array( $this, 'count_hook' ) );
add_filter( 'get_the_date', array( $this, 'count_hook' ) );
add_filter( 'the_modified_date', array( $this, 'count_hook' ) );
add_filter( 'get_the_modified_date', array( $this, 'count_hook' ) );
$post_id = self::factory()->post->create();
global $post, $currentday, $previousday;
$post = get_post( $post_id );
$currentday = 1;
$previousday = 0;
ob_start();
the_time();
get_the_time();
the_modified_time();
get_the_modified_time();
the_date();
get_the_date();
the_modified_date();
get_the_modified_date();
get_post_time();
get_post_modified_time();
ob_end_clean();
$this->assertSame( 1, $this->hooks_called['the_time'] );
$this->assertSame( 2, $this->hooks_called['get_the_time'] );
$this->assertSame( 1, $this->hooks_called['the_modified_time'] );
$this->assertSame( 2, $this->hooks_called['get_the_modified_time'] );
$this->assertSame( 1, $this->hooks_called['the_date'] );
$this->assertSame( 2, $this->hooks_called['get_the_date'] );
$this->assertSame( 1, $this->hooks_called['the_modified_date'] );
$this->assertSame( 2, $this->hooks_called['get_the_modified_date'] );
$this->assertSame( 5, $this->hooks_called['get_post_time'] );
$this->assertSame( 5, $this->hooks_called['get_post_modified_time'] );
}
public function count_hook( $input ) {
$this->hooks_called[ current_filter() ] ++;
return $input;
}
/**
* @ticket 33750
*/
function test_the_date() {
ob_start();
the_date();
$actual = ob_get_clean();
$this->assertSame( '', $actual );
$GLOBALS['post'] = self::factory()->post->create_and_get(
array(
'post_date' => '2015-09-16 08:00:00',
)
);
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousday'] = '17.09.15';
the_date();
$this->assertSame( 'September 16, 2015', ob_get_clean() );
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousday'] = '17.09.15';
the_date( 'Y' );
$this->assertSame( '2015', ob_get_clean() );
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousday'] = '17.09.15';
the_date( 'Y', 'before ', ' after' );
$this->assertSame( 'before 2015 after', ob_get_clean() );
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousday'] = '17.09.15';
the_date( 'Y', 'before ', ' after', false );
$this->assertSame( '', ob_get_clean() );
}
/**
* @ticket 47354
*/
function test_the_weekday_date() {
ob_start();
the_weekday_date();
$actual = ob_get_clean();
$this->assertSame( '', $actual );
$GLOBALS['post'] = self::factory()->post->create_and_get(
array(
'post_date' => '2015-09-16 08:00:00',
)
);
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousweekday'] = '17.09.15';
the_weekday_date();
$this->assertSame( 'Wednesday', ob_get_clean() );
ob_start();
$GLOBALS['currentday'] = '18.09.15';
$GLOBALS['previousweekday'] = '17.09.15';
the_weekday_date( 'before ', ' after' );
$this->assertSame( 'before Wednesday after', ob_get_clean() );
}
}