Skip to content

Commit cef762d

Browse files
Copilotswissspidy
andauthored
Add font library commands for WordPress 6.5+ (#567)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 946cea3 commit cef762d

10 files changed

+952
-0
lines changed

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
"comment unspam",
6464
"comment untrash",
6565
"comment update",
66+
"font",
67+
"font collection",
68+
"font collection get",
69+
"font collection is-registered",
70+
"font collection list",
71+
"font collection list-categories",
72+
"font collection list-families",
73+
"font face",
74+
"font face install",
75+
"font family",
76+
"font family install",
6677
"menu",
6778
"menu create",
6879
"menu delete",

entity-command.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,19 @@
113113
},
114114
)
115115
);
116+
117+
if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) {
118+
WP_CLI::add_command( 'font', 'Font_Namespace' );
119+
}
120+
121+
$wpcli_entity_font_version_check = array(
122+
'before_invoke' => function () {
123+
if ( Utils\wp_version_compare( '6.5', '<' ) ) {
124+
WP_CLI::error( 'Requires WordPress 6.5 or greater.' );
125+
}
126+
},
127+
);
128+
129+
WP_CLI::add_command( 'font collection', 'Font_Collection_Command', $wpcli_entity_font_version_check );
130+
WP_CLI::add_command( 'font family', 'Font_Family_Command', $wpcli_entity_font_version_check );
131+
WP_CLI::add_command( 'font face', 'Font_Face_Command', $wpcli_entity_font_version_check );

features/font-collection.feature

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Feature: Manage WordPress font collections
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-6.5
7+
Scenario: Listing font collections
8+
When I try `wp font collection list`
9+
Then STDOUT should be a table containing rows:
10+
| slug | name | description | categories |
11+
| google-fonts | Google Fonts | Install from Google Fonts. Fonts are copied to and served from your site. | Sans Serif (sans-serif), Display (display), Serif (serif), Handwriting (handwriting), Monospace (monospace) |
12+
13+
@require-wp-6.5
14+
Scenario: Getting a non-existent font collection
15+
When I try `wp font collection get nonexistent-collection`
16+
Then the return code should be 1
17+
And STDERR should contain:
18+
"""
19+
doesn't exist
20+
"""
21+
22+
@require-wp-6.5
23+
Scenario: Checking whether a font collection is registered
24+
When I try `wp font collection is-registered nonexistent-collection`
25+
Then the return code should be 1
26+
27+
When I run `wp font collection is-registered google-fonts`
28+
Then the return code should be 0
29+
30+
@require-wp-6.5
31+
Scenario: Listing font families in a collection
32+
When I run `wp font collection list-families google-fonts --format=count`
33+
Then STDOUT should be a number
34+
35+
@require-wp-6.5
36+
Scenario: Listing font families in a collection with fields
37+
When I run `wp font collection list-families google-fonts --fields=slug,name --format=csv`
38+
Then STDOUT should contain:
39+
"""
40+
slug,name
41+
"""
42+
43+
@require-wp-6.5
44+
Scenario: Filtering font families by category
45+
When I run `wp font collection list-families google-fonts --category=sans-serif --format=count`
46+
Then STDOUT should be a number
47+
48+
@require-wp-6.5
49+
Scenario: Listing categories in a collection
50+
When I run `wp font collection list-categories google-fonts --format=csv`
51+
Then STDOUT should contain:
52+
"""
53+
slug,name
54+
"""
55+
56+
@require-wp-6.5
57+
Scenario: Getting a non-existent collection for list-families
58+
When I try `wp font collection list-families nonexistent-collection`
59+
Then the return code should be 1
60+
And STDERR should contain:
61+
"""
62+
doesn't exist
63+
"""
64+
65+
@require-wp-6.5
66+
Scenario: Getting a non-existent collection for list-categories
67+
When I try `wp font collection list-categories nonexistent-collection`
68+
Then the return code should be 1
69+
And STDERR should contain:
70+
"""
71+
doesn't exist
72+
"""
73+
74+
@less-than-wp-6.5
75+
Scenario: Font collection commands fail on WordPress < 6.5
76+
Given a WP install
77+
When I try `wp font collection list`
78+
Then the return code should be 1
79+
And STDERR should contain:
80+
"""
81+
Requires WordPress 6.5 or greater
82+
"""

features/font-face.feature

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Feature: Manage WordPress font faces
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-6.5
7+
Scenario: Installing a font face
8+
Given I run `wp post create --post_type=wp_font_family --post_title="Test Family" --post_status=publish --porcelain`
9+
And save STDOUT as {FONT_FAMILY_ID}
10+
11+
When I run `wp font face install {FONT_FAMILY_ID} --src="https://example.com/font.woff2" --porcelain`
12+
Then STDOUT should be a number
13+
And save STDOUT as {FONT_FACE_ID}
14+
15+
When I run `wp post get {FONT_FACE_ID} --field=post_parent`
16+
Then STDOUT should be:
17+
"""
18+
{FONT_FAMILY_ID}
19+
"""
20+
21+
@require-wp-6.5
22+
Scenario: Installing a font face with custom properties
23+
Given I run `wp post create --post_type=wp_font_family --post_title="Test Family" --post_status=publish --porcelain`
24+
And save STDOUT as {FONT_FAMILY_ID}
25+
26+
When I run `wp font face install {FONT_FAMILY_ID} --src="font.woff2" --font-weight=700 --font-style=italic --porcelain`
27+
Then STDOUT should be a number
28+
And save STDOUT as {FONT_FACE_ID}
29+
30+
When I run `wp post get {FONT_FACE_ID} --field=post_title`
31+
Then STDOUT should contain:
32+
"""
33+
700
34+
"""
35+
And STDOUT should contain:
36+
"""
37+
italic
38+
"""
39+
40+
@require-wp-6.5
41+
Scenario: Installing a font face with invalid parent
42+
When I try `wp font face install 999999 --src="font.woff2"`
43+
Then the return code should be 1
44+
And STDERR should contain:
45+
"""
46+
doesn't exist
47+
"""
48+
49+
@require-wp-6.5
50+
Scenario: Installing a font face without required src parameter
51+
Given I run `wp post create --post_type=wp_font_family --post_title="Test Family" --post_status=publish --porcelain`
52+
And save STDOUT as {FONT_FAMILY_ID}
53+
54+
When I try `wp font face install {FONT_FAMILY_ID}`
55+
Then the return code should be 1
56+
And STDERR should contain:
57+
"""
58+
missing --src parameter
59+
"""
60+
61+
@less-than-wp-6.5
62+
Scenario: Font face install commands fail on WordPress < 6.5
63+
When I try `wp font face install 1 --src=test.woff2`
64+
Then the return code should be 1
65+
And STDERR should contain:
66+
"""
67+
Requires WordPress 6.5 or greater
68+
"""

features/font-family.feature

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Feature: Manage WordPress font families
2+
3+
Background:
4+
Given a WP install
5+
6+
@require-wp-6.5
7+
Scenario: Installing a font family from a collection
8+
When I run `wp font family install google-fonts "roboto" --porcelain`
9+
Then STDOUT should be a number
10+
And save STDOUT as {FONT_FAMILY_ID}
11+
12+
When I run `wp post get {FONT_FAMILY_ID} --field=post_title`
13+
Then STDOUT should contain:
14+
"""
15+
Roboto
16+
"""
17+
18+
When I run `wp post list --post_type=wp_font_face --post_parent={FONT_FAMILY_ID} --format=count`
19+
Then STDOUT should be a number
20+
21+
@require-wp-6.5
22+
Scenario: Installing a font family from a non-existent collection
23+
When I try `wp font family install nonexistent-collection roboto`
24+
Then the return code should be 1
25+
And STDERR should contain:
26+
"""
27+
doesn't exist
28+
"""
29+
30+
@require-wp-6.5
31+
Scenario: Installing a non-existent font family from a collection
32+
When I try `wp font family install google-fonts nonexistent-family`
33+
Then the return code should be 1
34+
And STDERR should contain:
35+
"""
36+
not found
37+
"""
38+
39+
@less-than-wp-6.5
40+
Scenario: Font family install commands fail on WordPress < 6.5
41+
When I try `wp font family install google-fonts roboto`
42+
Then the return code should be 1
43+
And STDERR should contain:
44+
"""
45+
Requires WordPress 6.5 or greater
46+
"""

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
6262
<exclude-pattern>*/src/Taxonomy_Command\.php$</exclude-pattern>
6363
<exclude-pattern>*/src/Comment(_Meta)?_Command\.php$</exclude-pattern>
64+
<exclude-pattern>*/src/Font(_Collection|_Face|_Family)?_Command\.php$</exclude-pattern>
65+
<exclude-pattern>*/src/Font_Namespace\.php$</exclude-pattern>
6466
<exclude-pattern>*/src/Menu(_Item|_Location)?_Command\.php$</exclude-pattern>
6567
<exclude-pattern>*/src/Network_Meta_Command\.php$</exclude-pattern>
6668
<exclude-pattern>*/src/Network_Namespace\.php$</exclude-pattern>

0 commit comments

Comments
 (0)