-
Notifications
You must be signed in to change notification settings - Fork 13
/
rewrite.feature
142 lines (120 loc) · 4.77 KB
/
rewrite.feature
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
Feature: Manage WordPress rewrites
Scenario: Change site permastructs
Given a WP install
When I run `wp rewrite structure /blog/%year%/%monthnum%/%day%/%postname%/ --category-base=section --tag-base=topic`
And I run `wp option get permalink_structure`
Then STDOUT should contain:
"""
/blog/%year%/%monthnum%/%day%/%postname%/
"""
When I run `wp option get category_base`
Then STDOUT should contain:
"""
section
"""
When I run `wp option get tag_base`
Then STDOUT should contain:
"""
topic
"""
When I run `wp rewrite list --format=csv`
Then STDOUT should be CSV containing:
| match | query | source |
| blog/[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$ | index.php?attachment=$matches[1]&tb=1 | post |
| topic/([^/]+)/?$ | index.php?tag=$matches[1] | post_tag |
| section/(.+?)/?$ | index.php?category_name=$matches[1] | category |
When I run `wp rewrite list --match=/topic/apple/ --format=csv --fields=match,query`
Then STDOUT should be CSV containing:
| match | query |
| topic/([^/]+)/?$ | index.php?tag=$matches[1] |
And STDOUT should not contain:
"""
source
"""
Scenario: Missing permalink_structure
Given a WP install
When I run `wp option delete permalink_structure`
And I try `wp option get permalink_structure`
Then STDOUT should be empty
When I try `wp rewrite flush`
Then STDERR should contain:
"""
Warning: Rewrite rules are empty, possibly because of a missing permalink_structure option.
"""
And STDOUT should be empty
When I run `wp rewrite structure /%year%/%monthnum%/%day%/%postname%/`
Then I run `wp rewrite flush`
Then STDOUT should be:
"""
Success: Rewrite rules flushed.
"""
Scenario: Generate .htaccess on hard flush with a project config
Given a WP install
And a wp-cli.yml file:
"""
apache_modules: [mod_rewrite]
"""
When I run `wp rewrite structure /%year%/%monthnum%/%day%/%postname%/ --hard`
Then the .htaccess file should exist
And the return code should be 0
And STDERR should be empty
Scenario: Error when trying to generate .htaccess on a multisite install
Given a WP multisite install
And a wp-cli.yml file:
"""
apache_modules: [mod_rewrite]
"""
When I try `wp rewrite flush --hard`
Then STDERR should be:
"""
Warning: WordPress can't generate .htaccess file for a multisite install.
"""
And STDOUT should be:
"""
Success: Rewrite rules flushed.
"""
And the return code should be 0
When I try `wp rewrite structure /%year%/%monthnum%/%day%/%postname%/ --hard`
Then STDERR should contain:
"""
Warning: WordPress can't generate .htaccess file for a multisite install.
"""
And STDOUT should be:
"""
Success: Rewrite structure set.
Success: Rewrite rules flushed.
"""
And the return code should be 0
Scenario: Warn the user when --skip-plugins or --skip-themes is used
Given a WP install
When I try `wp --skip-plugins rewrite flush`
Then STDERR should contain:
"""
Warning: Some rewrite rules may be missing because plugins weren't loaded.
"""
And the return code should be 0
When I try `wp --skip-plugins --skip-themes rewrite flush`
Then STDERR should contain:
"""
Warning: Some rewrite rules may be missing because plugins and themes weren't loaded.
"""
And the return code should be 0
When I try `wp rewrite flush`
Then STDERR should not contain:
"""
Warning: Some rewrite rules may be missing
"""
And the return code should be 0
Scenario: Match as expected when full URL is provided
Given a WP install
And I run `wp rewrite structure /%year%/%monthnum%/%day%/%postname%/`
When I run `wp rewrite list --match=/2022/11/13/hello-world/ --format=csv --fields=query,source`
Then STDOUT should be CSV containing:
| query | source |
| index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5] | post |
| index.php?pagename=$matches[1]&page=$matches[2] | page |
When I run `wp rewrite list --match=https://example.com/2022/11/13/hello-world/ --format=csv --fields=query,source`
Then STDOUT should be CSV containing:
| query | source |
| index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5] | post |
| index.php?pagename=$matches[1]&page=$matches[2] | page |