|
| 1 | +Feature: Audit strings in a WordPress project |
| 2 | + |
| 3 | + Background: |
| 4 | + Given a WP install |
| 5 | + |
| 6 | + Scenario: Audits a plugin for translation issues |
| 7 | + Given an empty foo-plugin directory |
| 8 | + And a foo-plugin/foo-plugin.php file: |
| 9 | + """ |
| 10 | + <?php |
| 11 | + /** |
| 12 | + * Plugin Name: Foo Plugin |
| 13 | + * Text Domain: foo-plugin |
| 14 | + */ |
| 15 | +
|
| 16 | + __( 'Hello %s', 'foo-plugin' ); |
| 17 | + """ |
| 18 | + |
| 19 | + When I try `wp i18n audit foo-plugin` |
| 20 | + Then STDERR should contain: |
| 21 | + """ |
| 22 | + Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. |
| 23 | + """ |
| 24 | + And STDERR should contain: |
| 25 | + """ |
| 26 | + Warning: Found 1 issue. |
| 27 | + """ |
| 28 | + And the return code should be 0 |
| 29 | + |
| 30 | + Scenario: Audits a plugin and finds no issues |
| 31 | + Given an empty foo-plugin directory |
| 32 | + And a foo-plugin/foo-plugin.php file: |
| 33 | + """ |
| 34 | + <?php |
| 35 | + /** |
| 36 | + * Plugin Name: Foo Plugin |
| 37 | + * Text Domain: foo-plugin |
| 38 | + */ |
| 39 | +
|
| 40 | + __( 'Hello World', 'foo-plugin' ); |
| 41 | + """ |
| 42 | + |
| 43 | + When I run `wp i18n audit foo-plugin` |
| 44 | + Then STDOUT should contain: |
| 45 | + """ |
| 46 | + Success: No issues found. |
| 47 | + """ |
| 48 | + And STDERR should be empty |
| 49 | + |
| 50 | + Scenario: Outputs audit results as JSON |
| 51 | + Given an empty foo-plugin directory |
| 52 | + And a foo-plugin/foo-plugin.php file: |
| 53 | + """ |
| 54 | + <?php |
| 55 | + /** |
| 56 | + * Plugin Name: Foo Plugin |
| 57 | + * Text Domain: foo-plugin |
| 58 | + */ |
| 59 | +
|
| 60 | + __( 'Hello %s', 'foo-plugin' ); |
| 61 | + """ |
| 62 | + |
| 63 | + When I run `wp i18n audit foo-plugin --format=json` |
| 64 | + Then STDOUT should contain: |
| 65 | + """ |
| 66 | + "file": "foo-plugin.php" |
| 67 | + """ |
| 68 | + And STDOUT should contain: |
| 69 | + """ |
| 70 | + "line": 7 |
| 71 | + """ |
| 72 | + And STDOUT should contain: |
| 73 | + """ |
| 74 | + "message": "The string \"Hello %s\" contains placeholders but has no \"translators:\" comment to clarify their meaning." |
| 75 | + """ |
| 76 | + And STDOUT should contain: |
| 77 | + """ |
| 78 | + "code": "missing-translator-comment" |
| 79 | + """ |
| 80 | + |
| 81 | + Scenario: Outputs audit results in GitHub Actions format |
| 82 | + Given an empty foo-plugin directory |
| 83 | + And a foo-plugin/foo-plugin.php file: |
| 84 | + """ |
| 85 | + <?php |
| 86 | + /** |
| 87 | + * Plugin Name: Foo Plugin |
| 88 | + * Text Domain: foo-plugin |
| 89 | + */ |
| 90 | +
|
| 91 | + __( 'Hello %s', 'foo-plugin' ); |
| 92 | + """ |
| 93 | + |
| 94 | + When I run `wp i18n audit foo-plugin --format=github-actions` |
| 95 | + Then STDOUT should contain: |
| 96 | + """ |
| 97 | + ::warning file=foo-plugin.php,line=7::The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. |
| 98 | + """ |
| 99 | + |
| 100 | + Scenario: Detects multiple unordered placeholders |
| 101 | + Given an empty foo-plugin directory |
| 102 | + And a foo-plugin/foo-plugin.php file: |
| 103 | + """ |
| 104 | + <?php |
| 105 | + /** |
| 106 | + * Plugin Name: Foo Plugin |
| 107 | + * Text Domain: foo-plugin |
| 108 | + */ |
| 109 | +
|
| 110 | + __( 'Hello %s %s', 'foo-plugin' ); |
| 111 | + """ |
| 112 | + |
| 113 | + When I try `wp i18n audit foo-plugin` |
| 114 | + Then STDERR should contain: |
| 115 | + """ |
| 116 | + Warning: foo-plugin.php:7: Multiple placeholders should be ordered. |
| 117 | + """ |
| 118 | + |
| 119 | + Scenario: Detects strings without translatable content |
| 120 | + Given an empty foo-plugin directory |
| 121 | + And a foo-plugin/foo-plugin.php file: |
| 122 | + """ |
| 123 | + <?php |
| 124 | + /** |
| 125 | + * Plugin Name: Foo Plugin |
| 126 | + * Text Domain: foo-plugin |
| 127 | + */ |
| 128 | +
|
| 129 | + __( '%s', 'foo-plugin' ); |
| 130 | + """ |
| 131 | + |
| 132 | + When I try `wp i18n audit foo-plugin` |
| 133 | + Then STDERR should contain: |
| 134 | + """ |
| 135 | + Warning: foo-plugin.php:7: Found string without translatable content. |
| 136 | + """ |
| 137 | + |
| 138 | + Scenario: Detects multiple translator comments |
| 139 | + Given an empty foo-plugin directory |
| 140 | + And a foo-plugin/foo-plugin.php file: |
| 141 | + """ |
| 142 | + <?php |
| 143 | + /** |
| 144 | + * Plugin Name: Foo Plugin |
| 145 | + * Text Domain: foo-plugin |
| 146 | + */ |
| 147 | +
|
| 148 | + /* translators: Comment 1 */ |
| 149 | + __( 'Hello World', 'foo-plugin' ); |
| 150 | +
|
| 151 | + /* translators: Comment 2 */ |
| 152 | + __( 'Hello World', 'foo-plugin' ); |
| 153 | + """ |
| 154 | + |
| 155 | + When I try `wp i18n audit foo-plugin` |
| 156 | + Then STDERR should contain: |
| 157 | + """ |
| 158 | + Warning: foo-plugin.php: |
| 159 | + """ |
| 160 | + And STDERR should contain: |
| 161 | + """ |
| 162 | + different translator comments |
| 163 | + """ |
| 164 | + |
| 165 | + Scenario: Detects missing singular placeholder |
| 166 | + Given an empty foo-plugin directory |
| 167 | + And a foo-plugin/foo-plugin.php file: |
| 168 | + """ |
| 169 | + <?php |
| 170 | + /** |
| 171 | + * Plugin Name: Foo Plugin |
| 172 | + * Text Domain: foo-plugin |
| 173 | + */ |
| 174 | +
|
| 175 | + _n( 'One comment', '%s Comments', $count, 'foo-plugin' ); |
| 176 | + """ |
| 177 | + |
| 178 | + When I try `wp i18n audit foo-plugin` |
| 179 | + Then STDERR should contain: |
| 180 | + """ |
| 181 | + Warning: foo-plugin.php:7: Missing singular placeholder, needed for some languages. |
| 182 | + """ |
| 183 | + |
| 184 | + Scenario: Detects mismatched placeholders in plural strings |
| 185 | + Given an empty foo-plugin directory |
| 186 | + And a foo-plugin/foo-plugin.php file: |
| 187 | + """ |
| 188 | + <?php |
| 189 | + /** |
| 190 | + * Plugin Name: Foo Plugin |
| 191 | + * Text Domain: foo-plugin |
| 192 | + */ |
| 193 | +
|
| 194 | + _n( '%s Comment', '%d Comments', $count, 'foo-plugin' ); |
| 195 | + """ |
| 196 | + |
| 197 | + When I try `wp i18n audit foo-plugin` |
| 198 | + Then STDERR should contain: |
| 199 | + """ |
| 200 | + Warning: foo-plugin.php:7: Mismatched placeholders for singular and plural string. |
| 201 | + """ |
| 202 | + |
| 203 | + Scenario: Respects --ignore-domain flag |
| 204 | + Given an empty foo-plugin directory |
| 205 | + And a foo-plugin/foo-plugin.php file: |
| 206 | + """ |
| 207 | + <?php |
| 208 | + /** |
| 209 | + * Plugin Name: Foo Plugin |
| 210 | + * Text Domain: foo-plugin |
| 211 | + */ |
| 212 | +
|
| 213 | + __( 'Hello %s', 'different-domain' ); |
| 214 | + """ |
| 215 | + |
| 216 | + When I try `wp i18n audit foo-plugin --ignore-domain` |
| 217 | + Then STDERR should contain: |
| 218 | + """ |
| 219 | + Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. |
| 220 | + """ |
| 221 | + |
| 222 | + Scenario: Respects --skip-php flag |
| 223 | + Given an empty foo-plugin directory |
| 224 | + And a foo-plugin/foo-plugin.php file: |
| 225 | + """ |
| 226 | + <?php |
| 227 | + /** |
| 228 | + * Plugin Name: Foo Plugin |
| 229 | + * Text Domain: foo-plugin |
| 230 | + */ |
| 231 | +
|
| 232 | + __( 'Hello %s', 'foo-plugin' ); |
| 233 | + """ |
| 234 | + |
| 235 | + When I run `wp i18n audit foo-plugin --skip-php` |
| 236 | + Then STDOUT should contain: |
| 237 | + """ |
| 238 | + Success: No issues found. |
| 239 | + """ |
| 240 | + |
| 241 | + Scenario: Shows file before warning message in plaintext format |
| 242 | + Given an empty foo-plugin directory |
| 243 | + And a foo-plugin/foo-plugin.php file: |
| 244 | + """ |
| 245 | + <?php |
| 246 | + /** |
| 247 | + * Plugin Name: Foo Plugin |
| 248 | + * Text Domain: foo-plugin |
| 249 | + */ |
| 250 | +
|
| 251 | + __( 'Hello %s', 'foo-plugin' ); |
| 252 | + """ |
| 253 | + |
| 254 | + When I try `wp i18n audit foo-plugin --format=plaintext` |
| 255 | + Then STDERR should contain: |
| 256 | + """ |
| 257 | + Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. |
| 258 | + """ |
0 commit comments