forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-post-content.php
193 lines (154 loc) · 5.19 KB
/
test-timber-post-content.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* @group posts-api
*/
class TestTimberPostContent extends Timber_UnitTestCase
{
public function testContent()
{
$quote = 'The way to do well is to do well.';
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post->post_content = $quote;
wp_update_post($post);
$this->assertEquals($quote, trim(strip_tags($post->content())));
}
public function testContentPaged()
{
$quote = $page1 = 'The way to do well is to do well.';
$quote .= '<!--nextpage-->';
$quote .= $page2 = "And do not let your tongue get ahead of your mind.";
$post_id = $this->factory->post->create();
$post = Timber::get_post($post_id);
$post->post_content = $quote;
wp_update_post($post);
$this->assertEquals($page1, trim(strip_tags($post->content(1))));
$this->assertEquals($page2, trim(strip_tags($post->content(2))));
}
public function testPagedContent()
{
$quote = $page1 = 'Named must your fear be before banish it you can.';
$quote .= '<!--nextpage-->';
$quote .= $page2 = "No, try not. Do or do not. There is no try.";
$post_id = $this->factory->post->create([
'post_content' => $quote,
]);
$this->go_to(get_permalink($post_id));
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$this->assertEquals($page1, trim(strip_tags($post->paged_content())));
$pagination = $post->pagination();
$this->go_to($pagination['pages'][1]['link']);
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$this->assertEquals($page2, trim(strip_tags($post->paged_content())));
}
public function testPagedContentWithBlocks()
{
$paged_content = /** @lang text */
'<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:nextpage -->
<!--nextpage-->
<!-- /wp:nextpage -->
<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->'
;
$post_id = $this->factory->post->create([
'post_title' => 'Paged content',
'post_content' => $paged_content,
'post_type' => 'post',
]);
$this->go_to(get_permalink($post_id));
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$post->setup();
$paged_content = trim(do_blocks(/** @lang text */
'<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->'
));
$this->assertEquals($paged_content, trim($post->paged_content()));
// Go to next page.
$pagination = $post->pagination();
$this->go_to($pagination['pages'][1]['link']);
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$post->setup();
$this->assertEquals($paged_content, trim($post->paged_content()));
}
public function testPagedContentWithBlocksAndNextPageAtBeginning()
{
$paged_content = /** @lang text */
'<!-- wp:nextpage -->
<!--nextpage-->
<!-- /wp:nextpage -->
<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:nextpage -->
<!--nextpage-->
<!-- /wp:nextpage -->
<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->'
;
$post_id = $this->factory->post->create([
'post_title' => 'Paged content',
'post_content' => $paged_content,
'post_type' => 'post',
]);
$this->go_to(get_permalink($post_id));
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$post->setup();
$paged_content = trim(do_blocks(/** @lang text */
'<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>Paged Content</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->'
));
$this->assertEquals($paged_content, trim($post->paged_content()));
// Go to next page.
$pagination = $post->pagination();
$this->go_to($pagination['pages'][1]['link']);
setup_postdata(get_post($post_id));
$post = Timber::get_post();
$post->setup();
$this->assertEquals($paged_content, trim($post->paged_content()));
}
/**
* @ticket 2218
*/
public function testGutenbergExcerptOption()
{
$content_1 = '<!-- wp:paragraph -->
<p>Heres the start to a thing</p>
<!-- /wp:paragraph -->
<!-- wp:more {"noTeaser":true} -->
<!--more-->
<!--noteaser-->
<!-- /wp:more -->
<!-- wp:paragraph -->
<p>Heres the read more stuff that we shant see!</p>
<!-- /wp:paragraph -->';
$post_id = $this->factory->post->create([
'post_content' => $content_1,
]);
$post = Timber::get_post($post_id);
$this->assertEquals('<p>Heres the read more stuff that we shant see!</p>', trim($post->content()));
}
}