-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEdgeCaseTest.php
More file actions
189 lines (133 loc) · 5.44 KB
/
Copy pathEdgeCaseTest.php
File metadata and controls
189 lines (133 loc) · 5.44 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
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
<?php
declare(strict_types=1);
namespace n5s\PageForCustomPostType\Tests\Integration;
use n5s\PageForCustomPostType\Tests\Fixtures\TestCase;
class EdgeCaseTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->createFixtures();
}
public function testPfcptPageWithStaticFrontPage(): void
{
$this->configureStaticFrontPage(true);
$this->get($this->getBookHomeUrl());
$this->assertTrue(is_home());
$this->assertFalse(is_front_page());
$this->assertTrue(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testFrontPageIsNotPfcptPage(): void
{
$this->configureStaticFrontPage(true);
$this->get(home_url('/'));
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testPfcptWithShowOnFrontPosts(): void
{
update_option('show_on_front', 'posts');
delete_option('page_on_front');
delete_option('page_for_posts');
$this->get($this->getBookHomeUrl());
$this->assertTrue(is_home());
$this->assertTrue(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testNestedPageSlug(): void
{
$parentPageId = static::factory()->post->create([
'post_type' => 'page',
'post_title' => 'Parent Page',
'post_name' => 'parent-page',
'post_status' => 'publish',
]);
$childPageId = static::factory()->post->create([
'post_type' => 'page',
'post_title' => 'Nested Book Home',
'post_name' => 'nested-book-home',
'post_status' => 'publish',
'post_parent' => $parentPageId,
]);
update_option('page_for_' . self::BOOK_POST_TYPE, $childPageId);
flush_rewrite_rules();
$url = get_permalink($childPageId);
$this->assertStringContainsString('parent-page', $url);
$this->get($url);
global $wp_query;
$this->assertTrue($wp_query->is_home);
$this->assertTrue(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testPfcptPageContentIsNotInQuery(): void
{
$this->get($this->getBookHomeUrl());
global $wp_query;
$postIds = wp_list_pluck($wp_query->posts, 'ID');
$this->assertNotContains($this->homeForBookId, $postIds);
}
public function testMultiplePfcptPagesWorkIndependently(): void
{
$this->get($this->getBookHomeUrl());
$this->assertTrue(is_home());
$this->assertTrue(\n5s\PageForCustomPostType\is_page_for_custom_post_type(self::BOOK_POST_TYPE));
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type(self::BIKE_POST_TYPE));
$this->get($this->getBikeHomeUrl());
$this->assertTrue(is_home());
$this->assertTrue(\n5s\PageForCustomPostType\is_page_for_custom_post_type(self::BIKE_POST_TYPE));
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type(self::BOOK_POST_TYPE));
}
public function testPfcptPageWithNoPostsPerPage(): void
{
update_option('posts_per_page', 999);
$this->get($this->getBookHomeUrl());
global $wp_query;
$this->assertCount(\count($this->bookIds), $wp_query->posts);
$this->assertSame(1, $wp_query->max_num_pages);
}
public function testRemovingPageAssignmentRestoresNormalBehavior(): void
{
$bookHomeUrl = $this->getBookHomeUrl();
delete_option('page_for_' . self::BOOK_POST_TYPE);
flush_rewrite_rules();
$this->get($bookHomeUrl);
global $wp_query;
$this->assertTrue($wp_query->is_page);
$this->assertFalse($wp_query->is_home);
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testQueriedObjectIsPageNotPosts(): void
{
$this->get($this->getBookHomeUrl());
$queriedObject = get_queried_object();
$this->assertInstanceOf(\WP_Post::class, $queriedObject);
$this->assertSame('page', $queriedObject->post_type);
$this->assertEquals($this->homeForBookId, $queriedObject->ID);
}
public function testUnregisteredCptDoesNotHijackQuery(): void
{
$bookHomeUrl = $this->getBookHomeUrl();
unregister_post_type(self::BOOK_POST_TYPE);
flush_rewrite_rules();
$this->get($bookHomeUrl);
global $wp_query;
$this->assertTrue($wp_query->is_page);
$this->assertFalse($wp_query->is_home);
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
public function testNonEligibleCptDeletesMappingOnRegistration(): void
{
$bookHomeUrl = $this->getBookHomeUrl();
$this->assertNotFalse(get_option('page_for_' . self::BOOK_POST_TYPE));
unregister_post_type(self::BOOK_POST_TYPE);
register_post_type(self::BOOK_POST_TYPE, [
'public' => false,
'publicly_queryable' => false,
'label' => 'Books',
]);
$this->assertFalse(get_option('page_for_' . self::BOOK_POST_TYPE));
flush_rewrite_rules();
$this->get($bookHomeUrl);
global $wp_query;
$this->assertTrue($wp_query->is_page);
$this->assertFalse($wp_query->is_home);
$this->assertFalse(\n5s\PageForCustomPostType\is_page_for_custom_post_type());
}
}