|
| 1 | +Feature: Manage WordPress SVG icons |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a WP install |
| 5 | + |
| 6 | + @require-wp-7.1 |
| 7 | + Scenario: Listing icons |
| 8 | + When I run `wp icon list --collection=core --format=count` |
| 9 | + Then STDOUT should be a number |
| 10 | + |
| 11 | + When I run `wp icon list --search=arrow-down --field=name` |
| 12 | + Then STDOUT should contain: |
| 13 | + """ |
| 14 | + core/arrow-down |
| 15 | + """ |
| 16 | + |
| 17 | + When I run `wp icon list --format=ids` |
| 18 | + Then STDOUT should contain: |
| 19 | + """ |
| 20 | + core/plus |
| 21 | + """ |
| 22 | + |
| 23 | + @require-wp-7.1 |
| 24 | + Scenario: Listing icons matches names and labels |
| 25 | + When I run `wp icon list --search="Arrow Down" --fields=name,label,collection` |
| 26 | + Then STDOUT should be a table containing rows: |
| 27 | + | name | label | collection | |
| 28 | + | core/arrow-down | Arrow Down | core | |
| 29 | + |
| 30 | + @require-wp-7.1 |
| 31 | + Scenario: Listing icons of a non-existent collection |
| 32 | + When I try `wp icon list --collection=nonexistent-collection` |
| 33 | + Then the return code should be 1 |
| 34 | + And STDERR should contain: |
| 35 | + """ |
| 36 | + doesn't exist |
| 37 | + """ |
| 38 | + |
| 39 | + @require-wp-7.1 |
| 40 | + Scenario: Getting an icon |
| 41 | + When I run `wp icon get core/plus --fields=name,label,collection` |
| 42 | + Then STDOUT should be a table containing rows: |
| 43 | + | Field | Value | |
| 44 | + | name | core/plus | |
| 45 | + | label | Plus | |
| 46 | + | collection | core | |
| 47 | + |
| 48 | + When I run `wp icon get core/plus --field=content` |
| 49 | + Then STDOUT should contain: |
| 50 | + """ |
| 51 | + <svg |
| 52 | + """ |
| 53 | + |
| 54 | + When I run `wp icon get core/plus --field=file_path` |
| 55 | + Then STDOUT should contain: |
| 56 | + """ |
| 57 | + wp-includes/images/icon-library/plus.svg |
| 58 | + """ |
| 59 | + |
| 60 | + @require-wp-7.1 |
| 61 | + Scenario: Getting a non-existent icon |
| 62 | + When I try `wp icon get core/nonexistent-icon` |
| 63 | + Then the return code should be 1 |
| 64 | + And STDERR should contain: |
| 65 | + """ |
| 66 | + doesn't exist |
| 67 | + """ |
| 68 | + |
| 69 | + @require-wp-7.1 |
| 70 | + Scenario: Checking whether an icon is registered |
| 71 | + When I try `wp icon is-registered core/nonexistent-icon` |
| 72 | + Then the return code should be 1 |
| 73 | + |
| 74 | + When I run `wp icon is-registered core/plus` |
| 75 | + Then the return code should be 0 |
| 76 | + |
| 77 | + @require-wp-7.1 |
| 78 | + Scenario: Rendering an icon |
| 79 | + When I run `wp icon render core/plus` |
| 80 | + Then STDOUT should contain: |
| 81 | + """ |
| 82 | + width="24" |
| 83 | + """ |
| 84 | + And STDOUT should contain: |
| 85 | + """ |
| 86 | + height="24" |
| 87 | + """ |
| 88 | + And STDOUT should contain: |
| 89 | + """ |
| 90 | + aria-hidden="true" |
| 91 | + """ |
| 92 | + |
| 93 | + @require-wp-7.1 |
| 94 | + Scenario: Rendering an icon with a size, class and label |
| 95 | + When I run `wp icon render core/plus --size=48 --class=my-icon --label="Add item"` |
| 96 | + Then STDOUT should contain: |
| 97 | + """ |
| 98 | + width="48" |
| 99 | + """ |
| 100 | + And STDOUT should contain: |
| 101 | + """ |
| 102 | + class="my-icon" |
| 103 | + """ |
| 104 | + And STDOUT should contain: |
| 105 | + """ |
| 106 | + role="img" |
| 107 | + """ |
| 108 | + And STDOUT should contain: |
| 109 | + """ |
| 110 | + aria-label="Add item" |
| 111 | + """ |
| 112 | + And STDOUT should not contain: |
| 113 | + """ |
| 114 | + aria-hidden |
| 115 | + """ |
| 116 | + |
| 117 | + @require-wp-7.1 |
| 118 | + Scenario: Rendering an icon at its intrinsic size |
| 119 | + When I run `wp icon render core/plus --size=none` |
| 120 | + Then STDOUT should contain: |
| 121 | + """ |
| 122 | + <svg |
| 123 | + """ |
| 124 | + And STDOUT should not contain: |
| 125 | + """ |
| 126 | + width= |
| 127 | + """ |
| 128 | + |
| 129 | + @require-wp-7.1 |
| 130 | + Scenario: Rendering an icon with an invalid size |
| 131 | + When I try `wp icon render core/plus --size=huge` |
| 132 | + Then the return code should be 1 |
| 133 | + And STDERR should contain: |
| 134 | + """ |
| 135 | + The --size argument must be a positive integer or "none". |
| 136 | + """ |
| 137 | + |
| 138 | + @require-wp-7.1 |
| 139 | + Scenario: Rendering a non-existent icon |
| 140 | + When I try `wp icon render core/nonexistent-icon` |
| 141 | + Then the return code should be 1 |
| 142 | + And STDERR should contain: |
| 143 | + """ |
| 144 | + doesn't exist |
| 145 | + """ |
| 146 | + |
| 147 | + @require-wp-7.1 |
| 148 | + Scenario: Managing icons registered by a plugin |
| 149 | + Given a wp-content/mu-plugins/test-icons.php file: |
| 150 | + """ |
| 151 | + <?php |
| 152 | + // Plugin Name: Test Icons |
| 153 | + add_action( |
| 154 | + 'init', |
| 155 | + function () { |
| 156 | + wp_register_icon_collection( |
| 157 | + 'test-icons', |
| 158 | + array( |
| 159 | + 'label' => 'Test Icons', |
| 160 | + 'description' => 'A collection for testing.', |
| 161 | + ) |
| 162 | + ); |
| 163 | +
|
| 164 | + wp_register_icon( |
| 165 | + 'test-icons/square', |
| 166 | + array( |
| 167 | + 'label' => 'Square', |
| 168 | + 'content' => '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 4h16v16H4z" /></svg>', |
| 169 | + ) |
| 170 | + ); |
| 171 | + } |
| 172 | + ); |
| 173 | + """ |
| 174 | + |
| 175 | + When I run `wp icon list --collection=test-icons --fields=name,label,collection` |
| 176 | + Then STDOUT should be a table containing rows: |
| 177 | + | name | label | collection | |
| 178 | + | test-icons/square | Square | test-icons | |
| 179 | + |
| 180 | + When I run `wp icon get test-icons/square --field=content` |
| 181 | + Then STDOUT should contain: |
| 182 | + """ |
| 183 | + M4 4h16v16H4z |
| 184 | + """ |
| 185 | + |
| 186 | + When I run `wp icon get test-icons/square --field=file_path` |
| 187 | + Then STDOUT should not contain: |
| 188 | + """ |
| 189 | + .svg |
| 190 | + """ |
| 191 | + |
| 192 | + When I run `wp icon render test-icons/square --size=16` |
| 193 | + Then STDOUT should contain: |
| 194 | + """ |
| 195 | + width="16" |
| 196 | + """ |
| 197 | + |
| 198 | + @less-than-wp-7.1 |
| 199 | + Scenario: Icon commands fail on WordPress < 7.1 |
| 200 | + When I try `wp icon list` |
| 201 | + Then the return code should be 1 |
| 202 | + And STDERR should contain: |
| 203 | + """ |
| 204 | + Requires WordPress 7.1 or greater |
| 205 | + """ |
0 commit comments