forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPosts.php
More file actions
128 lines (110 loc) · 2.86 KB
/
getPosts.php
File metadata and controls
128 lines (110 loc) · 2.86 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
<?php
/**
* @group post
* @group query
*/
class Tests_Post_GetPosts extends WP_UnitTestCase {
public function test_offset_should_be_null_by_default() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$found = get_posts( array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
) );
$this->assertSame( array( $p1 ), $found );
}
public function test_offset_0_should_be_respected() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$found = get_posts( array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
'offset' => 0,
) );
$this->assertSame( array( $p1 ), $found );
}
public function test_offset_non_0_should_be_respected() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$found = get_posts( array(
'numberposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
'offset' => 1,
) );
$this->assertSame( array( $p2 ), $found );
}
/**
* @ticket 34060
*/
public function test_paged_should_not_be_overridden_by_default_offset() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$found = get_posts( array(
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
'paged' => 2,
'posts_per_page' => 1,
) );
$this->assertSame( array( $p2 ), $found );
}
public function test_explicit_offset_0_should_override_paged() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$found = get_posts( array(
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
'paged' => 2,
'posts_per_page' => 1,
'offset' => 0,
) );
$this->assertSame( array( $p1 ), $found );
}
public function test_explicit_offset_non_0_should_override_paged() {
$p1 = self::factory()->post->create( array(
'post_date' => '2015-04-04 04:04:04',
) );
$p2 = self::factory()->post->create( array(
'post_date' => '2014-04-04 04:04:04',
) );
$p3 = self::factory()->post->create( array(
'post_date' => '2013-04-04 04:04:04',
) );
$found = get_posts( array(
'orderby' => 'date',
'order' => 'DESC',
'fields' => 'ids',
'paged' => 2,
'posts_per_page' => 1,
'offset' => 2,
) );
$this->assertSame( array( $p3 ), $found );
}
}