Skip to content

Commit ea2adda

Browse files
authored
Merge pull request #133 from 2ndkauboy/104-add-locale-parameter
2 parents 709cec9 + 14b426e commit ea2adda

File tree

3 files changed

+122
-9
lines changed

3 files changed

+122
-9
lines changed

features/core-install.feature

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,91 @@ Feature: Install WordPress core
171171
"""
172172
And the return code should be 0
173173
174+
@less-than-php-7
175+
Scenario: Install WordPress with locale set to de_DE on WP < 4.0
176+
Given an empty directory
177+
And an empty cache
178+
And a database
179+
180+
When I run `wp core download --version=3.7 --locale=de_DE`
181+
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
182+
And I run `echo {VERSION}`
183+
Then STDOUT should contain:
184+
"""
185+
3.7
186+
"""
187+
And the wp-settings.php file should exist
188+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
189+
190+
When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE`
191+
Then STDOUT should be:
192+
"""
193+
Success: Generated 'wp-config.php' file.
194+
"""
195+
196+
# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
197+
When I try `wp core install --url=example.org --title=Test --admin_user=testadmin --admin_email=testadmin@example.com --admin_password=newpassword --locale=de_DE --skip-email`
198+
Then STDERR should contain:
199+
"""
200+
Warning: The flag --locale=de_DE is being ignored as it requires WordPress 4.0+.
201+
"""
202+
Then STDOUT should contain:
203+
"""
204+
Success: WordPress installed successfully.
205+
"""
206+
207+
When I run `wp core version`
208+
Then STDOUT should contain:
209+
"""
210+
3.7
211+
"""
212+
213+
When I run `wp taxonomy list`
214+
Then STDOUT should contain:
215+
"""
216+
Kategorien
217+
"""
218+
219+
Scenario: Install WordPress with locale set to de_DE on WP >= 4.0
220+
Given an empty directory
221+
And an empty cache
222+
And a database
223+
224+
When I run `wp core download --version=5.6 --locale=de_DE`
225+
And save STDOUT 'Downloading WordPress ([\d\.]+)' as {VERSION}
226+
And I run `echo {VERSION}`
227+
Then STDOUT should contain:
228+
"""
229+
5.6
230+
"""
231+
And the wp-settings.php file should exist
232+
And the {SUITE_CACHE_DIR}/core/wordpress-{VERSION}-de_DE.tar.gz file should exist
233+
234+
When I run `wp config create --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASSWORD} --dbhost={DB_HOST} --locale=de_DE`
235+
Then STDOUT should be:
236+
"""
237+
Success: Generated 'wp-config.php' file.
238+
"""
239+
240+
# Old versions of WP can generate wpdb database errors if the WP tables don't exist, so STDERR may or may not be empty
241+
When I run `wp core install --url=example.org --title=Test --admin_user=testadmin --admin_email=testadmin@example.com --admin_password=newpassword --locale=de_DE --skip-email`
242+
Then STDOUT should contain:
243+
"""
244+
Success: WordPress installed successfully.
245+
"""
246+
247+
When I run `wp core version`
248+
Then STDOUT should contain:
249+
"""
250+
5.6
251+
"""
252+
253+
When I run `wp taxonomy list`
254+
Then STDOUT should contain:
255+
"""
256+
Kategorien
257+
"""
258+
174259
Scenario: Install WordPress multisite without specifying the password
175260
Given an empty directory
176261
And WP files

features/core.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Feature: Manage WordPress installation
309309
<?php
310310
// ** MySQL settings ** //
311311
/** The name of the database for WordPress */
312-
define('DB_NAME', 'wp_cli_test');
312+
define('DB_NAME', '{DB_NAME}');
313313
314314
/** MySQL database username */
315315
define('DB_USER', '{DB_USER}');

src/Core_Command.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ public function is_installed( $args, $assoc_args ) {
393393
* --admin_email=<email>
394394
* : The email address for the admin user.
395395
*
396+
* [--locale=<locale>]
397+
* : The locale/language for the installation (e.g. `de_DE`). Default is `en_US`.
398+
*
396399
* [--skip-email]
397400
* : Don't send an email notification to the new admin user.
398401
*
@@ -605,6 +608,19 @@ function wp_new_blog_notification() {
605608
'admin_password' => '',
606609
];
607610

611+
if ( Utils\wp_version_compare( '4.0', '<' ) ) {
612+
if ( array_key_exists( 'locale', $assoc_args ) ) {
613+
WP_CLI::warning(
614+
sprintf(
615+
'The flag --locale=%s is being ignored as it requires WordPress 4.0+.',
616+
$assoc_args['locale']
617+
)
618+
);
619+
}
620+
} else {
621+
$defaults['locale'] = '';
622+
}
623+
608624
$args = wp_parse_args( $assoc_args, $defaults );
609625

610626
// Support prompting for the `--url=<url>`,
@@ -622,14 +638,26 @@ function wp_new_blog_notification() {
622638
WP_CLI::error( "The '{$args['admin_email']}' email address is invalid." );
623639
}
624640

625-
$result = wp_install(
626-
$args['title'],
627-
$args['admin_user'],
628-
$args['admin_email'],
629-
$public,
630-
'',
631-
$password
632-
);
641+
if ( Utils\wp_version_compare( '4.0', '>=' ) ) {
642+
$result = wp_install(
643+
$args['title'],
644+
$args['admin_user'],
645+
$args['admin_email'],
646+
$public,
647+
'',
648+
$password,
649+
$args['locale']
650+
);
651+
} else {
652+
$result = wp_install(
653+
$args['title'],
654+
$args['admin_user'],
655+
$args['admin_email'],
656+
$public,
657+
'',
658+
$password
659+
);
660+
}
633661

634662
if ( is_wp_error( $result ) ) {
635663
$reason = WP_CLI::error_to_string( $result );

0 commit comments

Comments
 (0)