forked from timber/timber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-timber-static.php
143 lines (126 loc) · 4.28 KB
/
test-timber-static.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
<?php
/**
* @group posts-api
*/
class TestTimberStaticPages extends Timber_UnitTestCase
{
public function tear_down()
{
update_option('show_on_front', 'posts');
update_option('page_on_front', '0');
update_option('page_for_posts', '0');
}
public function testPageAsPostsPage()
{
$pids = $this->factory->post->create_many(6);
$page_id = $this->factory->post->create([
'post_type' => 'page',
]);
update_option('page_for_posts', $page_id);
$this->go_to(home_url('/?page_id=' . $page_id));
$page = Timber::get_post();
$this->assertEquals($page_id, $page->ID);
}
public function testPageAsJustAPage()
{
$pids = $this->factory->post->create_many(6);
$page_id = $this->factory->post->create([
'post_title' => 'Foobar',
'post_name' => 'foobar',
'post_type' => 'page',
]);
$this->go_to(home_url('/?page_id=' . $page_id));
$page = Timber::get_post();
$this->assertEquals($page_id, $page->ID);
}
public function testPageAsStaticFront()
{
$pids = $this->factory->post->create_many(6);
$page_id = $this->factory->post->create([
'post_type' => 'page',
]);
update_option('page_on_front', $page_id);
$this->go_to(home_url('/'));
global $wp_query;
$wp_query->queried_object = get_post($page_id);
$page = Timber::get_post();
$this->assertEquals($page_id, $page->ID);
}
public function testFrontPageAsPage()
{
$spaceballs = "What's the matter, Colonel Sandurz? Chicken?";
$page_id = $this->factory->post->create([
'post_title' => 'Spaceballs',
'post_content' => $spaceballs,
'post_type' => 'page',
]);
update_option('show_on_front', 'page');
update_option('page_on_front', $page_id);
$this->go_to(home_url('/'));
$post = Timber::get_post();
$this->assertEquals($page_id, $post->ID);
}
public function testStaticPostPage()
{
$this->clearPosts();
$page_id = $this->factory->post->create([
'post_title' => 'Gobbles',
'post_type' => 'page',
]);
$posts = $this->factory->post->create_many(10, [
'post_title' => 'Timmy',
]);
update_option('show_on_front', 'page');
update_option('page_for_posts', $page_id);
$this->go_to(get_permalink($page_id));
$posts = Timber::get_posts();
$this->assertEquals('Timmy', $posts[0]->title());
}
public function testOtherPostOnStaticPostPage()
{
$page_id = $this->factory->post->create([
'post_title' => 'Gobbles',
'post_type' => 'page',
]);
update_option('page_for_posts', $page_id);
$post_id = $this->factory->post->create([
'post_title' => 'My Real post',
'post_type' => 'post',
]);
$this->go_to(home_url('/?p=' . $page_id));
$post = Timber::get_post($post_id);
$this->assertEquals($post_id, $post->ID);
}
public function testRegularStaticPage()
{
$this->markTestSkipped('@todo what is this testing?');
$page_id = $this->factory->post->create([
'post_title' => 'Mister Slave',
'post_type' => 'page',
]);
$children = $this->factory->post->create_many(10, [
'post_title' => 'Timmy',
]);
$this->go_to(home_url('/?p=' . $page_id));
$posts = Timber::get_posts();
$this->assertCount(0, $posts);
$page = Timber::get_post();
$this->assertEquals($page_id, $page->ID);
}
public function testRegularStaticPageFlipped()
{
$this->markTestSkipped('@todo what is this testing?');
$page_id = $this->factory->post->create([
'post_title' => 'Mister Slave',
'post_type' => 'page',
]);
$children = $this->factory->post->create_many(10, [
'post_title' => 'Timmy',
]);
$this->go_to(home_url('/?p=' . $page_id));
$page = Timber::get_post();
$this->assertEquals($page_id, $page->ID);
$posts = Timber::get_posts();
$this->assertCount(0, $posts);
}
}