forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneratePostdata.php
More file actions
145 lines (124 loc) · 3.31 KB
/
generatePostdata.php
File metadata and controls
145 lines (124 loc) · 3.31 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
<?php
/**
* @group query
* @covers ::generate_postdata
*/
class Tests_Query_GeneratePostdata extends WP_UnitTestCase {
/**
* @ticket 42814
*/
public function test_setup_by_id() {
$p = self::factory()->post->create_and_get();
$data = generate_postdata( $p->ID );
$this->assertSame( $p->ID, $data['id'] );
}
/**
* @ticket 42814
*/
public function test_setup_by_fake_post() {
$fake = new stdClass();
$fake->ID = 98765;
$data = generate_postdata( $fake->ID );
// Fails because there's no post with this ID.
$this->assertFalse( $data );
}
/**
* @ticket 42814
*/
public function test_setup_by_postish_object() {
$p = self::factory()->post->create();
$post = new stdClass();
$post->ID = $p;
$data = generate_postdata( $p );
$this->assertSame( $p, $data['id'] );
}
/**
* @ticket 42814
*/
public function test_authordata() {
$u = self::factory()->user->create_and_get();
$p = self::factory()->post->create_and_get(
array(
'post_author' => $u->ID,
)
);
$data = generate_postdata( $p );
$this->assertNotEmpty( $data['authordata'] );
$this->assertEquals( $u, $data['authordata'] );
}
/**
* @ticket 42814
*/
public function test_currentday() {
$p = self::factory()->post->create_and_get(
array(
'post_date' => '1980-09-09 06:30:00',
)
);
$data = generate_postdata( $p );
$this->assertSame( '09.09.80', $data['currentday'] );
}
public function test_currentmonth() {
$p = self::factory()->post->create_and_get(
array(
'post_date' => '1980-09-09 06:30:00',
)
);
$data = generate_postdata( $p );
$this->assertSame( '09', $data['currentmonth'] );
}
/**
* @ticket 42814
*/
public function test_single_page() {
$post = self::factory()->post->create_and_get(
array(
'post_content' => 'Page 0',
)
);
$data = generate_postdata( $post );
$this->assertSame( 0, $data['multipage'] );
$this->assertSame( 1, $data['numpages'] );
$this->assertSame( array( 'Page 0' ), $data['pages'] );
}
/**
* @ticket 42814
*/
public function test_multi_page() {
$post = self::factory()->post->create_and_get(
array(
'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
)
);
$data = generate_postdata( $post );
$this->assertSame( 1, $data['multipage'] );
$this->assertSame( 4, $data['numpages'] );
$this->assertSame( array( 'Page 0', 'Page 1', 'Page 2', 'Page 3' ), $data['pages'] );
}
/**
* @ticket 42814
*/
public function test_nextpage_at_start_of_content() {
$post = self::factory()->post->create_and_get(
array(
'post_content' => '<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
)
);
$data = generate_postdata( $post );
$this->assertSame( 1, $data['multipage'] );
$this->assertSame( 3, $data['numpages'] );
$this->assertSame( array( 'Page 1', 'Page 2', 'Page 3' ), $data['pages'] );
}
/**
* @ticket 42814
*/
public function test_trim_nextpage_linebreaks() {
$post = self::factory()->post->create_and_get(
array(
'post_content' => "Page 0\n<!--nextpage-->\nPage 1\nhas a line break\n<!--nextpage-->Page 2<!--nextpage-->\n\nPage 3",
)
);
$data = generate_postdata( $post );
$this->assertSame( array( 'Page 0', "Page 1\nhas a line break", 'Page 2', "\nPage 3" ), $data['pages'] );
}
}