Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
"font face install",
"font family",
"font family install",
"icon",
"icon collection",
"icon collection get",
"icon collection is-registered",
"icon collection list",
"icon get",
"icon is-registered",
"icon list",
"icon render",
"menu",
"menu create",
"menu delete",
Expand Down
11 changes: 11 additions & 0 deletions entity-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@
WP_CLI::add_command( 'font collection', 'Font_Collection_Command', $wpcli_entity_font_version_check );
WP_CLI::add_command( 'font family', 'Font_Family_Command', $wpcli_entity_font_version_check );
WP_CLI::add_command( 'font face', 'Font_Face_Command', $wpcli_entity_font_version_check );

$wpcli_entity_icon_version_check = array(
'before_invoke' => function () {
if ( Utils\wp_version_compare( '7.1', '<' ) ) {
WP_CLI::error( 'Requires WordPress 7.1 or greater.' );
}
},
);

WP_CLI::add_command( 'icon', 'Icon_Command', $wpcli_entity_icon_version_check );
WP_CLI::add_command( 'icon collection', 'Icon_Collection_Command', $wpcli_entity_icon_version_check );
110 changes: 110 additions & 0 deletions features/icon-collection.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Feature: Manage WordPress icon collections

Background:
Given a WP install

@require-wp-7.1
Scenario: Listing icon collections
When I run `wp icon collection list --fields=slug,label,description`
Then STDOUT should be a table containing rows:
| slug | label | description |
| core | WordPress | Default icon collection. |

@require-wp-7.1
Scenario: Listing icon collections in other formats
When I run `wp icon collection list --format=ids`
Then STDOUT should contain:
"""
core
"""

When I run `wp icon collection list --fields=slug,label --format=json`
Then STDOUT should be JSON containing:
"""
[{"slug":"core","label":"WordPress"}]
"""

When I run `wp icon collection list --format=count`
Then STDOUT should be a number

@require-wp-7.1
Scenario: Getting an icon collection
When I run `wp icon collection get core --fields=slug,label,description`
Then STDOUT should be a table containing rows:
| Field | Value |
| slug | core |
| label | WordPress |
| description | Default icon collection. |

When I run `wp icon collection get core --field=label`
Then STDOUT should be:
"""
WordPress
"""

@require-wp-7.1
Scenario: Counting the icons of a collection
When I run `wp icon collection get core --field=count`
Then STDOUT should be a number

@require-wp-7.1
Scenario: Getting a non-existent icon collection
When I try `wp icon collection get nonexistent-collection`
Then the return code should be 1
And STDERR should contain:
"""
doesn't exist
"""

@require-wp-7.1
Scenario: Checking whether an icon collection is registered
When I try `wp icon collection is-registered nonexistent-collection`
Then the return code should be 1

When I run `wp icon collection is-registered core`
Then the return code should be 0

@require-wp-7.1
Scenario: Listing a collection registered by a plugin
Given a wp-content/mu-plugins/test-icons.php file:
"""
<?php
// Plugin Name: Test Icons
add_action(
'init',
function () {
wp_register_icon_collection(
'test-icons',
array(
'label' => 'Test Icons',
'description' => 'A collection for testing.',
)
);

wp_register_icon(
'test-icons/square',
array(
'label' => 'Square',
'content' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 4h16v16H4z" /></svg>',
)
);
}
);
"""

When I run `wp icon collection list --fields=slug,label,description,count`
Then STDOUT should be a table containing rows:
| slug | label | description | count |
| test-icons | Test Icons | A collection for testing. | 1 |

When I run `wp icon collection is-registered test-icons`
Then the return code should be 0

@less-than-wp-7.1
Scenario: Icon collection commands fail on WordPress < 7.1
When I try `wp icon collection list`
Then the return code should be 1
And STDERR should contain:
"""
Requires WordPress 7.1 or greater
"""
205 changes: 205 additions & 0 deletions features/icon.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
Feature: Manage WordPress SVG icons

Background:
Given a WP install

@require-wp-7.1
Scenario: Listing icons
When I run `wp icon list --collection=core --format=count`
Then STDOUT should be a number

When I run `wp icon list --search=arrow-down --field=name`
Then STDOUT should contain:
"""
core/arrow-down
"""

When I run `wp icon list --format=ids`
Then STDOUT should contain:
"""
core/plus
"""

@require-wp-7.1
Scenario: Listing icons matches names and labels
When I run `wp icon list --search="Arrow Down" --fields=name,label,collection`
Then STDOUT should be a table containing rows:
| name | label | collection |
| core/arrow-down | Arrow Down | core |

@require-wp-7.1
Scenario: Listing icons of a non-existent collection
When I try `wp icon list --collection=nonexistent-collection`
Then the return code should be 1
And STDERR should contain:
"""
doesn't exist
"""

@require-wp-7.1
Scenario: Getting an icon
When I run `wp icon get core/plus --fields=name,label,collection`
Then STDOUT should be a table containing rows:
| Field | Value |
| name | core/plus |
| label | Plus |
| collection | core |

When I run `wp icon get core/plus --field=content`
Then STDOUT should contain:
"""
<svg
"""

When I run `wp icon get core/plus --field=file_path`
Then STDOUT should contain:
"""
wp-includes/images/icon-library/plus.svg
"""

@require-wp-7.1
Scenario: Getting a non-existent icon
When I try `wp icon get core/nonexistent-icon`
Then the return code should be 1
And STDERR should contain:
"""
doesn't exist
"""

@require-wp-7.1
Scenario: Checking whether an icon is registered
When I try `wp icon is-registered core/nonexistent-icon`
Then the return code should be 1

When I run `wp icon is-registered core/plus`
Then the return code should be 0

@require-wp-7.1
Scenario: Rendering an icon
When I run `wp icon render core/plus`
Then STDOUT should contain:
"""
width="24"
"""
And STDOUT should contain:
"""
height="24"
"""
And STDOUT should contain:
"""
aria-hidden="true"
"""

@require-wp-7.1
Scenario: Rendering an icon with a size, class and label
When I run `wp icon render core/plus --size=48 --class=my-icon --label="Add item"`
Then STDOUT should contain:
"""
width="48"
"""
And STDOUT should contain:
"""
class="my-icon"
"""
And STDOUT should contain:
"""
role="img"
"""
And STDOUT should contain:
"""
aria-label="Add item"
"""
And STDOUT should not contain:
"""
aria-hidden
"""

@require-wp-7.1
Scenario: Rendering an icon at its intrinsic size
When I run `wp icon render core/plus --size=none`
Then STDOUT should contain:
"""
<svg
"""
And STDOUT should not contain:
"""
width=
"""

@require-wp-7.1
Scenario: Rendering an icon with an invalid size
When I try `wp icon render core/plus --size=huge`
Then the return code should be 1
And STDERR should contain:
"""
The --size argument must be a positive integer or "none".
"""

@require-wp-7.1
Scenario: Rendering a non-existent icon
When I try `wp icon render core/nonexistent-icon`
Then the return code should be 1
And STDERR should contain:
"""
doesn't exist
"""

@require-wp-7.1
Scenario: Managing icons registered by a plugin
Given a wp-content/mu-plugins/test-icons.php file:
"""
<?php
// Plugin Name: Test Icons
add_action(
'init',
function () {
wp_register_icon_collection(
'test-icons',
array(
'label' => 'Test Icons',
'description' => 'A collection for testing.',
)
);

wp_register_icon(
'test-icons/square',
array(
'label' => 'Square',
'content' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 4h16v16H4z" /></svg>',
)
);
}
);
"""

When I run `wp icon list --collection=test-icons --fields=name,label,collection`
Then STDOUT should be a table containing rows:
| name | label | collection |
| test-icons/square | Square | test-icons |

When I run `wp icon get test-icons/square --field=content`
Then STDOUT should contain:
"""
M4 4h16v16H4z
"""

When I run `wp icon get test-icons/square --field=file_path`
Then STDOUT should not contain:
"""
.svg
"""

When I run `wp icon render test-icons/square --size=16`
Then STDOUT should contain:
"""
width="16"
"""

@less-than-wp-7.1
Scenario: Icon commands fail on WordPress < 7.1
When I try `wp icon list`
Then the return code should be 1
And STDERR should contain:
"""
Requires WordPress 7.1 or greater
"""
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<exclude-pattern>*/src/Comment(_Meta)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Font(_Collection|_Face|_Family)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Font_Namespace\.php$</exclude-pattern>
<exclude-pattern>*/src/Icon(_Collection)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Menu(_Item|_Location)?_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Network_Meta_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/Network_Namespace\.php$</exclude-pattern>
Expand Down
Loading